-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_free.c
100 lines (91 loc) · 1.94 KB
/
utils_free.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
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marlean <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/01 16:18:54 by rdanyell #+# #+# */
/* Updated: 2022/06/17 13:24:15 by marlean ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void free_envp_list(t_envp *envp_list)
{
if (!envp_list)
return ;
while (envp_list)
{
if (envp_list->key)
free(envp_list->key);
if (envp_list->value)
free(envp_list->value);
envp_list = envp_list->next;
}
free(envp_list);
envp_list = NULL;
}
void free_com_list(t_com *com)
{
t_com *tmp;
if (com)
{
while (com)
{
tmp = com->next;
if (com->name)
free(com->name);
if (com->arg)
free_array(com->arg);
if (com->file)
free(com->file);
com = tmp;
}
if (com)
free(com);
}
}
void ft_free_com_list(t_com **com)
{
t_com *tmp;
if (*com)
{
while (*com)
{
tmp = (*com)->next;
if ((*com)->name)
free((*com)->name);
if ((*com)->arg)
free_array((*com)->arg);
if ((*com)->file)
free((*com)->file);
if (*com)
free(*com);
(*com) = tmp;
}
if ((*com))
free((*com));
}
}
void free_array(char **arr)
{
int i;
i = 0;
if (arr)
{
if (arr[i])
{
while (arr[i])
{
free(arr[i]);
i++;
}
}
free(arr);
}
}
void ft_free(char *str)
{
if (str)
free(str);
}