mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 01:34:11 +00:00
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:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user