-
Notifications
You must be signed in to change notification settings - Fork 0
/
other2.c
90 lines (82 loc) · 2.08 KB
/
other2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* other2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aulamber <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/05/18 23:35:19 by aulamber #+# #+# */
/* Updated: 2014/05/19 00:00:24 by aulamber ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "minishell1.h"
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
void ft_env(t_list *list)
{
while (list)
{
ft_printf("%s=%s\n", list->key, list->value);
list = list->next;
}
}
t_list *ft_setenv(t_list *list, char *key, char *value)
{
t_list *tmp;
tmp = list;
while (list && list->next)
{
if (!ft_strcmp(key, list->key))
{
free(list->value);
list->value = ft_strdup(value);
return (tmp);
}
list = list->next;
}
list = list_add_end(list, ft_list_new(key, value));
return (list);
}
t_list *ft_unsetenv_2(t_list *list, t_list *tmp)
{
if (list == tmp)
{
tmp = list->next;
if (list->next)
list->next->prev = NULL;
list_destroy(list);
return (tmp);
}
list->prev->next = list->next;
if (list->next)
list->next->prev = list->prev;
list_destroy(list);
return (tmp);
}
t_list *ft_unsetenv(t_list *list, char *key)
{
t_list *tmp;
if ((tmp = list))
{
while (list)
{
if (!ft_strcmp(key, list->key))
ft_unsetenv_2(list, tmp);
list = list->next;
}
}
return (NULL);
}
void list_destroy(t_list *list)
{
if (list)
{
free(list->key);
free(list->value);
free(list);
}
}