-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnon_builtins2.c
More file actions
112 lines (106 loc) · 3.16 KB
/
non_builtins2.c
File metadata and controls
112 lines (106 loc) · 3.16 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* non_builtins2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aouchaad <aouchaad@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/22 23:40:33 by aouchaad #+# #+# */
/* Updated: 2023/06/23 15:14:36 by aouchaad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void check_redirect_in_child(t_variables *var, t_redirection **tmp2, \
t_command_line **tmp)
{
while ((*tmp2))
{
if ((*tmp2)->type == read_fromf)
{
var->fd_in = check_exist_and_permission_inchild(\
(*tmp2)->file, (*tmp2)->type);
if (var->fd_in == -1)
exit(1);
var->rffile = 1;
}
else if ((*tmp2)->type == write_inf || (*tmp2)->type == append)
{
var->fd_out = check_exist_and_permission_inchild(\
(*tmp2)->file, (*tmp2)->type);
var->wifile = 1;
if (var->fd_out == -1)
exit(1);
}
else if ((*tmp2)->type == heredoc)
{
var->rffile = 1;
var->fd_in = (*tmp)->heredoc_fd;
}
(*tmp2) = (*tmp2)->next;
}
}
void also_builtings_in_child(t_glob **glob, t_command_line **tmp)
{
if (ft_strcmp((*tmp)->command, "exit") == 0)
{
(*glob)->exit_stat = ft_exit((*tmp)->args, glob);
exit((*glob)->exit_stat);
}
else if (ft_strcmp((*tmp)->command, "unset") == 0)
{
(*glob)->exit_stat = ft_unset(glob, (*tmp)->args);
exit((*glob)->exit_stat);
}
else if (ft_strcmp((*tmp)->command, "cd") == 0)
{
(*glob)->exit_stat = ft_cd(glob);
exit((*glob)->exit_stat);
}
}
void builtings_in_child(t_glob **glob, t_command_line **tmp)
{
if (ft_strcmp((*tmp)->command, "echo") == 0)
{
(*glob)->exit_stat = ft_echo((*tmp)->args);
exit((*glob)->exit_stat);
}
else if (ft_strcmp((*tmp)->command, "env") == 0)
{
(*glob)->exit_stat = ft_env((*glob)->envp);
exit((*glob)->exit_stat);
}
else if (ft_strcmp((*tmp)->command, "pwd") == 0)
{
(*glob)->exit_stat = ft_pwd((*glob)->envp);
exit((*glob)->exit_stat);
}
else if (ft_strcmp((*tmp)->command, "export") == 0)
{
(*glob)->exit_stat = ft_export((*tmp)->args, glob);
exit((*glob)->exit_stat);
}
also_builtings_in_child(glob, tmp);
}
void send_to_execve(t_glob **glob, t_command_line **tmp, \
t_variables *var)
{
char *path;
char **args;
char **env;
path = command_path((*glob)->envp, (*tmp)->command);
args = join_args((*tmp)->command, (*tmp)->args);
env = join_envp((*glob)->envp);
if (path != NULL && (*glob)->command_line->command != NULL)
{
var->error = execve(path, args, env);
if (var->error == -1)
{
print_error((*glob)->command_line->command, \
"command not found");
exit (127);
}
else
exit (0);
}
exit((*glob)->exit_stat);
}