minishell/srcs/cmd_cd_utils.c
2020-02-14 12:31:39 +01:00

32 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_cd_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 11:55:54 by tmaze #+# #+# */
/* Updated: 2020/02/14 11:56:53 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_env *cd_updateenv(char *key, char *val, t_env **env)
{
t_env *tmp;
if ((tmp = ft_envgetelem(key, *env)) != NULL)
ft_envupdate(key, *env, val);
else if ((tmp = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
{
if ((tmp->key = ft_strdup(key)) == NULL)
ft_envdelelem(&tmp);
if (tmp && (tmp->val = ft_strdup(val)) == NULL)
ft_envdelelem(&tmp);
if (tmp)
ft_envaddend(env, tmp);
}
return (tmp);
}