-
Notifications
You must be signed in to change notification settings - Fork 0
/
minishell_outils2.c
53 lines (48 loc) · 1.56 KB
/
minishell_outils2.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
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell_outils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eelaazmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/20 18:53:25 by eelaazmi #+# #+# */
/* Updated: 2021/12/20 18:53:27 by eelaazmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_env *fill_env(t_env *env, char *envp)
{
char **help;
help = ft_split(envp, '=');
env->key = ft_strdup(help[0]);
env->value = ft_strdup(help[1]);
ft_free(help, 0);
return (env);
}
t_env *split_env(t_env *env, char **envp)
{
t_env *tmp;
int i;
env = (t_env *)malloc(sizeof(t_env));
i = 0;
env = fill_env(env, envp[0]);
tmp = env;
env->next = (t_env *)malloc(sizeof(t_env));
if (!env->next)
return (NULL);
env = env->next;
while (envp[++i])
{
env = fill_env(env, envp[i]);
if (envp[i + 1])
{
env->next = (t_env *)malloc(sizeof(t_env));
if (!env->next)
return (NULL);
env = env->next;
}
}
env->next = NULL;
env = tmp;
return (env);
}