Ajout d'une fonction t_list -> char** nommé 'env_to_strs'
This commit is contained in:
parent
96da8e54c3
commit
8b771d6615
31
env.c
31
env.c
@ -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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -206,6 +206,7 @@ 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);
|
||||||
|
}*/
|
||||||
|
Loading…
Reference in New Issue
Block a user