#include "ll.h" #include #include #include #include // 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; 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; }