From 536c3c7765a77b44dd4625e8248369529d187416 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 28 May 2025 12:23:32 +0200 Subject: [PATCH] include: list.h: add xorg_list_present() This function walks through the list and checks whether an entry is already present. This check sometimes is neccessary, since trying to add an entry twice has catastrophic consequences: iteration will become endless loop. Signed-off-by: Enrico Weigelt, metux IT consult --- include/list.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/list.h b/include/list.h index 90efd8af5..20beb92fd 100644 --- a/include/list.h +++ b/include/list.h @@ -234,6 +234,23 @@ xorg_list_is_empty(struct xorg_list *head) return ((head->next == NULL) || (head->next == head)); } +/** + * @brief check whether element already is in list + * + * @param entry The element to check for + * @param head The existing list. + * @return zero when entry isn't present in list, otherwise non-zero + */ +static inline int +xorg_list_present(struct xorg_list *entry, struct xorg_list *head) +{ + for (struct xorg_list *l=head->next; l && (l != head); l=l->next) { + if (l == entry) + return 1; + } + return 0; +} + /** * Returns a pointer to the container of this list element. *