-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_env.c
More file actions
66 lines (58 loc) · 1.26 KB
/
Copy pathinit_env.c
File metadata and controls
66 lines (58 loc) · 1.26 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
66
/*
** EPITECH PROJECT, 2023
** B-PSU-200-MPL-2-1-minishell1-victor.boudet
** File description:
** init_env
*/
#include "shell.h"
char **env_fonc(int value, char **array)
{
static char **env = NULL;
switch (value) {
case 0:
env = array;
break;
case 1:
return env;
break;
}
return NULL;
}
void init_env(char **env)
{
env_fonc(0, env);
}
int remove_env(char *name)
{
char **env = env_fonc(1, NULL);
for (int i = 0; env[i] != NULL; i++) {
if (my_strncomp(env[i], name, my_strlen(name))) {
env_fonc(0, remove_row(env, i));
return 0;
}
}
return 0;
}
void add_env(char *name, char *value)
{
char **array = get_env();
int i = 0;
int enter = 0;
char **new = malloc(sizeof(char *) * (array_len(array) + 3));
for (i = 0; array[i] != NULL; i++) {
if (my_strncomp(array[i], name, my_strlen(name))) {
new[i] = my_strcat(my_strcat(name, "="), value);
enter = 1;
} else {
new[i] = array[i];
}
}
if (enter == 0)
new[i] = my_strcat(my_strcat(name, "="), value);
new[i + 1] = NULL;
env_fonc(0, new);
}
char **get_env(void)
{
return env_fonc(1, NULL);
}