-
Notifications
You must be signed in to change notification settings - Fork 0
/
exit.c
92 lines (85 loc) · 2.2 KB
/
exit.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/30 11:56:08 by zhabri #+# #+# */
/* Updated: 2023/01/10 10:50:58 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
bool exit_parent_arg(char **cmd_split)
{
long long ret;
if (cmd_split[1])
{
if (check_exit_error(cmd_split))
return (true);
clean_exit(NULL);
if (!is_valid_exit_arg(cmd_split[1]))
{
free_tab(cmd_split);
exit(2);
}
ret = ft_atoll(cmd_split[1]);
free_tab(cmd_split);
exit(ret);
}
return (false);
}
bool exit_parent(void)
{
int ret;
char **cmd_split;
if (ft_lstsize(*g_glob->cmds) == 1)
{
cmd_split = ft_split_quotes(((t_cmd *)(*g_glob->cmds)->content)->str, \
" \t");
if (cmd_split && cmd_split[0] && !ft_strncmp(cmd_split[0], "exit", 5))
{
ft_putstr_fd("exit\n", 1);
if (exit_parent_arg(cmd_split))
{
free_tab(cmd_split);
return (true);
}
else
{
ret = g_glob->exit_ret;
clean_and_free(cmd_split);
exit(ret);
}
}
free_tab(cmd_split);
}
return (false);
}
void exit_child(char *cmd, int fd_out)
{
long long ret;
char **cmd_split;
close(fd_out);
cmd_split = ft_split_quotes(cmd, " \t");
if (cmd_split[1])
{
if (check_exit_error(cmd_split))
{
clean_and_free(cmd_split);
exit(1);
}
clean_exit(NULL);
if (!is_valid_exit_arg(cmd_split[1]))
{
free_tab(cmd_split);
exit(2);
}
ret = ft_atoll(cmd_split[1]);
free_tab(cmd_split);
exit(ret);
}
ret = g_glob->exit_ret;
clean_and_free(cmd_split);
exit(ret);
}