blob: aa5d10b15c0a47dcccb20c333023e0d883f918be (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:16 by charles #+# #+# */
/* Updated: 2020/06/23 10:03:39 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/*
** \file exit.c
** \brief `exit` builtin
*/
int builtin_exit(char **argv, t_env env)
{
int status;
(void)env;
if (argv[1] == NULL)
status = 0;
else if (argv[2] != NULL)
{
// replace with minishell error system
ft_putendl_fd("minishell: exit: too many arguments", STDERR_FILENO);
return 1;
}
else
{
errno = 0;
status = ft_atoi_strict(argv[1]);
if (errno != 0)
{
// replace with minishell error system
ft_putendl_fd("minishell: exit: ---argv[1]---: numeric argument required", STDERR_FILENO);
return 2;
}
}
exit(status % 256);
return (0);
}
|