-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_not_builtin.c
More file actions
67 lines (60 loc) · 1.76 KB
/
ft_not_builtin.c
File metadata and controls
67 lines (60 loc) · 1.76 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_not_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/10 16:28:57 by mamoussa #+# #+# */
/* Updated: 2020/12/12 16:45:33 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
size_t args_count(void)
{
size_t counter;
t_cmd *current;
counter = 0;
current = g_cmd_head;
while (current && (current->type != semicolumn) &&
(current->type != pipee))
{
counter++;
current = current->next;
}
return (counter);
}
char **set_args(size_t counter)
{
size_t i;
char **args;
t_cmd *current;
i = 0;
current = g_cmd_head;
args = (char**)malloc(sizeof(char*) * (counter + 1));
while (current && (current->type != semicolumn) &&
(current->type != pipee))
{
args[i] = ft_strdup(current->string);
i++;
current = current->next;
}
args[i] = NULL;
return (args);
}
void ft_not_builtin(void)
{
size_t counter;
char **args;
counter = args_count();
if (!not_built_error())
{
printf("%s\n", g_cmd_head->string);
ft_error("command not found\n");
exit(127);
}
imp_red();
imp_pipes();
args = set_args(counter);
execve(args[0], args, g_tmp_env);
}