-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipex_utils.c
50 lines (46 loc) · 1.46 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
39
40
41
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dvan-der <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/14 13:55:14 by dvan-der #+# #+# */
/* Updated: 2022/02/09 14:20:52 by dvan-der ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
void free_pipex(t_pipe *p)
{
ft_free_char_array(p->path);
ft_free_char_array(p->mycmd);
free(p);
return ;
}
int arrange_output(t_pipe *p, int output, int file2)
{
if (file2 == 1)
{
output = open(p->argv[p->cmd_lim + 1], \
O_CREAT | O_RDWR | O_TRUNC, 0644);
if (output < 0 || output > 1024)
{
perror("");
exit(errno);
}
}
return (output);
}
int arrange_input(t_pipe *p, int input)
{
if (input == -1 && p->cmd_i == 2)
{
input = open(p->argv[1], O_RDONLY);
if (input < 0 || input > 1024)
{
perror("");
exit(errno);
}
}
return (input);
}