Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/builtin/export/export_utils3.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* export_utils3.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/07/27 17:56:26 by yabtaour #+# #+# */
9
/* Updated: 2022/07/27 17:56:27 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../../minishell.h"
14
15
t_env *ft_new_node(char *name, char *value)
16
{
17
t_env *node;
18
19
node = malloc (sizeof(t_env));
20
if (!node)
21
exit (1);
22
if (name)
23
node->name = ft_substr(name, 0, ft_strlen(name));
24
if (!node->name)
25
exit (1);
26
if (value)
27
{
28
if (ft_strlen(value))
29
node->value = ft_substr(value, 0, ft_strlen(value));
30
else
31
{
32
node->value = malloc (sizeof(char) * 1);
33
node->value[0] = '\0';
34
}
35
}
36
else
37
node->value = NULL;
38
node->next = NULL;
39
node->prev = NULL;
40
return (node);
41
}
42
43
void ft_add_new_env(t_data *data, char *name, char *value)
44
{
45
t_env *env_clone;
46
t_env *new_node;
47
48
env_clone = data->lst_env;
49
new_node = ft_new_node(name, value);
50
if (!env_clone)
51
{
52
if (new_node)
53
data->lst_env = new_node;
54
return ;
55
}
56
while (env_clone->next)
57
env_clone = env_clone->next;
58
if (new_node)
59
{
60
env_clone->next = new_node;
61
new_node->prev = env_clone;
62
}
63
}
64
65