From 8b771d661579b15f30aab23b5120887903f9817c Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Fri, 17 Feb 2023 13:06:16 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20fonction=20t=5Flist=20->=20char?= =?UTF-8?q?**=20nomm=C3=A9=20'env=5Fto=5Fstrs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/env.c b/env.c index bb3d3f8..ca51da5 100644 --- a/env.c +++ b/env.c @@ -6,7 +6,7 @@ /* 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) { - t_env *content; + t_env *content; + if (set_value_by_key(key, value, head) == 0) return (0); 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); } +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 **head; @@ -241,3 +261,12 @@ t_list **init_env(char **env) } 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); +}*/