include: list.h: add duplicate checking add/append functions
Simplify cases where callers need to check whether an entry already is in a list before adding / appending. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
536c3c7765
commit
349d13961d
|
@ -251,6 +251,44 @@ xorg_list_present(struct xorg_list *entry, struct xorg_list *head)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief prepend a new element to the end of the list if not existing yet
|
||||
*
|
||||
* Same as xorg_list_add(), but protecting against duplicate insertion.
|
||||
*
|
||||
* @param entry The new element to append to the list.
|
||||
* @param head The existing list.
|
||||
* @return zero if element already in list, otherwise non-zero
|
||||
*/
|
||||
static inline int
|
||||
xorg_list_add_ndup(struct xorg_list *entry, struct xorg_list *head)
|
||||
{
|
||||
if (xorg_list_present(entry, head))
|
||||
return 0;
|
||||
|
||||
xorg_list_add(entry, head);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief append a new element to the end of the list if not existing yet
|
||||
*
|
||||
* Same as xorg_list_append(), but protecting against duplicate insertion.
|
||||
*
|
||||
* @param entry The new element to append to the list.
|
||||
* @param head The existing list.
|
||||
* @return zero if element already in list, otherwise non-zero
|
||||
*/
|
||||
static inline int
|
||||
xorg_list_append_ndup(struct xorg_list *entry, struct xorg_list *head)
|
||||
{
|
||||
if (xorg_list_present(entry, head))
|
||||
return 0;
|
||||
|
||||
xorg_list_append(entry, head);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the container of this list element.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue