aboutsummaryrefslogtreecommitdiff
path: root/src/lib/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/list.c')
-rw-r--r--src/lib/list.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/list.c b/src/lib/list.c
new file mode 100644
index 0000000..db7c5a6
--- /dev/null
+++ b/src/lib/list.c
@@ -0,0 +1,32 @@
+// Copyright (c) 2023, Marvin Borner <dev@marvinborner.de>
+// SPDX-License-Identifier: MIT
+
+#include <stdlib.h>
+
+#include <log.h>
+#include <lib/list.h>
+
+static struct list *list_new(void)
+{
+ struct list *list = malloc(sizeof(*list));
+ if (!list)
+ fatal("out of memory!\n");
+ return list;
+}
+
+struct list *list_add(struct list *list, void *data)
+{
+ struct list *new = list_new();
+ new->data = data;
+ new->next = list;
+ return new;
+}
+
+void list_free(struct list *list)
+{
+ while (list) {
+ struct list *next = list->next;
+ free(list);
+ list = next;
+ }
+}