blob: a39b246da6a4a030baba1da79849f3319d68c0b4 (
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* environment.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:21:24 by cacharle #+# #+# */
/* Updated: 2020/02/28 12:30:55 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define MS_ENVIRONMENT_HT_SIZE 2048
t_ftht *ms_environment_from_array(const char **envp)
{
t_ftht *environment;
int i;
char *key;
char *value;
/* int equal_pos; */
if (envp == NULL)
return (NULL);
if ((environment = ft_htnew(MS_ENVIRONMENT_HT_SIZE)) == NULL)
return (NULL);
i = -1;
while (envp[++i] != NULL)
{
// free stuff on error
if ((value = ft_strchr(envp[i], '=')) == NULL)
return (NULL);
if ((key = ft_strndup(envp[i], ft_strspn(envp[i], "="))) == NULL)
return (NULL);
if ((value = ft_strdup(value)) == NULL)
return (NULL);
if (ft_htset(environment, key, value, ms_ht_del_str_entry) == NULL)
return (NULL);
}
return (environment);
}
char **ms_environment_to_array(t_ftht *environment)
{
(void)environment;
// need ft_htlen
return (NULL);
}
/* void ms_environment_destroy(t_ftht *environment) */
/* { */
/* ft_htdestroy(environment, ms_ht_del_str_entry); */
/* } */
|