summaryrefslogtreecommitdiffstats
path: root/src/list.h
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2021-12-20 16:25:43 +0100
committerLouis Burda <quent.burda@gmail.com>2021-12-20 16:25:43 +0100
commitf07580d31d1148c4a1811c36b09ca0ad50d9576b (patch)
tree05a8fbb44af81f3b5937df80c5af3305ec3ed3c9 /src/list.h
parentfaee8e9c6db45c6adacfc5113d55927f92e8bf29 (diff)
downloadtmus-f07580d31d1148c4a1811c36b09ca0ad50d9576b.tar.gz
tmus-f07580d31d1148c4a1811c36b09ca0ad50d9576b.zip
Restructured repository and added automatic make dependency generation
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/list.h b/src/list.h
new file mode 100644
index 0000000..d74ac9f
--- /dev/null
+++ b/src/list.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <stdlib.h>
+
+#define OFFSET(type, attr) ((size_t) &((type *)0)->attr)
+#define UPCAST(ptr, type) ({ \
+ const typeof( ((type *)0)->link ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - OFFSET(type, link) ); })
+
+#define LIST_HEAD ((struct link) { .prev = NULL, .next = NULL })
+#define LINK_EMPTY ((struct link) { 0 })
+
+#define LINK(p) (&(p)->link)
+
+struct link {
+ struct link *prev;
+ struct link *next;
+};
+
+/* list_XXX functions operate on the list head */
+
+int list_empty(struct link *head);
+int list_len(struct link *head);
+int list_ffind(struct link *head, struct link *link);
+
+struct link *link_back(struct link *list);
+void link_prepend(struct link *list, struct link *link);
+void link_append(struct link *list, struct link *link);
+struct link *link_pop(struct link *link);
+
+struct link *link_iter(struct link *link, int n);
+
+void list_push_back(struct link *list, struct link *link);
+
+//rstrrrstrssiimmrsrsssts