diff --git a/inc/environment.h b/inc/environment.h index 7dd7beb..29dac33 100644 --- a/inc/environment.h +++ b/inc/environment.h @@ -21,5 +21,6 @@ t_environment *environment_get(t_list *environment, char *name); void environment_free(t_list *environment); int environment_parse(char **envp, t_list **environment); char **environment_get_arr(t_list *environment); +void environment_del(t_list **environment, char *name); #endif // environment_H diff --git a/src/environment/environment_del.c b/src/environment/environment_del.c new file mode 100644 index 0000000..c531c66 --- /dev/null +++ b/src/environment/environment_del.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* environment_del.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/02/11 14:17:53 by whaffman #+# #+# */ +/* Updated: 2025/02/11 14:33:29 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void environment_del(t_list **environment, char *name) +{ + t_list *prev; + t_list *current; + t_list *next; + + prev = NULL; + next = NULL; + current = *environment; + while (current != NULL) + { + if (ft_strncmp(((t_environment *)current->content)->name, name, ft_strlen(name) + 1) == 0) + { + next = current->next; + free(((t_environment *)current->content)->name); + free(((t_environment *)current->content)->value); + free(current->content); + free(current); + if (prev == NULL) + *environment = next; + else + prev->next = next; + return ; + } + prev = current; + current = current->next; + } +} diff --git a/src/utils/simple_builtins.c b/src/utils/simple_builtins.c index 0d9b89d..80007a4 100644 --- a/src/utils/simple_builtins.c +++ b/src/utils/simple_builtins.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */ -/* Updated: 2025/02/11 14:09:49 by whaffman ######## odam.nl */ +/* Updated: 2025/02/11 14:30:38 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -94,6 +94,8 @@ void simple_builtins(t_minishell *minishell) } else if (cmp_value(minishell->tokens, "export")) builtin_export(minishell); + else if (cmp_value(minishell->tokens, "unset")) + environment_del(&(minishell->environment), ((t_token *)minishell->tokens->next->content)->value); else { path = executor_absolute_path(minishell->environment, ((t_token *)minishell->tokens->content)->value);