summaryrefslogtreecommitdiff
path: root/lichen.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2025-10-24 12:44:06 -0500
committersanine <sanine.not@pm.me>2025-10-24 12:44:06 -0500
commit30efa292790dfdc9eedefa97a9f82e1cac2aeaa0 (patch)
tree8c8f10e92489de9bfe37dc2698d32c8f210897ef /lichen.c
parent54430e64cbb9577ee69de40bc92040428c73e097 (diff)
add alloc/dealloc functions for generic linked list
Diffstat (limited to 'lichen.c')
-rw-r--r--lichen.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lichen.c b/lichen.c
index f20c1b3..e8c8e19 100644
--- a/lichen.c
+++ b/lichen.c
@@ -1,4 +1,6 @@
#include "lichen.h"
+#include <stdio.h>
+#include <string.h>
void li_xorshift32_seed(struct li_xorshift32_t *xor, uint32_t seed) {
@@ -18,3 +20,35 @@ uint32_t li_xorshift32(void *s) {
// return just top 32 bits
return x >> 32;
}
+
+
+
+li_llnode_t * li_alloc_llnode() {
+ li_llnode_t *n = malloc(sizeof(li_llnode_t));
+ if (n == NULL) {
+ fprintf(stderr, "failed to allocate linked-list node\n");
+ return NULL;
+ } else {
+ n->tag = 0;
+ n->data = 0;
+ n->next = NULL;
+ return n;
+ }
+}
+
+
+li_llnode_t * li_copy_llnode(li_llnode_t *n) {
+ li_llnode_t *m = li_alloc_llnode();
+ if (m == NULL) {
+ return NULL;
+ }
+ memcpy(m, n, sizeof(li_llnode_t));
+ return m;
+}
+
+void li_free_llnode(li_llnode_t *n, void (*free_data)(void*)) {
+ if (n != NULL) {
+ free_data(n->data);
+ }
+ free(n);
+}