summaryrefslogtreecommitdiffstats
path: root/src/s_init.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-05 23:05:03 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-05 23:05:03 +0200
commitf7b13a353092017e37045344528c985172eafc3a (patch)
treec0bf8c6e8611cb72055f6a65634d1d0d35d6c4d8 /src/s_init.c
parentNew utils functions (diff)
download42-minishell-f7b13a353092017e37045344528c985172eafc3a.tar.gz
42-minishell-f7b13a353092017e37045344528c985172eafc3a.tar.bz2
42-minishell-f7b13a353092017e37045344528c985172eafc3a.tar.xz
42-minishell-f7b13a353092017e37045344528c985172eafc3a.tar.zst
42-minishell-f7b13a353092017e37045344528c985172eafc3a.zip
Vars are fixed and finished
Diffstat (limited to 'src/s_init.c')
-rw-r--r--src/s_init.c30
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)
{