-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.c
More file actions
89 lines (80 loc) · 1.44 KB
/
Copy pathmemory.c
File metadata and controls
89 lines (80 loc) · 1.44 KB
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
#include "shell.h"
/**
* free_path_list - frees a list_t list
* @head: linked list
* Return: void
*/
void free_path_list(path_t *head)
{
path_t *i = head;
path_t *next = NULL;
for (; i != NULL; i = next)
{
next = i->next;
free(i->path_dir);
free(i);
}
}
/**
* free_env_list - frees a env_t list
* @head: pointer to head of env_t list
* Return: void
*/
void free_env_list(env_t *head)
{
env_t *i = head;
env_t *next = NULL;
for (; i != NULL; i = next)
{
next = i->next;
free(i->name);
free(i->value);
free(i);
}
}
/**
* free_string_array - frees memory allocated by a double pointer
* @array: 2D array to free
* Return: TRUE (1) on success; FALSE (0 on fail)
*/
int free_string_array(char **array)
{
int i = 0;
if (!array)
return (FALSE);
while (array[i])
{
free(array[i]);
i++;
}
free(array);
return (TRUE);
}
/**
* free_history - frees all elements of the hist_t struct
* @head: pointer to first node in hist_t list
* Return: void
*/
void free_history(hist_t *head)
{
hist_t *temp_node;
hist_t *next_node;
temp_node = head;
for (; temp_node; temp_node = next_node)
{
next_node = temp_node->next;
free(temp_node->cmd);
free(temp_node);
}
}
/**
* free_info_items - frees all elements of the info_t struct
* @info: pointer to the info_t struct
* Return: void
*/
void free_info_items(info_t *info)
{
free_env_list(info->env_head);
free_path_list(info->path_head);
free_history(info->hist_head);
}