-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin_unset.c
57 lines (52 loc) · 1.7 KB
/
builtin_unset.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marlean <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/03 10:53:59 by hcolumbu #+# #+# */
/* Updated: 2022/06/17 13:51:36 by marlean ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void delete_from_env(t_envp **envp_list, char *arg)
{
t_envp *tmp;
tmp = *envp_list;
while (*envp_list)
{
if (*envp_list && !ft_strcmp((*envp_list)->key, arg))
{
tmp = (*envp_list)->next;
free((*envp_list)->key);
free((*envp_list)->value);
free (*envp_list);
*envp_list = tmp;
}
if ((*envp_list)->next && !ft_strcmp((*envp_list)->next->key, arg))
{
free((*envp_list)->next->key);
free((*envp_list)->next->value);
free((*envp_list)->next);
(*envp_list)->next = (*envp_list)->next->next;
}
*envp_list = (*envp_list)->next;
}
*envp_list = tmp;
}
int builtin_unset(t_com *com, t_envp **envp_list)
{
int i;
if (!envp_list || !com)
return (1);
if (!com->arg)
return (0);
i = 0;
while (com->arg[i])
{
delete_from_env(envp_list, com->arg[i]);
i++;
}
return (0);
}