-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_list.c
More file actions
43 lines (37 loc) · 705 Bytes
/
Copy pathpath_list.c
File metadata and controls
43 lines (37 loc) · 705 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
#include "path_list.h"
/**
* path_list - build a linked list of the PATH directories
*
* Return: pointer to a dir_list_t list of PATH directories,
* else NULL
*/
dir_list_t *path_list(void)
{
char *path = NULL;
char **dir_array = NULL;
const char *PATH_VAR = "PATH", *PATH_DELIM = ":";
dir_list_t *head = NULL;
unsigned int i = 0;
path = _getenv(PATH_VAR);
if (path == NULL)
{
return (NULL);
}
path = strdup(path);
if (path == NULL)
{
return (NULL);
}
dir_array = tokenize(path, PATH_DELIM);
if (dir_array == NULL)
{
return (NULL);
}
for (i = 0; dir_array[i] != NULL; i++)
{
add_dir_list_node(&head, dir_array[i]);
}
free(dir_array);
free(path);
return (head);
}