-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_dir_list_node.c
More file actions
45 lines (39 loc) · 810 Bytes
/
add_dir_list_node.c
File metadata and controls
45 lines (39 loc) · 810 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
#include "path_list.h"
/**
* add_dir_list_node - add a new dir_list_t node at the end of a dir_list_t
* list
* @head: address of a pointer to the list's head
* @dir_name: name of directory
*
* Return: address of new node, else NULL
*/
dir_list_t *add_dir_list_node(dir_list_t **head, const char *dir_name)
{
dir_list_t *new = NULL, *tmp = NULL;
if (head == NULL || dir_name == NULL)
{
return (NULL);
}
/* Creation and initializaton of new node */
new = malloc(sizeof(dir_list_t));
if (new == NULL)
{
return (NULL);
}
new->dir = strdup(dir_name);
if (new->dir == NULL)
{
return (NULL);
}
new->next = NULL;
/* Linking of new node */
if (*head == NULL)
(*head) = new;
else
{
for (tmp = *head; tmp->next != NULL;)
tmp = tmp->next;
tmp->next = new;
}
return (new);
}