moved env functions to libft
This commit is contained in:
29
libft/srcs/ft_envnew.c
Normal file
29
libft/srcs/ft_envnew.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
Reference in New Issue
Block a user