Feat(WIP): Added possibility to cmd_env to execute commands with
altered env. Added dummy function for cd, echo, setenv & unsetenv Started work on env copy feature
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */
|
||||
/* Updated: 2019/09/20 12:00:38 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/09/20 15:32:46 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -41,3 +41,48 @@ t_list *env2lst(char **env)
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user