minishell/src/environment/environment_add.c
whaffman ab72bd5bbb malloc_safe
- add freelist to minishell
- add t_minishell *minishell to all function calling malloc_free
- substituted all malloc calls but the first to malloc_safe
2025-02-25 14:54:17 +01:00

40 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* environment_add.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:33 by whaffman #+# #+# */
/* Updated: 2025/02/25 14:28:43 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void environment_add(t_minishell *minishell, char *name, char *value)
{
t_environment *new_environment;
t_list *new_node;
t_list **environment;
environment = &minishell->environment;
if (name != NULL && value != NULL)
{
new_environment = malloc_safe(minishell, sizeof(t_environment));
if (new_environment == NULL)
return (perror("malloc"));
new_environment->name = ft_strdup(name);
new_environment->value = ft_strdup(value);
new_node = ft_lstnew(new_environment);
if (new_node == NULL
|| new_environment->name == NULL
|| new_environment->value == NULL)
{
environment_free(new_environment);
return (perror("malloc"));
}
ft_lstadd_back(environment, new_node);
}
}