made environment use ft_lstclear
This commit is contained in:
parent
bb0e90c846
commit
71d1797a22
@ -6,21 +6,22 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/04 16:26:35 by whaffman #+# #+# */
|
/* Created: 2025/02/04 16:26:35 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/05 12:36:59 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/11 15:39:15 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef environment_H
|
#ifndef ENVIRONMENT_H
|
||||||
# define environment_H
|
# define ENVIRONMENT_H
|
||||||
|
|
||||||
# include "minishell.h"
|
# include "minishell.h"
|
||||||
|
|
||||||
void environment_add(t_list **environment, char *name, char *value);
|
void environment_add(t_list **environment, char *name, char *value);
|
||||||
void environment_print(t_list *environment);
|
void environment_print(t_list *environment);
|
||||||
t_environment *environment_get(t_list *environment, char *name);
|
t_environment *environment_get(t_list *environment, char *name);
|
||||||
void environment_free(t_list *environment);
|
void environment_free_list(t_list **environment);
|
||||||
int environment_parse(char **envp, t_list **environment);
|
int environment_parse(char **envp, t_list **environment);
|
||||||
char **environment_get_arr(t_list *environment);
|
char **environment_get_arr(t_list *environment);
|
||||||
void environment_del(t_list **environment, char *name);
|
void environment_del(t_list **environment, char *name);
|
||||||
|
void environment_free(void *content);
|
||||||
|
|
||||||
#endif // environment_H
|
#endif // ENVIRONMENT_H
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/11 14:17:53 by whaffman #+# #+# */
|
/* Created: 2025/02/11 14:17:53 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/11 14:33:29 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/11 15:40:09 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,18 +17,18 @@ void environment_del(t_list **environment, char *name)
|
|||||||
t_list *prev;
|
t_list *prev;
|
||||||
t_list *current;
|
t_list *current;
|
||||||
t_list *next;
|
t_list *next;
|
||||||
|
t_environment *env;
|
||||||
|
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
next = NULL;
|
next = NULL;
|
||||||
current = *environment;
|
current = *environment;
|
||||||
while (current != NULL)
|
while (current != NULL)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(((t_environment *)current->content)->name, name, ft_strlen(name) + 1) == 0)
|
env = (t_environment *)current->content;
|
||||||
|
if (ft_strncmp(env->name, name, ft_strlen(name) + 1) == 0)
|
||||||
{
|
{
|
||||||
next = current->next;
|
next = current->next;
|
||||||
free(((t_environment *)current->content)->name);
|
environment_free(current->content);
|
||||||
free(((t_environment *)current->content)->value);
|
|
||||||
free(current->content);
|
|
||||||
free(current);
|
free(current);
|
||||||
if (prev == NULL)
|
if (prev == NULL)
|
||||||
*environment = next;
|
*environment = next;
|
||||||
|
|||||||
@ -5,24 +5,19 @@
|
|||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/04 16:13:59 by whaffman #+# #+# */
|
/* Created: 2025/02/11 15:38:43 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/04 16:14:04 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/11 15:38:48 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void environment_free(t_list *environment)
|
void environment_free(void *content)
|
||||||
{
|
{
|
||||||
t_list *tmp;
|
t_environment *env;
|
||||||
|
|
||||||
while (environment != NULL)
|
env = (t_environment *)content;
|
||||||
{
|
free(env->name);
|
||||||
tmp = environment;
|
free(env->value);
|
||||||
environment = environment->next;
|
free(env);
|
||||||
free(((t_environment *)tmp->content)->name);
|
|
||||||
free(((t_environment *)tmp->content)->value);
|
|
||||||
free(tmp->content);
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/environment/environment_free_list.c
Normal file
18
src/environment/environment_free_list.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* :::::::: */
|
||||||
|
/* environment_free_list.c :+: :+: */
|
||||||
|
/* +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
|
/* +#+ */
|
||||||
|
/* Created: 2025/02/04 16:13:59 by whaffman #+# #+# */
|
||||||
|
/* Updated: 2025/02/04 16:14:04 by whaffman ######## odam.nl */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void environment_free_list(t_list **environment)
|
||||||
|
{
|
||||||
|
ft_lstclear(environment, environment_free);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user