-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfell_env_struct.c
70 lines (63 loc) · 1.64 KB
/
fell_env_struct.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fell_env_struct.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emohamed <emohamed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/18 10:59:43 by emohamed #+# #+# */
/* Updated: 2023/09/30 22:32:10 by emohamed ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void free_x_dmax(char **str)
{
int i;
i = 0;
while (str[i])
{
free(str[i]);
i++;
}
}
char *dp_en(const char *s1)
{
int i;
char *p;
if (!s1)
return (0);
i = 0;
p = malloc(sizeof(char) * ft_strlen(s1) + 1);
if (!p)
return (NULL);
while (s1[i])
{
p[i] = s1[i];
i++;
}
p[i] = '\0';
return (p);
}
void fell_env_struct(t_vars *vars)
{
int i;
char *key;
char **tempers;
i = 0;
tempers = NULL;
while (vars->envp[i])
{
tempers = ft_split_export(vars->envp[i], '=');
key = tempers[0];
vars->env[i].key = dp_en(key);
if (ft_strchr(vars->envp[i], '='))
{
vars->env[i].is_equal = 1;
vars->env[i].value = dp_en(ft_strchr(vars->envp[i], '=') + 1);
}
if (tempers)
free_x_dmax(tempers);
tempers = NULL;
i++;
}
}