util: Add list_is_singular() helper function
Returns whether the list has exactly one element.
Reviewed-by: Matt Turner <mattst88@gmail.com>
diff --git a/src/util/list.h b/src/util/list.h
index b98ce59..066f9b8 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -99,6 +99,14 @@
return list->next == list;
}
+/**
+ * Returns whether the list has exactly one element.
+ */
+static inline bool list_is_singular(const struct list_head *list)
+{
+ return list->next != NULL && list->next->next == list;
+}
+
static inline unsigned list_length(struct list_head *list)
{
struct list_head *node;