-
Notifications
You must be signed in to change notification settings - Fork 0
/
unset.c
65 lines (60 loc) · 1.77 KB
/
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
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apashkov <apashkov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/17 09:02:57 by apashkov #+# #+# */
/* Updated: 2024/04/03 17:14:30 by apashkov ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int unset_one(t_env **env_list, char *input, t_alloc *mllcd)
{
t_env *head;
t_env *temp;
head = *env_list;
while (head && ft_strncmp(input, head->env_var, ft_strlen(input)))
{
temp = head;
head = head->next;
}
if (head)
{
if (!ft_strncmp(input, (*env_list)->env_var, ft_strlen(input)))
{
temp = head->next;
*env_list = temp;
}
else
temp->next = head->next;
if (head->malloced == true)
free(head->env_var);
free(head);
mllcd->exit_status = 0;
}
return (0);
}
int unset(char **cmd, t_alloc *mllcd)
{
int i;
i = 0;
if (!cmd[1])
{
mllcd->exit_status = 0;
return (0);
}
if (cmd[1][0] == '-')
{
ft_putstr_fd("unset: ", 2);
ft_putchar_fd(cmd[1][0], 2);
ft_putchar_fd(cmd[1][1], 2);
ft_putstr_fd(": invalid option\n", 2);
mllcd->exit_status = 2;
return (2);
}
while (cmd[++i])
unset_one(&mllcd->env_list, cmd[i], mllcd);
return (0);
}