-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_manag.c
More file actions
114 lines (100 loc) · 1.63 KB
/
Copy pathmemory_manag.c
File metadata and controls
114 lines (100 loc) · 1.63 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "main.h"
/**
* add_ln_nd_end - Adds a command line at the end of a line_list.
* @hd: Head of the linked list.
* @cmd_line: Command line.
*
* Return: Address of the head.
*/
line_list *add_ln_nd_end(line_list **hd, char *cmd_line)
{
line_list *nw, *tmp;
nw = malloc(sizeof(line_list));
if (nw == NULL)
return (NULL);
nw->line = cmd_line;
nw->next = NULL;
tmp = *hd;
if (tmp == NULL)
{
*hd = nw;
}
else
{
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = nw;
}
return (*hd);
}
/**
* free_line_ls - Frees a line_list.
* @hd: Head of the linked list.
*
* Return: No return.
*/
void free_line_ls(line_list **hd)
{
line_list *tmp;
line_list *current;
if (hd != NULL)
{
current = *hd;
while ((tmp = current) != NULL)
{
current = current->next;
free(tmp);
}
*hd = NULL;
}
}
/**
* add_node_en - Adds a separator found at the end
* of a sep_list.
* @hd: Head of the linked list.
* @sp: Separator found (; | &).
*
* Return: Address of the head.
*/
sep_list *add_node_en(sep_list **hd, char sp)
{
sep_list *new_n, *tmp;
new_n = malloc(sizeof(sep_list));
if (new_n == NULL)
return (NULL);
new_n->sep = sp;
new_n->next = NULL;
tmp = *hd;
if (tmp == NULL)
{
*hd = new_n;
}
else
{
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = new_n;
}
return (*hd);
}
/**
* free_sp_ls - Frees a sep_list.
* @hd: Head of the linked list.
*
* Return: No return.
*/
void free_sp_ls(sep_list **hd)
{
sep_list *tmp;
sep_list *current;
if (hd != NULL)
{
current = *hd;
while ((tmp = current) != NULL)
{
current = current->next;
free(tmp);
}
*hd = NULL;
}
}