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); +}*/