diff options
Diffstat (limited to 'src/s_init.c')
-rw-r--r-- | src/s_init.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/s_init.c b/src/s_init.c index 1dbbbb7..ab64603 100644 --- a/src/s_init.c +++ b/src/s_init.c @@ -20,6 +20,7 @@ #include "b_export_next.h" #include "d_define.h" +#include "f_fail.h" #include "m_funptr.h" #include "s_init.h" #include "u_vars.h" @@ -67,14 +68,31 @@ static char static void inc_shlvl(t_msh *msh) { + int32_t shlvl; char *str_one; char *str_two; + char *tmp; + char fmt[8]; - u_subst_var_value("$SHLVL", - str_one = ft_itoa( - ft_atoi(str_two = u_get_var_value("$SHLVL", msh)) + 1), msh); - ft_memdel((void*)&str_one); - ft_memdel((void*)&str_two); + if ((tmp = u_get_var_value("$SHLVL", msh)) == NULL) + { + ft_memcpy(fmt, "SHLVL=1", 8); + b_export_with_equals(fmt, msh); + } + else + { + ft_memdel((void*)&tmp); + str_two = u_get_var_value("$SHLVL", msh); + shlvl = ft_atoi(str_two); + if (shlvl >= 999) + f_shlvl_too_high(shlvl); + shlvl = (shlvl >= 999) ? 0 : shlvl; + shlvl = (shlvl < 0) ? 0 : shlvl + 1; + str_one = ft_itoa(shlvl); + u_subst_var_value("$SHLVL", str_one, msh); + ft_memdel((void*)&str_one); + ft_memdel((void*)&str_two); + } } static char @@ -91,7 +109,7 @@ static char b_export_with_equals(fmt, msh); return (cwd); } - if ((dir = opendir(cwd)) != 0) + if ((dir = opendir(cwd)) != NULL) closedir(dir); else if (errno == ENOENT) { |