-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_handler.c
More file actions
61 lines (46 loc) · 851 Bytes
/
list_handler.c
File metadata and controls
61 lines (46 loc) · 851 Bytes
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
#include "main.h"
/**
* add_node_end - add new nodes for splitted paths
* @head: head of node pointer
* @directory: splitted value to be put in a node
* Return: new head of node
*/
list_t *add_node_end(list_t *head, char *directory)
{
list_t *new_node = NULL;
list_t *current = NULL;
new_node = malloc(sizeof(list_t));
if (!new_node)
return (NULL);
new_node->dir = _strdup(directory);
new_node->next = NULL;
if (!head)
head = new_node;
else
{
current = head;
while (current->next)
current = current->next;
current->next = new_node;
}
return (head);
}
/**
* free_list - frees node list
* @head: head of node list
*
* Return: void
*/
void free_list(list_t *head)
{
list_t *temp;
while (head)
{
temp = head->next;
free(head->dir);
head->dir = NULL;
free(head);
head = temp;
}
head = NULL;
}