From d68d0f39ab7675745e7d177f6774736f7ec58783 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Wed, 1 Dec 2021 00:31:01 +0100 Subject: Replace readline with own implementation for integration --- link.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 link.h (limited to 'link.h') 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 + +#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); -- cgit v1.2.3-71-gd317