From 82ce86a4bdd17581bcb42dd78245b5d961bf99bb Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 23 Feb 2021 13:23:55 -0500 Subject: Add a list_size() primitive This adds list_size(), which tells us how many elements are in a list. Signed-off-by: Peter Jones --- include/list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/list.h b/include/list.h index ad87b45b..1d36e163 100644 --- a/include/list.h +++ b/include/list.h @@ -102,5 +102,16 @@ list_del(struct list_head *entry) for (pos = (head)->prev, n = pos->prev; pos != (head); \ pos = n, n = pos->prev) +static inline size_t +list_size(struct list_head *entry) +{ + list_t *pos; + size_t i = 0; + list_for_each(pos, entry) { + i++; + } + return i; +} + #endif /* !LIST_H_ */ // vim:fenc=utf-8:tw=75:noet -- cgit v1.2.3