forked from glyif/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
free.c
94 lines (82 loc) · 1.5 KB
/
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
#include "header.h"
/**
* freeall - function to free all allocated memory
* @arginv: args inventory
*
* Return: 0 on success, 1 on failure
*/
int freeall(arg_inventory_t *arginv)
{
int exit_status;
if (arginv)
{
save_alias(arginv);
file_history(arginv);
free_history(arginv->history);
free(arginv->history_file);
free_environ(arginv->envlist);
free_alias(arginv->alias);
free(arginv->alias_file);
if (arginv->input_commands)
free(arginv->input_commands);
exit_status = arginv->exit_status;
free(arginv);
}
return (exit_status);
}
/**
* free_alias - function to free all allocated memory
* @head: head of alias
*
* Return: 0 on success, 1 on failure
*/
int free_alias(alias_t *head)
{
alias_t *temp = head;
while (head)
{
temp = temp->next;
free(head->alias);
free(head->command);
free(head);
head = temp;
}
return (EXT_SUCCESS);
}
/**
* free_environ - function to free all allocated memory
* @head: head of custom _environ
*
* Return: 0 on success, 1 on failure
*/
int free_environ(env_t *head)
{
env_t *temp = head;
while (head)
{
temp = temp->next;
free(head->var);
free(head->val);
free(head);
head = temp;
}
return (EXT_SUCCESS);
}
/**
* free_history - function to free all allocated memory
* @head: history linked list
*
* Return: 0 on success, 1 on failure
*/
int free_history(history_t *head)
{
history_t *temp = head;
while (head)
{
temp = temp->next;
free(head->command);
free(head);
head = temp;
}
return (EXT_SUCCESS);
}