-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_command.c
41 lines (36 loc) · 1.35 KB
/
check_command.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebouabba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/19 22:42:27 by ebouabba #+# #+# */
/* Updated: 2022/02/20 19:12:53 by ebouabba ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
static char *command(char *path, char *av)
{
t_list pipex;
int i;
i = 0;
pipex.check = ft_strjoin(path, "/");
pipex.path = ft_strjoin(pipex.check, av);
return (pipex.path);
}
char *check_command(char **list_cmd, char *av)
{
t_list pipex;
int i;
i = 0;
while (list_cmd[i])
{
pipex.check = command(list_cmd[i], av);
if (access(pipex.check, F_OK) == 0)
return (pipex.check);
i++;
}
check_error("Error: command not found\n");
return (NULL);
}