minishell/src/environment/environment_get_arr.c
whaffman 869eb0d857 Environment
environment: rename functions
environment: add get_arr function
builtins: add export builtin
2025-02-08 14:43:53 +01:00

43 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* environment_get_arr.c :+: :+: */
/* +:+ */
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 13:59:48 by willem #+# #+# */
/* Updated: 2025/02/08 13:59:49 by willem ######## odam.nl */
/* */
/* ************************************************************************** */
# include "minishell.h"
char **environment_get_arr(t_list *environment)
{
char **arr;
t_environment *env;
int i;
arr = malloc(sizeof(char *) * (ft_lstsize(environment) + 1));
if (arr == NULL)
return (NULL);
i = 0;
while (environment != NULL)
{
env = (t_environment *)environment->content;
arr[i] = malloc(ft_strlen(env->name) + ft_strlen(env->value) + 2);
if (arr[i] == NULL)
{
ft_free_arr(arr);
return (NULL);
}
ft_strlcpy(arr[i], env->name, ft_strlen(env->name) + 1);
ft_strlcat(arr[i], "=", ft_strlen(env->name) + 2);
ft_strlcat(arr[i], env->value, ft_strlen(env->name) + ft_strlen(env->value) + 2);
environment = environment->next;
i++;
}
arr[i] = NULL;
return (arr);
}