-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin_exit.c
58 lines (53 loc) · 1.69 KB
/
builtin_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rdanyell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/04 10:53:59 by hcolumbu #+# #+# */
/* Updated: 2022/06/16 16:51:22 by rdanyell ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void arguments_handler(char **array, t_com *com, t_envp *envp_list)
{
int i;
i = 0;
if (array[0][i] == '+' || array[0][i] == '-')
i++;
while (array[0][++i])
{
if (array[0][i] < '0' || array[0][i] > '9')
{
ft_putendl_fd("Myshell 🐚: exit: numeric argument required", 2);
free_com_list(com);
free_envp_list(envp_list);
exit(255);
}
}
if (array[1])
ft_putendl_fd("exit \nMyshell 🐚: exit: too many arguments", 2);
else
{
i = ft_atoi(array[0]);
ft_putendl_fd("exit", 1);
free_com_list(com);
free_envp_list(envp_list);
exit(i);
}
}
void builtin_exit(t_com *com, t_envp *envp_list)
{
int i;
i = 0;
if (!com->arg)
{
ft_putendl_fd("exit", 1);
free_com_list(com);
free_envp_list(envp_list);
exit(0);
}
else
arguments_handler(com->arg, com, envp_list);
}