-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_utils.c
69 lines (63 loc) · 1.9 KB
/
main_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/23 10:40:36 by zhabri #+# #+# */
/* Updated: 2023/01/10 11:08:49 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void reset_g_glob(void)
{
g_glob->in_child = false;
g_glob->sig_int = false;
g_glob->sig_quit = false;
g_glob->here_doc = false;
}
void final_clean_up(void)
{
ft_lstclear(g_glob->envp, free);
free_null(g_glob->minishell_sum);
free_null(g_glob->envp);
free_null(g_glob);
rl_clear_history();
}
void free_null(void *var)
{
if (var)
free(var);
var = NULL;
}
void init_g_glob(void)
{
g_glob = malloc(sizeof(t_glob));
g_glob->head = NULL;
g_glob->cmds = NULL;
g_glob->envp = NULL;
g_glob->input = NULL;
g_glob->minishell_sum = NULL;
g_glob->exit_ret = 0;
g_glob->in_child = false;
g_glob->sig_int = false;
g_glob->here_doc = false;
}
void clean_exit(int *children_pid)
{
free_null(children_pid);
if (g_glob->cmds)
clear_cmds();
free_null(g_glob->cmds);
if (g_glob->head)
free_op_list();
if (g_glob->envp)
ft_lstclear(g_glob->envp, free);
free_null(g_glob->envp);
free_null(g_glob->head);
free_null(g_glob->input);
free_null(g_glob->minishell_sum);
free_null(g_glob);
rl_clear_history();
}