-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_tools.c
More file actions
50 lines (43 loc) · 1.06 KB
/
process_tools.c
File metadata and controls
50 lines (43 loc) · 1.06 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
// 42 HEADER
#include "minishell.h"
char *builtin_names[] = {
"exit", "cd", "echo", "env", "export", "pwd", "unset", NULL
};
t_builtin_function g_builtin_functions[] = {
NULL, &change_dir, &echo, &env, &ft_export, &ft_pwd, &ft_unset, NULL
};
int isbuiltin(char *bname)
{
return (ft_tabindex(
(const void **)builtin_names, (const void*)bname, (void*)ft_strcmp
));
}
int call_builtin_function(int builtin_index, char *args[], t_options *opt)
{
int r;
int tmp[2];
if (opt->current_pwrite != -1)
{
tmp[RDEND] = dup(STDIN_FILENO);
dup2(opt->current_pwrite, STDOUT_FILENO);
}
if (opt->previous_pread != -1)
{
tmp[WREND] = dup(STDOUT_FILENO);
dup2(opt->previous_pread, STDIN_FILENO);
}
r = g_builtin_functions[builtin_index](args);
if (opt->previous_pread != -1)
dup2(tmp[RDEND], STDIN_FILENO);
if (opt->current_pwrite != -1)
dup2(tmp[WREND], STDOUT_FILENO);
return (r);
}
char *isbinary(char *bname)
{
if (try_path(bname))
return (bname);
if (errno == EISDIR)
return (NULL);
return (build_path(get_key_value(environment, "PATH"), bname));
}