From 48c73d2d49bfb4d0576bf6aae9d84307699e045c Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Fri, 22 Sep 2023 00:27:48 +0200 Subject: [PATCH] Add list_exactly_one() and list_more_than_one() utility functions --- include/lib/list.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/lib/list.h b/include/lib/list.h index 41f3678..fda023c 100644 --- a/include/lib/list.h +++ b/include/lib/list.h @@ -132,6 +132,24 @@ static inline int list_empty(const struct list_head* head) return head->next == head; } +/** + * list_exactly_one - tests whether a list has exactly one element + * @head: the list to test. + */ +static inline int list_exactly_one(const struct list_head* head) +{ + return head->next == head->prev; +} + +/** + * list_more_than_one - tests whether a list has more than one element + * @head: the list to test. + */ +static inline int list_more_than_one(const struct list_head* head) +{ + return head->next != head->prev; +} + /** * list_rotate_left - rotate the list to the left * @head: the head of the list -- 2.43.0