」 feat(builtins/ft_exit): ft_exit is there ! :D

This commit is contained in:
yosyo
2024-07-15 15:16:08 +02:00
parent bd49fa19a1
commit 891a43dbbb
2 changed files with 45 additions and 21 deletions

View File

@ -3,31 +3,55 @@
/* ::: :::::::: */
/* ft_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
/* Updated: 2024/07/14 14:24:47 by adjoly ### ########.fr */
/* Updated: 2024/07/15 15:14:57 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int check_exit_value(char *str)
{
int i;
i = 0;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i])
{
if (!ft_isdigit(str[i]))
return (1);
i++;
}
if (!i)
return (1);
return (0);
}
void ft_exit(char **argv, int ac)
{
char **tmp;
char *tmp_arg;
(void)tmp;
(void)tmp_arg;
(void)argv;
(void)ac;
exit(727);
// if (ac > 2)
// exit
// while (*tmp)
// {
//
// tmp++;
// }
int return_value;
if (ac < 2)
exit(get_exit_code(-1));
if (check_exit_value(argv[1]))
{
printf("minishell: exit: %s: numeric argument required\n", argv[1]);
exit(2);
}
else
{
if (ac > 2)
printf("minishell: exit: too many arguments\n");
else
{
return_value = atoi(argv[1]);
if (return_value == -1)
return_value += 255;
exit(get_exit_code(return_value));
}
}
get_exit_code(1);
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */
/* Updated: 2024/07/15 14:04:23 by mmoussou ### ########.fr */
/* Updated: 2024/07/15 14:45:09 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,9 +48,9 @@ void print_return_value(int return_code)
{
code = WTERMSIG(return_code);
get_exit_code(128 + code);
if (WCOREDUMP(return_code))
if (WCOREDUMP(return_code) && sigmsg[code])
printf("minishell : %s %s\n", sigmsg[code], ERROR_COREDUMP);
else
else if (sigmsg[code])
printf("minishell : %s\n", sigmsg[code]);
}
}