aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorMarvin Borner2020-11-01 12:35:00 +0100
committerMarvin Borner2020-11-01 12:35:00 +0100
commitf40be8b5b6227775901a99946779661d0b4439e6 (patch)
tree34c28f138f4167de258ee18db44707aa4637a68d /libc
parente0d3b1671b3f94657d70223b51285ed287c882df (diff)
Added files demo and needed functions
Diffstat (limited to 'libc')
-rw-r--r--libc/inc/list.h1
-rw-r--r--libc/list.c16
2 files changed, 17 insertions, 0 deletions
diff --git a/libc/inc/list.h b/libc/inc/list.h
index 0c3668d..50b21c2 100644
--- a/libc/inc/list.h
+++ b/libc/inc/list.h
@@ -17,6 +17,7 @@ struct node {
};
struct list *list_new();
+void list_destroy(struct list *list);
/* struct node *list_new_node(); */ // TODO: Make node-specific things static/private?
/* void list_add_node(struct list *list, struct node *node); */
struct node *list_add(struct list *list, void *data);
diff --git a/libc/list.c b/libc/list.c
index 7baae92..6e1f95d 100644
--- a/libc/list.c
+++ b/libc/list.c
@@ -13,6 +13,22 @@ struct list *list_new()
return list;
}
+void list_destroy(struct list *list)
+{
+ struct node *iterator = list->head;
+ while (iterator != NULL) {
+ if (iterator->next == NULL) {
+ free(iterator);
+ break;
+ }
+ iterator = iterator->next;
+ free(iterator->prev);
+ }
+ list->head = NULL;
+ free(list);
+ list = NULL;
+}
+
struct node *list_new_node()
{
struct node *node = malloc(sizeof(*node));