-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappend_node.c
More file actions
47 lines (46 loc) · 855 Bytes
/
append_node.c
File metadata and controls
47 lines (46 loc) · 855 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
#include "simple_shell.h"
/**
* appendnode - append path var to an empty path_t
* @s: pointer to path var
* @lists: pointer to path_t list
* Return: pointer to the new list
*/
path_t *appendnode(char *s, path_t *lists)
{
char *directory;
path_t *pointer, *h;
int k = 0, n = 0, sup = 0, dlen = 0;
if (s == NULL || lists == NULL)
return (NULL);
h = lists;
pointer = h;
while (pointer != NULL)
{
if (s[k] == ':' || s[k] == '\0')
{
if (s[k] != '\0')
k++;
directory = malloc(sizeof(char) * dlen + 2);
if (directory == NULL)
return (NULL);
while (s[sup] != ':' && s[sup] != '\0')
{
directory[n] = s[sup];
sup++;
n++;
}
directory[n++] = '/';
directory[n] = '\0';
sup = k;
n = 0;
pointer->dir = directory;
pointer = pointer->next;
}
else
{
dlen++;
k++;
}
}
return (h);
}