45 lines
1.6 KiB
C
45 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_envnew.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/12/05 14:54:55 by tmaze #+# #+# */
|
|
/* Updated: 2019/12/05 17:12:59 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
t_env *ft_envnew(char *env)
|
|
{
|
|
t_env *ret;
|
|
int i;
|
|
|
|
i = 0;
|
|
ret = NULL;
|
|
while (env[i] && env[i] != '=')
|
|
i++;
|
|
if (env[i] == '=' && (ret = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
|
|
if ((ret->val = ft_strsub(env, i + 1, ft_strlen(env) - i - 1)) == NULL
|
|
|| (ret->key = ft_strsub(env, 0, i)) == NULL)
|
|
ft_envdelelem(&ret);
|
|
return (ret);
|
|
}
|
|
|
|
t_env *ft_envnewinit(char *key, char *val, t_env *env)
|
|
{
|
|
t_env *ret;
|
|
int i;
|
|
|
|
i = 0;
|
|
ret = NULL;
|
|
if ((ret = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
|
|
if ((ret->key = ft_strdup(key)) != NULL)
|
|
if ((ret->val = ft_strdup(val)) != NULL)
|
|
return (ret);
|
|
ft_envdelelem(&ret);
|
|
return (ret);
|
|
}
|