blob: ca07f9f94f0ce5051bce2c22d03f4a02f38cf985 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:31:07 by chuhlig #+# #+# */
/* Updated: 2024/10/25 15:48:56 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "env.h"
#include "get_next_line.h"
#include "libft.h"
void getenvlst(t_env **env, char **en)
{
char *tmp;
int i;
t_env *current;
i = 0;
while (en[i] != NULL)
{
tmp = ft_strchr(en[i], '=');
*tmp = '\0';
current = *env;
current = malloc(sizeof(t_env));
current->name = ft_strdup(en[i]);
current->value = ft_strdup(tmp + 1);
current->next = *env;
*env = current;
i++;
}
}
void free_envlst(t_env **env)
{
t_env *cur;
t_env *new;
cur = *env;
while (cur)
{
new = cur->next;
free(cur->name);
free(cur->value);
free(cur);
cur = new;
}
}
char *env_get(t_env *env, char *name)
{
while (env != NULL)
{
if (!ft_strncmp(env->name, name, ft_strlen(name)))
return (env->value);
env = env->next;
}
return (NULL);
}
|