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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-28 12:23:32 +02:00
parent 9461072ab4
commit 536c3c7765

View File

@ -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.
*