-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfree_shell.c
61 lines (54 loc) · 1.58 KB
/
free_shell.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_shell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alberrod <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/02 18:51:32 by dgomez-m #+# #+# */
/* Updated: 2024/04/23 19:41:51 by alberrod ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void free_list(t_my_env *env_list)
{
t_my_env *tmp;
t_my_env *tmp2;
tmp = env_list;
while (tmp)
{
tmp2 = tmp->next;
free(tmp->name);
if (*(tmp->value))
free(tmp->value);
if (tmp != NULL)
free(tmp);
tmp = tmp2;
}
}
void free_array_of_strings(char **env)
{
int i;
i = -1;
while (env[++i])
free(env[i]);
free(env);
}
void free_env(t_shell *shell)
{
free(shell->user);
free(shell->env);
free(shell->home);
free(shell->path);
free(shell->prompt);
free(shell->input);
}
void free_shell(t_shell *shell)
{
free_list(shell->env_list);
free_array_of_strings(shell->my_env);
free_env(shell);
if (!shell->input)
return ;
cleanup_cmd_list(&shell->parsed_input);
}