Ajout d'une fonction t_list -> char** nommé 'env_to_strs'

This commit is contained in:
Etienne Rey-bethbeder 2023-02-17 13:06:16 +01:00
parent 96da8e54c3
commit 8b771d6615

33
env.c
View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */ /* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/02/16 16:24:21 by cchauvet ### ########.fr */ /* Updated: 2023/02/17 13:05:29 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -205,7 +205,8 @@ int set_value_by_key(char *key, char *value, t_list **head)
int create_value_by_key(char *key, char *value, t_list **head) int create_value_by_key(char *key, char *value, t_list **head)
{ {
t_env *content; t_env *content;
if (set_value_by_key(key, value, head) == 0) if (set_value_by_key(key, value, head) == 0)
return (0); return (0);
content = ft_calloc(1, sizeof(t_env)); content = ft_calloc(1, sizeof(t_env));
@ -217,6 +218,25 @@ int create_value_by_key(char *key, char *value, t_list **head)
return (0); return (0);
} }
char **env_to_strs(t_list **head)
{
t_list *current;
t_env *content;
char **env;
int i;
current = *head;
env = ft_calloc(ft_lstsize(*head), sizeof(char *));
i = 0;
while (current->content)
{
content = current->content;
env[i++] = ft_strmerger(3, content->key, "=", content->value);
current = current->next;
}
return (env);
}
t_list **init_env(char **env) t_list **init_env(char **env)
{ {
t_list **head; t_list **head;
@ -241,3 +261,12 @@ t_list **init_env(char **env)
} }
return (head); return (head);
} }
/*int main(int argc, char *argv[], char **env)
{
t_list **new;
new = init_env(env);
ft_printf("%S", env_to_strs(new));
return (0);
}*/