-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor_utils.c
79 lines (69 loc) · 1.96 KB
/
executor_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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* executor_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rpohl <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/16 12:44:02 by rpohl #+# #+# */
/* Updated: 2022/10/18 18:19:19 by rpohl ### ########.fr */
/* */
/* ************************************************************************** */
#include "executor.h"
void close_other_fd(t_executor *executor, int fd1, int fd2)
{
int i;
i = 0;
while (i < executor->num_pipes * 2)
{
if (!(i == fd1 || i == fd2))
close(executor->pipes[i]);
i++;
}
}
void close_fd(t_executor *executor)
{
int i;
i = 0;
while (i < executor->num_pipes)
{
close(executor->pipes[2 * i]);
close(executor->pipes[2 * i + 1]);
i++;
}
close(executor->fd1);
close(executor->fd2);
}
// char *get_cmd_path(char **paths, char *cmd)
// {
// char *tmp;
// char *command;
// if (access(cmd, 0) == 0)
// return (cmd);
// while (*paths)
// {
// tmp = ft_strjoin(*paths, "/");
// command = ft_strjoin(tmp, cmd);
// free(tmp);
// if (access(command, 0) == 0)
// return (command);
// free(command);
// paths++;
// }
// return (NULL);
// }
// char **get_cmd_paths(t_var *envp)
// {
// char **paths;
// t_var *tmp;
// tmp = envp;
// while (ft_strcmp("PATH", tmp->name) != 0)
// tmp = tmp->next;
// paths = ft_split(tmp->content, ':');
// return (paths);
// }
char exit_msg(char *msg, char exit_code)
{
perror(msg);
exit(exit_code);
}