summaryrefslogtreecommitdiffstats
path: root/src/s_init_next.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/s_init_next.c')
-rw-r--r--src/s_init_next.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/s_init_next.c b/src/s_init_next.c
index 4521ce1..d506d9d 100644
--- a/src/s_init_next.c
+++ b/src/s_init_next.c
@@ -10,16 +10,17 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
-#include <stdlib.h>
-#include <unistd.h>
#include <dirent.h>
#include <errno.h>
+#include <libft.h>
#ifdef __linux__
# include <linux/limits.h>
#else
# include <limits.h>
#endif
+#include <paths.h>
+#include <stdlib.h>
+#include <unistd.h>
#include "b_export_next.h"
#include "f_fail.h"
@@ -27,7 +28,7 @@
#include "u_vars.h"
#include "u_vars_next.h"
-void s_inc_shlvl(t_msh *msh)
+void s_inc_shlvl(t_msh *msh)
{
char fmt[8];
char tmp[255];
@@ -52,7 +53,7 @@ void s_inc_shlvl(t_msh *msh)
}
}
-char **s_dupenv_del(char **nenvp, unsigned long i)
+char **s_dupenv_del(char **nenvp, unsigned long i)
{
while (i > 0)
{
@@ -63,20 +64,37 @@ char **s_dupenv_del(char **nenvp, unsigned long i)
return (NULL);
}
-char **s_dupenv(char *const envp[])
+static char s_cpy_path(char **ptr, char *nenvp[], size_t *i)
+{
+ char tmp[255];
+
+ if (*ptr != NULL)
+ return (0);
+ if (*ptr == NULL)
+ {
+ ft_sprintf(tmp, "PATH=%s", _PATH_STDPATH);
+ if ((nenvp[*i] = ft_strdup(tmp)) == NULL)
+ return (1);
+ *(i) += 1;
+ }
+ return (0);
+}
+
+char **s_dupenv(char *const envp[])
{
- unsigned long i;
- char **nenvp;
+ size_t i;
+ char **nenvp;
+ char **ptr;
+ ptr = (char**)envp;
+ while (*ptr != NULL && ft_strncmp(*ptr, "PATH=", 5) != 0)
+ ptr++;
i = 0;
while (envp[i] != NULL)
- {
i++;
- }
+ i += (*ptr == NULL) ? (1) : (0);
if ((nenvp = (char**)malloc((i + 1) * sizeof(char*))) == NULL)
- {
return (NULL);
- }
i = 0;
while (envp[i] != NULL)
{
@@ -84,11 +102,13 @@ char **s_dupenv(char *const envp[])
return (s_dupenv_del(nenvp, i));
i++;
}
+ if (s_cpy_path(ptr, nenvp, &i) == 1)
+ return (s_dupenv_del(nenvp, i));
nenvp[i] = NULL;
return (nenvp);
}
-void s_set_cwd(char cwd[], t_msh *msh)
+void s_set_cwd(char cwd[], t_msh *msh)
{
char fmt[PATH_MAX];
DIR *dir;