blob: 1a0426bf2aa6e1ea38c1a21603f67c6b38ee74a3 (
plain)
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
|
#include "ll.h"
#include <stdlib.h>
#include <error.h>
#include <errno.h>
#include <stdio.h>
// Initialize an empty nodelist object
struct nodelist* nodelist_init(struct nodelist *start) {
if(start == NULL) {
start = calloc(1, sizeof(struct nodelist));
if(start == NULL) {
error(0, errno, "Could not allocate space for empty node list object");
return NULL;
}
}
start->fullpath = NULL;
start->next = NULL;
start->type = NODELIST_TYPE__UNDEF;
return start;
}
struct nodelist* nodelist_prepend(struct nodelist *new, struct nodelist *list) {
new->next = list;
return new;
}
struct nodelist* nodelist_append(struct nodelist *list, struct nodelist *append) {
struct nodelist *p = NULL, *prev = NULL;
for(p = list; p != NULL; p = p->next)
prev = p;
// If the pointer p is null, prev will never be set, so just error out
if(prev == NULL)
return NULL;
prev->next = append;
return list;
}
int nodelist_delete(struct nodelist *list) {
struct nodelist *p, *next;
for(p = list; p != NULL; p = next) {
next = p->next;
free(p);
}
return 0;
}
|