From c92b4f7cf884cde740d2c5986d6f88be7dcafcc2 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Tue, 18 Jun 2024 18:51:36 -0500 Subject: Almost make scanning folders work --- src/ll.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ll.c (limited to 'src/ll.c') 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 @@ +#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; + 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; +} \ No newline at end of file -- cgit v1.2.3