From 4343832097996886d085fe1139abcec363afc9ee Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 25 Sep 2023 13:29:03 -0400 Subject: list: New [S]LIST_EMPTY() macros --- src/list.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h index 9f8fd20..5cb6264 100644 --- a/src/list.h +++ b/src/list.h @@ -187,6 +187,15 @@ #define SLIST_ITEM_INIT__(item, next) \ LIST_VOID_(item->next = NULL) +/** + * Check if a singly-linked list is empty. + */ +#define SLIST_EMPTY(list) \ + SLIST_EMPTY_((list)) + +#define SLIST_EMPTY_(list) \ + ((void)sizeof(list->tail - &list->head), !list->head) + /** * Insert an item into a singly-linked list. * @@ -335,6 +344,15 @@ static inline void *slist_remove_impl(void *ret, void *cursor, void *next, void #define LIST_ITEM_INIT__(item, prev, next) \ LIST_VOID_(item->prev = item->next = NULL) +/** + * Check if a doubly-linked list is empty. + */ +#define LIST_EMPTY(list) \ + LIST_EMPTY_((list)) + +#define LIST_EMPTY_(list) \ + ((void)sizeof(list->tail - list->head), !list->head) + /** * Add an item to the tail of a doubly-linked list. * -- cgit v1.2.3