mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix(builtins/export): fixed double values when empty + leaks
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/11 19:00:04 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/07/13 16:10:38 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -30,6 +30,7 @@ void ft_env(t_env *env);
|
||||
void ft_unset(char *arg, t_env *env);
|
||||
|
||||
char **env_get_list(t_env *env);
|
||||
void add_to_env(char *name, char *content, t_env *env);
|
||||
void ft_export(char **args, t_env *env);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/11 19:07:01 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/07/13 16:11:55 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -62,6 +62,7 @@ void env_print_in_order(t_env *env_l)
|
||||
printf("declare -x %s\n", env[i]);
|
||||
i++;
|
||||
}
|
||||
ft_free("a", &env);
|
||||
return ;
|
||||
}
|
||||
|
||||
@ -74,7 +75,7 @@ int export_value(char *arg, t_env *env)
|
||||
{
|
||||
name = ft_strdup(arg);
|
||||
if (name)
|
||||
ft_envadd_back(&env, ft_envnew(name, ft_calloc(1, 1)));
|
||||
add_to_env(name, NULL, env);
|
||||
return (-1);
|
||||
}
|
||||
name = ft_calloc(sizeof(char), ft_strchr(arg, '=') - arg + 1);
|
||||
@ -87,10 +88,7 @@ int export_value(char *arg, t_env *env)
|
||||
ft_strlcpy(name, arg, ft_strchr(arg, '=') - arg + 1);
|
||||
ft_strlcpy(content, ft_strchr(arg, '=') + 1,
|
||||
ft_strlen(ft_strchr(arg, '=')) + 1);
|
||||
if (env_get_value(name, env))
|
||||
env_edit(name, content, env);
|
||||
else
|
||||
ft_envadd_back(&env, ft_envnew(name, content));
|
||||
add_to_env(name, content, env);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/11 18:59:27 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/11 18:59:42 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/07/13 16:10:28 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -51,3 +51,15 @@ char **env_get_list(t_env *env)
|
||||
}
|
||||
return (ar);
|
||||
}
|
||||
|
||||
void add_to_env(char *name, char *content, t_env *env)
|
||||
{
|
||||
if (!content)
|
||||
content = ft_calloc(1, 1);
|
||||
if (!content)
|
||||
return ;
|
||||
if (env_get_value(name, env))
|
||||
env_edit(name, content, env);
|
||||
else
|
||||
ft_envadd_back(&env, ft_envnew(name, content));
|
||||
}
|
||||
|
Reference in New Issue
Block a user