-
Notifications
You must be signed in to change notification settings - Fork 0
/
dop_help_bonus.c
71 lines (63 loc) · 1.17 KB
/
dop_help_bonus.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "header/pipex_bonus.h"
int **ft_create_pipes(int argc)
{
int **pipes;
int i;
i = -1;
pipes = (int **)malloc(sizeof(int *) * (argc - 4));
if (!pipes)
return (NULL);
while (++i < (argc - 4))
{
pipes[i] = (int *)malloc(sizeof(int) * 2);
if (!pipes[i])
return (NULL);
}
return (pipes);
}
void ft_free_all(int **pipes, int argc)
{
int i;
i = -1;
while (++i < (argc - 4))
free(pipes[i]);
free(pipes);
}
void ft_close_all(int **pipes, int argc)
{
int i;
i = -1;
while (++i < (argc - 4))
{
close(pipes[i][0]);
close(pipes[i][1]);
}
}
int ft_choose_child(int **pipes, char **argv, char **envp, int i)
{
if ((ft_strncmp(argv[1], "here_doc", 8) == 0))
{
if (i == 0)
{
ft_for_first_hand_child(pipes, argv, envp, 3);
return (1);
}
else
ft_for_circle_hand_child(pipes, argv, envp, i);
}
else
{
if (i == 0)
ft_for_first_child(pipes, argv, envp, 2);
else
ft_for_circle_child(pipes, argv, envp, i);
}
return (0);
}
void ft_choose_last_child(int **pipes, char **argv, char **envp, int i)
{
if ((ft_strncmp(argv[1], "here_doc", 8) == 0))
ft_for_last_hand_child(pipes, argv, envp, i);
else
ft_for_last_child(pipes, argv, envp, i);
}