Added list_contains feature

This commit is contained in:
carlosgp143@gmail.com 2018-05-30 09:03:45 +02:00
parent a7bc3aac8d
commit 9327edb91f
2 changed files with 24 additions and 0 deletions

View File

@ -324,4 +324,26 @@ list_item_next(void *item)
return item == NULL ? NULL : ((struct list *)item)->next;
}
/*---------------------------------------------------------------------------*/
/**
* \brief Check if the list contains an item
* \param list The list that is checked
* \param item An item to look for in the list
* \returns 0 if the list does not contains the item, and 1 otherwise
*
* This function searches for an item in the list and returns
* 0 if the list does not contain the item, and 1 if the item
* is present in the list.
*/
int
list_contains(list_t list, void *item)
{
struct list *l;
for(l = *list; l != NULL; l = l->next) {
if(item == l) {
return 1;
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -151,6 +151,8 @@ void list_insert(list_t list, void *previtem, void *newitem);
void * list_item_next(void *item);
int list_contains(list_t list, void *item);
#endif /* LIST_H_ */
/** @} */