Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/env/ft_env_list.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_env_list.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/26 18:16:13 by yabtaour #+# #+# */
9
/* Updated: 2022/09/21 16:00:21 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
t_env *ft_new_env_node(char *value)
16
{
17
t_env *node;
18
int i;
19
20
i = 0;
21
node = NULL;
22
node = malloc(sizeof(t_env));
23
if (!node)
24
exit (1);
25
while (value[i] != '=')
26
i++;
27
node->name = ft_substr(value, 0, i);
28
i++;
29
if (value[i])
30
node->value = ft_substr(value, i, ft_strlen(value) - i);
31
node->next = NULL;
32
node->prev = NULL;
33
return (node);
34
}
35
36
t_env *ft_add_to_env_back(t_env *envi, char *value)
37
{
38
t_env *node;
39
t_env *envi_clone;
40
41
if (!value)
42
return (NULL);
43
node = ft_new_env_node(value);
44
if (envi == NULL)
45
return (node);
46
envi_clone = envi;
47
while (envi_clone->next != NULL)
48
envi_clone = envi_clone->next;
49
envi_clone->next = node;
50
node->prev = envi_clone;
51
return (envi);
52
}
53
54