/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ms_env.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */ /* Updated: 2019/09/20 15:32:46 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" void lstdelenvelem(void *content, size_t size) { size = 0; ft_strdel(&(((char**)content)[1])); ft_strdel(&(((char**)content)[0])); ft_memdel(&content); } t_list *env2lst(char **env) { t_list *ret; t_list *new; int i; i = 0; ret = NULL; while (env[i]) { if ((new = (t_list*)ft_memalloc(sizeof(t_list))) == NULL || (new->content = ft_strsplit(env[i], '=')) == NULL || ft_lstaddend(&ret, new) == NULL) { ft_lstdel(&ret, &lstdelenvelem); return (NULL); } i++; } return (ret); } t_list *env_cpy(t_list *env) { t_list *it; t_list *new; t_list *cpy; int i; it = env; cpy = NULL; while (it) { while (((char**)it->content)[i]) i++; i++; if ((new = (t_list*)ft_memalloc(sizeof(t_list))) == NULL || (new->content = ft_memalloc(sizeof(char*)) * i) == NULL) { ft_lstdelenvelem(new->content, 0); ft_memdel(&new); ft_lstdel(&cpy, &lstdelenvelem); return (NULL); } i = 0; while (((char**)it->content)[i]) { if ((((char**)new->content)[i] = ft_strdup(((char**)it->content)[i])) == NULL) { ft_lstdelenvelem(new->content, 0); ft_memdel(&new); ft_lstdel(&cpy, &lstdelenvelem); return (NULL); } } ((char**)new->content)[i] = NULL; if (lst_addend(&cpy, new) == NULL) { ft_lstdelenvelem(new->content, 0); ft_lstdel(&cpy, &lstdelenvelem); return (NULL); } } }