summaryrefslogtreecommitdiffstats
path: root/link.h
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2021-12-01 00:31:01 +0100
committerLouis Burda <quent.burda@gmail.com>2021-12-20 15:31:03 +0100
commitd68d0f39ab7675745e7d177f6774736f7ec58783 (patch)
tree9f0cf6732517619e370186f288be172eead73fb0 /link.h
parent02141177f8055a2d0edace481d631adbcb4b4c47 (diff)
downloadtmus-d68d0f39ab7675745e7d177f6774736f7ec58783.tar.gz
tmus-d68d0f39ab7675745e7d177f6774736f7ec58783.zip
Replace readline with own implementation for integration
Diffstat (limited to 'link.h')
-rw-r--r--link.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/link.h b/link.h
new file mode 100644
index 0000000..09f358f
--- /dev/null
+++ b/link.h
@@ -0,0 +1,23 @@
+#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 })
+
+struct link {
+ struct link *prev, *next;
+};
+
+int list_len(struct link *list);
+struct link* list_back(struct link *list);
+
+void link_push_back(struct link *list, struct link *link);
+
+void link_prepend(struct link *list, struct link *link);
+void link_append(struct link *list, struct link *link);
+void link_pop(struct link *link);