-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterate_shlvl.c
45 lines (40 loc) · 1.35 KB
/
iterate_shlvl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* iterate_shlvl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: auspensk <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/11 10:28:57 by auspensk #+# #+# */
/* Updated: 2024/10/11 10:57:16 by auspensk ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int find_envp(char **envp, char *key)
{
int i;
i = 0;
while (envp[i])
{
if (!ft_strncmp(envp[i], key, ft_strlen(key)))
return (i);
i++;
}
return (-1);
}
void iterate_shlvl(t_data *data)
{
int i;
int lvl;
char *shlvl;
i = find_envp(data->envp, "SHLVL=");
if (i < 0)
ft_export("SHLVL=1", NULL, data);
else
{
lvl = ft_atoi(&(data->envp[i][6]));
lvl ++;
shlvl = ft_strjoin("SHLVL=", ft_itoa(lvl));
ft_export(shlvl, NULL, data);
}
}