util: Add list_is_singular() helper function
[mesa.git] / src / util / list.h
index b98ce59ff77d6c6344f6147fe13214b022c7a863..066f9b8dfe50bb5852e9b31d781e602cb6b55ce4 100644 (file)
@@ -99,6 +99,14 @@ static inline bool list_empty(struct list_head *list)
    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;