-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_utils.c
77 lines (68 loc) · 1.8 KB
/
env_utils.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
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aoizel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 13:52:13 by aoizel #+# #+# */
/* Updated: 2024/01/09 13:56:58 by aoizel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
size_t env_lst_len(t_envlst *env_list)
{
size_t count;
count = 0;
if (env_list == NULL)
return (0);
while (env_list != NULL)
{
count++;
env_list = env_list->next;
}
return (count);
}
void env_putkey(char *keyvalue, char *elem_key)
{
size_t i;
i = 0;
while (keyvalue[i] && keyvalue[i] != '=')
{
elem_key[i] = keyvalue[i];
i++;
}
elem_key[i] = '\0';
}
void env_putvalue(char *keyvalue, char *elem_value)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (keyvalue[i] && keyvalue[i] != '=')
i++;
if (keyvalue[i] == '=')
i++;
while (keyvalue[i] && keyvalue[i] != '=')
{
elem_value[j] = keyvalue[i];
i++;
j++;
}
elem_value[j] = '\0';
}
void env_destroy(t_envlst *envlst)
{
t_envlst *curr_elem;
t_envlst *next_elem;
curr_elem = envlst;
while (curr_elem)
{
free(curr_elem->key);
free(curr_elem->value);
next_elem = curr_elem->next;
free(curr_elem);
curr_elem = next_elem;
}
}