summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-09-25 13:29:03 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-09-25 13:29:03 -0400
commit4343832097996886d085fe1139abcec363afc9ee (patch)
tree454ff289c71d895d3a0ab1a8561a8567d915dc51
parent72ea07d8c200bd6cd34ce02121165f3888624ac6 (diff)
downloadbfs-4343832097996886d085fe1139abcec363afc9ee.tar.xz
list: New [S]LIST_EMPTY() macros
-rw-r--r--src/list.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/list.h b/src/list.h
index 9f8fd20..5cb6264 100644
--- a/src/list.h
+++ b/src/list.h
@@ -188,6 +188,15 @@
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.
*
* @param list
@@ -336,6 +345,15 @@ static inline void *slist_remove_impl(void *ret, void *cursor, void *next, void
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.
*
* @param list