shell_script()
+ reset "rl_event_hook" to NULL after here_doc() + split init.c in multiple files + submodule minishell_tests
This commit is contained in:
37
srcs/init/init_shlvl.c
Normal file
37
srcs/init/init_shlvl.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_shlvl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/18 04:35:33 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int init_shlvl(void)
|
||||
{
|
||||
char *tmp;
|
||||
int ret;
|
||||
|
||||
tmp = getenv("SHLVL");
|
||||
if (tmp && ft_isdigit_str(tmp))
|
||||
{
|
||||
tmp = ft_itoa(ft_atoi(tmp) + 1);
|
||||
if (!tmp)
|
||||
return (0);
|
||||
tmp = ft_strjoinfree_s2("SHLVL=", tmp);
|
||||
if (!tmp)
|
||||
return (0);
|
||||
ret = export_var(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
else
|
||||
ret = export_var("SHLVL=1");
|
||||
if (ret == -1)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
Reference in New Issue
Block a user