diff options
Diffstat (limited to '')
-rw-r--r-- | src/s_init_next.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/s_init_next.c b/src/s_init_next.c index 9a98e9a..6ee17d4 100644 --- a/src/s_init_next.c +++ b/src/s_init_next.c @@ -20,15 +20,17 @@ #endif #include <paths.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include "b_export_next.h" #include "f_fail.h" +#include "s_destroy.h" #include "s_struct.h" #include "u_vars.h" #include "u_vars_next.h" -void s_inc_shlvl(t_msh *msh) +char s_inc_shlvl(t_msh *msh) { char fmt[8]; char tmp[255]; @@ -49,8 +51,12 @@ void s_inc_shlvl(t_msh *msh) shlvl = (shlvl >= 999) ? 0 : shlvl; shlvl = (shlvl < 0) ? 0 : shlvl + 1; ft_itoa_s(str, shlvl); - u_subst_var_value("$SHLVL", str, msh); + if (u_subst_var_value("$SHLVL", str, msh) == 1) + { + return (1); + } } + return (0); } char **s_dupenv_del(char **nenvp, unsigned long i) @@ -116,18 +122,26 @@ void s_set_cwd(char cwd[], t_msh *msh) u_get_var_value(cwd, "$PWD", PATH_MAX, msh); if (cwd[0] == C_NUL) { - getcwd(cwd, PATH_MAX); - ft_sprintf(fmt, "%s=%s", "PWD", cwd); - b_export_with_equals(fmt, msh); + if (getcwd(cwd, PATH_MAX) != NULL) + { + ft_sprintf(fmt, "%s=%s", "PWD", cwd); + b_export_with_equals(fmt, msh); + } + else + ft_dprintf(STDERR_FILENO, "minishell: %s\n", strerror(errno)); return ; } if ((dir = opendir(cwd)) != NULL) closedir(dir); else if (errno == ENOENT) { - getcwd(cwd, PATH_MAX); - ft_sprintf(fmt, "%s=%s", "PWD", cwd); - b_export_with_equals(fmt, msh); + if (getcwd(cwd, PATH_MAX) != NULL) + { + ft_sprintf(fmt, "%s=%s", "PWD", cwd); + b_export_with_equals(fmt, msh); + } + else + ft_dprintf(STDERR_FILENO, "minishell: %s\n", strerror(errno)); return ; } } |