🔨」 fix(builtins/ft_exit): fix close 0 1 2 + exit alone leaks fix + normed

This commit is contained in:
yosyo
2024-07-15 16:09:00 +02:00
parent de3b52d9d4
commit 51056c3986
2 changed files with 23 additions and 17 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/15 12:28:36 by adjoly #+# #+# */
/* Updated: 2024/07/15 15:50:55 by mmoussou ### ########.fr */
/* Updated: 2024/07/15 16:07:23 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@ void free_exit(t_env *env, char **env_array)
{
int i;
i = 0;
i = 3;
while (i < 1024)
{
close(i);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
/* Updated: 2024/07/15 15:49:06 by mmoussou ### ########.fr */
/* Updated: 2024/07/15 16:07:11 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,12 +31,30 @@ int check_exit_value(char *str)
return (0);
}
void ft_exit(char **argv, int ac, char **env_array, t_env *env)
void exit_args_handler(char **argv, int ac, char **env_array, t_env *env)
{
int return_value;
if (ac > 2)
{
printf("minishell: exit: too many arguments\n");
get_exit_code(1);
return ;
}
return_value = atoi(argv[1]);
if (return_value == -1)
return_value += 255;
free_exit(env, env_array);
exit(get_exit_code(return_value));
}
void ft_exit(char **argv, int ac, char **env_array, t_env *env)
{
if (ac < 2)
{
free_exit(env, env_array);
exit(get_exit_code(-1));
}
if (check_exit_value(argv[1]))
{
printf("minishell: exit: %s: numeric argument required\n", argv[1]);
@ -44,17 +62,5 @@ void ft_exit(char **argv, int ac, char **env_array, t_env *env)
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;
free_exit(env, env_array);
exit(get_exit_code(return_value));
}
}
get_exit_code(1);
exit_args_handler(argv, ac, env_array, env);
}