-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_list.c
69 lines (61 loc) · 1.67 KB
/
path_list.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* path_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rvan-der <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 14:36:09 by rvan-der #+# #+# */
/* Updated: 2017/03/24 17:48:18 by rvan-der ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
int *pathdup(int *path, int len)
{
int i;
int *ret;
if ((ret = (int*)malloc(sizeof(int) * len)) == NULL)
return (NULL);
i = -1;
while (++i < len)
ret[i] = path[i];
return (ret);
}
t_path *new_path(int *path)
{
t_path *new;
if ((new = (t_path*)malloc(sizeof(t_path))) == NULL)
return (NULL);
new->len = pathlen(path);
if ((new->pth = pathdup(path, new->len + 1)) == NULL)
{
free(new);
return (NULL);
}
new->next = NULL;
new->pass = 0;
return (new);
}
void path_add(t_path *elem, t_path **list)
{
if (elem != NULL)
{
if (list != NULL)
elem->next = *list;
*list = elem;
}
}
int plist_len(t_path *list)
{
int i;
t_path *tmp;
i = 0;
if ((tmp = list) == NULL)
return (i);
while (tmp != NULL)
{
i++;
tmp = tmp->next;
}
return (i);
}