-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_command.c
More file actions
52 lines (48 loc) · 1.51 KB
/
ft_command.c
File metadata and controls
52 lines (48 loc) · 1.51 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlutsch <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/04 11:26:30 by rlutsch #+# #+# */
/* Updated: 2016/11/14 14:50:33 by rlutsch ### ########.fr */
/* */
/* ************************************************************************** */
#include "21sh.h"
void ft_command(char **av)
{
char *p;
pid_t father;
extern char **environ;
char **path;
int i;
i = 0;
i = ft_operator(av);
father = 0;
if (i == 1)
kill(father, -1);
else if (i != 0)
{
path = ft_strsplit(ft_getenv("PATH"), ':');
i = ft_tablen(path);
father = fork();
if (father == 0){
while (i-- > 0)
{
if (ft_strncmp(av[0], "/bin/", 5) != 0)
p = ft_strjoin(ft_strjoin(path[i], "/"), av[0]);
if (!(execve(p, av, environ)))
{
free(path);
exit(EXIT_FAILURE);
}
}
ft_putstr("command not found:");
ft_putstr(ft_strjoin(av[0], "\n"));
}
else
wait(0);
}
free (path);
}