-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.c
58 lines (53 loc) · 1.64 KB
/
helpers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* helpers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fraqioui <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/20 09:34:46 by fraqioui #+# #+# */
/* Updated: 2023/01/20 09:34:48 by fraqioui ### ########.fr */
/* */
/* ************************************************************************** */
#include"pipex.h"
void ft_exit(char *s)
{
ft_printf("%s", s);
exit(1);
}
char *find_path(char **env)
{
if (env == NULL || env[0] == NULL)
return (NULL);
while (*env)
{
if (ft_strncmp("PATH", *env, 4) == 0)
return (*env + 5);
env++;
}
return (NULL);
}
void ft_close_ends(int a, int b, int c, int d)
{
close(a);
close(b);
close(c);
close(d);
}
void freeing(char **a, char **b, char **c, char *d)
{
ft_alloc_fail(a);
ft_alloc_fail(b);
ft_alloc_fail(c);
free(d);
}
void ft_print_mess(t_pp pp, char **path_s, int flg)
{
freeing(pp.cmd_a, pp.cmd_b, path_s, NULL);
ft_close_ends(pp.fd_in, pp.fd_out, pp.end[1], pp.end[0]);
if (flg)
ft_exit("failed to create the first child process");
else
ft_exit("failed to create the second child process");
return ;
}