mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🔨」 fix(builtins/ft_exit): fix close 0 1 2 + exit alone leaks fix + normed
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/15 12:28:36 by adjoly #+# #+# */
|
/* 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;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 3;
|
||||||
while (i < 1024)
|
while (i < 1024)
|
||||||
{
|
{
|
||||||
close(i);
|
close(i);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
|
/* 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);
|
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;
|
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)
|
if (ac < 2)
|
||||||
|
{
|
||||||
|
free_exit(env, env_array);
|
||||||
exit(get_exit_code(-1));
|
exit(get_exit_code(-1));
|
||||||
|
}
|
||||||
if (check_exit_value(argv[1]))
|
if (check_exit_value(argv[1]))
|
||||||
{
|
{
|
||||||
printf("minishell: exit: %s: numeric argument required\n", 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);
|
exit(2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
exit_args_handler(argv, ac, env_array, env);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user