-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipex_utils.c
38 lines (35 loc) · 1.37 KB
/
pipex_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yrhiba <yrhiba@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/28 08:42:37 by yrhiba #+# #+# */
/* Updated: 2022/12/06 03:44:18 by yrhiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
size_t getcmdscount(t_pipex *vars, int ac, const char **av)
{
vars->herdoc = 0;
if (ac > 1 && (strcmp(HERDOC, av[1]) == 0))
vars->herdoc = 1;
if (vars->herdoc)
{
if (ac < 6)
return (errno = EIO, -1);
vars->flags = O_WRONLY | O_CREAT | O_APPEND;
return (ac - 4);
}
if (ac < 5)
return (errno = EIO, -1);
vars->flags = O_WRONLY | O_CREAT;
return (ac - 3);
}
const char **getcmds(t_pipex *vars, const char **av)
{
if (vars->herdoc)
return (av + 3);
return (av + 2);
}