diff options
Diffstat (limited to 'src/builtin/exit.c')
| -rw-r--r-- | src/builtin/exit.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/builtin/exit.c b/src/builtin/exit.c index 15271f6..860325e 100644 --- a/src/builtin/exit.c +++ b/src/builtin/exit.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:16 by charles #+# #+# */ -/* Updated: 2020/07/13 15:35:44 by charles ### ########.fr */ +/* Updated: 2020/07/17 16:36:03 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,27 +19,32 @@ int builtin_exit(char **argv, t_env env) { - int status; + long status; + char *after; (void)env; if (argv[1] == NULL) status = g_last_status_code; - 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) + status = ft_strtol(argv[1], &after, 10); + while (ft_isblank(*after)) + after++; + if (*after != '\0' || errno == ERANGE) { // replace with minishell error system - ft_putendl_fd("minishell: exit: ---argv[1]---: numeric argument required", STDERR_FILENO); + ft_putstr_fd("minishell: exit: ", STDERR_FILENO); + ft_putstr_fd(argv[1], STDERR_FILENO); + ft_putstr_fd(": numeric argument required\n", STDERR_FILENO); return 2; } + if (argv[2] != NULL) + { + // replace with minishell error system + ft_putendl_fd("minishell: exit: too many arguments", STDERR_FILENO); + return 1; + } } exit(status % 256); return (0); |
