-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
38 lines (35 loc) · 1.44 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mskeleto <mskeleto@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/07 07:17:45 by mskeleto #+# #+# */
/* Updated: 2021/12/07 08:18:33 by mskeleto ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
int main(int argc, char **argv, char **envp)
{
pid_t pid;
int *fd;
int *files;
if (argc != 5)
return (ft_error(1, NULL, NULL));
fd = (int *)malloc(sizeof(int) * 2);
files = (int *)malloc(sizeof(int) * 2);
open_and_pipe(files, fd, argv);
if (!fd || !files || files[0] == -1 || files[1] == -1)
return (0);
pid = fork();
if (pid < 0)
return (ft_error(3, NULL, NULL));
if (pid == 0)
ft_daughter1(ft_split(argv[2], ' '), envp, fd, files);
else
ft_parent(ft_split(argv[3], ' '), envp, fd, files);
close(files[1]);
close(fd[0]);
return (0);
}