-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathms_run_exit.c
56 lines (51 loc) · 1.56 KB
/
ms_run_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_run_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pnuti <pnuti@student.42wolfsburg.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/19 08:10:56 by pnuti #+# #+# */
/* Updated: 2022/01/05 11:28:00 by pnuti ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_libs.h"
static int is_all_num(char *s)
{
int i;
i = 0;
if ((s[i] < '0' || s[i] > '9') && s[i] != '-' && s[i] != '+')
return (0);
i++;
while (s[i])
{
if (s[i] < '0' || s[i] > '9')
return (0);
i++;
}
return (1);
}
int run_exit(void *stt, void *cmd)
{
t_struct *st;
t_cmd *arr;
st = (t_struct *)stt;
arr = (t_cmd *)cmd;
if (st->nb_cmd != 1 && if_exit(st) == 1)
return (-1);
printf("exit\n");
if (!arr->cmd[1])
g_exit_value = 0;
else
{
g_exit_value = ft_atoi(arr->cmd[1]);
if (!is_all_num(arr->cmd[1]))
{
g_exit_value = 2;
ft_putstr_fd("minishell: exit: numeric argument required\n", 2);
}
}
free_memory(st);
free_env(st);
return (0);
}