From abec91e56b179d9d327da2d3d9ae960f5260e14f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 15:09:25 +0200 Subject: Nice functional cd --- src/ft_s_init.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ft_s_init.c') diff --git a/src/ft_s_init.c b/src/ft_s_init.c index 46dac90..76bf72d 100644 --- a/src/ft_s_init.c +++ b/src/ft_s_init.c @@ -30,6 +30,7 @@ t_msh return (NULL); if (!(msh->shname = ft_strdup(argv[0]))) return (NULL); + /* TODO: shname: care about "./", try with symlinks */ msh->cwd = NULL; msh->cwd = getcwd(NULL, 0); /* TODO: handle getcwd failed */ -- cgit v1.2.3 From 8b6c386883878eec839103305b20cb4d63eef873 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 16:05:07 +0200 Subject: duped completely envp --- src/ft_s_init.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/ft_s_init.c') diff --git a/src/ft_s_init.c b/src/ft_s_init.c index 76bf72d..463cb0b 100644 --- a/src/ft_s_init.c +++ b/src/ft_s_init.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include +#include #include #include @@ -18,6 +19,45 @@ #include "ft_m_funptr.h" #include "ft_s_init.h" +static char + **ft_dupenv_del(char **nenvp, + uint64_t i) +{ + while (i > 0) + { + ft_memdel((void*)&nenvp[i]); + i--; + } + ft_memdel((void*)&nenvp); + return (NULL); +} + +static char + **ft_dupenv(char *envp[]) +{ + uint64_t i; + char **nenvp; + + i = 0; + while (envp[i]) + { + i++; + } + if (!(nenvp = (char**)malloc((i + 1) * sizeof(char*)))) + { + return (NULL); + } + i = 0; + while (envp[i]) + { + if (!(nenvp[i] = ft_strdup(envp[i]))) + return (ft_dupenv_del(nenvp, i)); + i++; + } + nenvp[i] = NULL; + return (nenvp); +} + t_msh *ft_init_msh(const char *argv[], char *envp[]) @@ -34,7 +74,9 @@ t_msh msh->cwd = NULL; msh->cwd = getcwd(NULL, 0); /* TODO: handle getcwd failed */ - msh->envp = envp; + msh->envp = NULL; + if (!(msh->envp = ft_dupenv(envp))) + return (NULL); msh->ret = 0; ft_init_buptr(msh); msh->curr = NULL; -- cgit v1.2.3 From 2c9ad3343cb47d9a83f39fd0077fadf98a0cf30b Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 16:10:07 +0200 Subject: Ok argv, envp --- src/ft_s_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ft_s_init.c') diff --git a/src/ft_s_init.c b/src/ft_s_init.c index 463cb0b..26b196b 100644 --- a/src/ft_s_init.c +++ b/src/ft_s_init.c @@ -33,7 +33,7 @@ static char } static char - **ft_dupenv(char *envp[]) + **ft_dupenv(char *const envp[]) { uint64_t i; char **nenvp; @@ -59,8 +59,8 @@ static char } t_msh - *ft_init_msh(const char *argv[], - char *envp[]) + *ft_init_msh(char *const argv[], + char *const envp[]) { t_msh *msh; -- cgit v1.2.3 From ed2f6193d141c6b8bab9ee916f74d11db517625b Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 16:49:07 +0200 Subject: Trying vars --- src/ft_s_init.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ft_s_init.c') diff --git a/src/ft_s_init.c b/src/ft_s_init.c index 26b196b..88a3817 100644 --- a/src/ft_s_init.c +++ b/src/ft_s_init.c @@ -80,5 +80,6 @@ t_msh msh->ret = 0; ft_init_buptr(msh); msh->curr = NULL; + msh->vars = NULL; return (msh); } -- cgit v1.2.3