-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipex_helper_bonus.c
83 lines (73 loc) · 1.89 KB
/
pipex_helper_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
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_helper_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: melkholy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/10 15:34:17 by melkholy #+# #+# */
/* Updated: 2022/09/12 22:15:40 by melkholy ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex_bonus.h"
char **ft_cmd_space(char *cmd, t_pipe *buff, char *str)
{
char **cmd_path;
char *tmp;
cmd_path = ft_split(cmd, ' ');
tmp = ft_get_path(cmd_path[0], buff);
if (tmp)
{
free(cmd_path[0]);
cmd_path[0] = tmp;
}
else
{
ft_free_pth(cmd_path);
return (NULL);
}
if (str)
free(cmd);
return (cmd_path);
}
void ft_single_q(char *str, char **cmd_path)
{
int count;
count = 0;
while (cmd_path[count])
count ++;
free(cmd_path[count - 1]);
cmd_path[count - 1] = str;
}
char *ft_found_q(char *cmd, char **str)
{
char *tmp;
*str = ft_strdup(ft_strchr(cmd, 39));
cmd = ft_strtrim(cmd, *str);
tmp = ft_strjoin(cmd, " 42");
free(cmd);
cmd = tmp;
tmp = ft_strtrim(*str, "'");
free(*str);
*str = tmp;
return (cmd);
}
void ft_free_pipes(int **pipes, int pipe)
{
int count;
count = 0;
while (count < pipe)
{
free(pipes[count]);
count ++;
}
free(pipes);
}
void ft_close_pipes(int **pipes, int count)
{
while (--count >= 0)
{
close(pipes[count][0]);
close(pipes[count][1]);
}
}