-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_util2.c
More file actions
65 lines (59 loc) · 1.84 KB
/
main_util2.c
File metadata and controls
65 lines (59 loc) · 1.84 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_util2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shebaz <shebaz@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/20 22:30:12 by szeroual #+# #+# */
/* Updated: 2024/12/18 09:29:21 by shebaz ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_envi *create__node(char *name, char *value)
{
t_envi *new_node;
new_node = malloc(1 * sizeof(t_envi));
if (!new_node)
{
perror("calloc");
exit(EXIT_FAILURE);
}
new_node->name = ft_strdup_1(name);
new_node->vale = ft_strdup_1(value);
if (!new_node->name || !new_node->vale)
{
perror("strdup");
free(new_node->name);
free(new_node->vale);
free(new_node);
exit(EXIT_FAILURE);
}
new_node->next = NULL;
new_node->prv = NULL;
return (new_node);
}
void add_env_node(t_envi **env_list, t_envi *new_node)
{
if (*env_list)
(*env_list)->prv = new_node;
new_node->next = *env_list;
*env_list = new_node;
}
void process_env_entry(char *env_entry, t_envi **env_list)
{
char *name;
char *value;
t_envi *new_node;
name = strtok(env_entry, "=");
value = strtok(NULL, "=");
if (!name || !value)
{
perror("error");
free(env_entry);
return ;
}
new_node = create__node(name, value);
add_env_node(env_list, new_node);
free(env_entry);
}