-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexit.c
More file actions
48 lines (45 loc) · 733 Bytes
/
exit.c
File metadata and controls
48 lines (45 loc) · 733 Bytes
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
#include "minishell.h"
void ft_exit_two(char **args, int ret)
{
ret = ft_atoi(args[0]);
if (ret > 255)
{
write(1, "exit\n", 6);
exit(ret % 256);
}
else if (ret < 0)
{
write(1, "exit\n", 6);
exit (ret + 256);
}
else
{
write(1, "exit\n", 6);
exit(ret);
}
}
int ft_exit(char **args)
{
int b;
b = 0;
if (args[0] == NULL)
exit(g_global.return_value);
while (args[0][b] != '\0')
{
if (ft_isdigit(args[0][b]) != 1)
{
printf("exit\nminishell: exit: ");
printf("%s: numeric argument required\n", args[0]);
exit(255);
}
b++;
}
if (args[1] != NULL)
{
printf("exit\nminishell: exit: too many arguments\n");
g_global.return_value = 1;
return (0);
}
ft_exit_two(args, 0);
return (0);
}