environment_del en simple unset
This commit is contained in:
parent
5c1d76fe83
commit
bb0e90c846
@ -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
|
||||
|
||||
42
src/environment/environment_del.c
Normal file
42
src/environment/environment_del.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* environment_del.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user