This commit is contained in:
mdev9
2024-04-24 14:06:52 +02:00
parent 285a99b6a9
commit 6a05ea29a2
4 changed files with 19 additions and 12 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */ /* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
/* Updated: 2024/04/24 13:06:58 by tomoron ### ########.fr */ /* Updated: 2024/04/24 13:45:58 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,18 +21,11 @@ int export_invalid_identifier(char *arg, char *name)
return (1); return (1);
} }
t_env *export_set_env(t_env *env, char *name, char *value, int append) t_env *set_env(t_env *env, char *name, char *value, int append)
{ {
t_env *tmp; t_env *tmp;
tmp = env; tmp = env;
if (!value || !name)
{
free(name);
free(value);
ft_printf_fd(2, "minishell: malloc failed");
return (env);
}
while (tmp) while (tmp)
{ {
if (!ft_strcmp(name, tmp->name)) if (!ft_strcmp(name, tmp->name))
@ -53,6 +46,19 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append)
} }
tmp = tmp->next; tmp = tmp->next;
} }
return (env);
}
t_env *export_set_env(t_env *env, char *name, char *value, int append)
{
if (!value || !name)
{
free(name);
free(value);
ft_printf_fd(2, "minishell: malloc failed");
return (env);
}
set_env(env, name, value, append);
return (env_add_back(env, name, value)); return (env_add_back(env, name, value));
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/04/24 13:07:14 by tomoron ### ########.fr */ /* Updated: 2024/04/24 13:34:44 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -77,13 +77,13 @@ t_env *add_shlvl(t_env *env)
char *tmp; char *tmp;
tmp = ft_get_env(env, "SHLVL"); tmp = ft_get_env(env, "SHLVL");
if(!tmp) if (!tmp)
nb = 0; nb = 0;
else else
nb = ft_atoi(tmp); nb = ft_atoi(tmp);
nb++; nb++;
env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0); env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0);
return(env); return (env);
} }
int init_minishell(t_msh **msh, int argc, char **argv, char **envp) int init_minishell(t_msh **msh, int argc, char **argv, char **envp)

View File

@ -17,3 +17,4 @@ To test:
test signals test signals
test and verify all malocs test and verify all malocs
verify forbidden functions verify forbidden functions
check for any hidden or useless files