diff options
Diffstat (limited to 'src/ll.c')
| -rw-r--r-- | src/ll.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/ll.c b/src/ll.c new file mode 100644 index 0000000..1a0426b --- /dev/null +++ b/src/ll.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #include "ll.h" | ||
| 2 | |||
| 3 | #include <stdlib.h> | ||
| 4 | #include <error.h> | ||
| 5 | #include <errno.h> | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | |||
| 9 | // Initialize an empty nodelist object | ||
| 10 | struct nodelist* nodelist_init(struct nodelist *start) { | ||
| 11 | if(start == NULL) { | ||
| 12 | start = calloc(1, sizeof(struct nodelist)); | ||
| 13 | if(start == NULL) { | ||
| 14 | error(0, errno, "Could not allocate space for empty node list object"); | ||
| 15 | return NULL; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | start->fullpath = NULL; | ||
| 20 | start->next = NULL; | ||
| 21 | start->type = NODELIST_TYPE__UNDEF; | ||
| 22 | |||
| 23 | return start; | ||
| 24 | } | ||
| 25 | |||
| 26 | struct nodelist* nodelist_prepend(struct nodelist *new, struct nodelist *list) { | ||
| 27 | new->next = list; | ||
| 28 | return new; | ||
| 29 | } | ||
| 30 | |||
| 31 | struct nodelist* nodelist_append(struct nodelist *list, struct nodelist *append) { | ||
| 32 | struct nodelist *p = NULL, *prev = NULL; | ||
| 33 | for(p = list; p != NULL; p = p->next) | ||
| 34 | prev = p; | ||
| 35 | |||
| 36 | // If the pointer p is null, prev will never be set, so just error out | ||
| 37 | if(prev == NULL) | ||
| 38 | return NULL; | ||
| 39 | |||
| 40 | prev->next = append; | ||
| 41 | |||
| 42 | return list; | ||
| 43 | } | ||
| 44 | |||
| 45 | int nodelist_delete(struct nodelist *list) { | ||
| 46 | struct nodelist *p, *next; | ||
| 47 | for(p = list; p != NULL; p = next) { | ||
| 48 | next = p->next; | ||
| 49 | free(p); | ||
| 50 | } | ||
| 51 | |||
| 52 | return 0; | ||
| 53 | } \ No newline at end of file | ||
