summaryrefslogtreecommitdiffstats
path: root/src/ft_s_init.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-04-29 11:47:02 +0200
committersalad <fmoenne-@student.le-101.fr>2020-04-29 11:47:02 +0200
commit961bda4f42562bf8ceb70a888730362d021c5552 (patch)
tree820577dc790c3a8884c44b329d04a8d42ed1ca44 /src/ft_s_init.c
parentsimple really (diff)
parentTrying vars (diff)
download42-minishell-961bda4f42562bf8ceb70a888730362d021c5552.tar.gz
42-minishell-961bda4f42562bf8ceb70a888730362d021c5552.tar.bz2
42-minishell-961bda4f42562bf8ceb70a888730362d021c5552.tar.xz
42-minishell-961bda4f42562bf8ceb70a888730362d021c5552.tar.zst
42-minishell-961bda4f42562bf8ceb70a888730362d021c5552.zip
merge master into fmoenne_indahouse
Diffstat (limited to 'src/ft_s_init.c')
-rw-r--r--src/ft_s_init.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/ft_s_init.c b/src/ft_s_init.c
index 46dac90..88a3817 100644
--- a/src/ft_s_init.c
+++ b/src/ft_s_init.c
@@ -11,6 +11,7 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
@@ -18,9 +19,48 @@
#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 *const 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[])
+ *ft_init_msh(char *const argv[],
+ char *const envp[])
{
t_msh *msh;
@@ -30,12 +70,16 @@ 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 */
- msh->envp = envp;
+ msh->envp = NULL;
+ if (!(msh->envp = ft_dupenv(envp)))
+ return (NULL);
msh->ret = 0;
ft_init_buptr(msh);
msh->curr = NULL;
+ msh->vars = NULL;
return (msh);
}