-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_pipes.c
More file actions
44 lines (40 loc) · 1.33 KB
/
ft_pipes.c
File metadata and controls
44 lines (40 loc) · 1.33 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pipes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/28 17:27:03 by mamoussa #+# #+# */
/* Updated: 2020/12/10 16:30:56 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
size_t check_for_pipe(t_cmd *cur_cmd)
{
while (cur_cmd && (cur_cmd->type != semicolumn))
{
if (cur_cmd->type == pipee)
{
g_is_pipe = 1;
return (1);
}
cur_cmd = cur_cmd->next;
}
return (0);
}
void ft_pipes(t_cmd *cur_cmd)
{
int *fd;
fd = (int*)malloc(sizeof(int) * 2);
if (check_for_pipe(cur_cmd))
{
pipe(fd);
g_cur->fd0 = dup(fd[0]);
g_cur->fd1 = dup(fd[1]);
close(fd[0]);
close(fd[1]);
}
free(fd);
fd = NULL;
}