1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

list: added new function list_lookup_index()

This commit is contained in:
Steffen Vogel 2018-05-24 09:05:00 +02:00
parent a535ec5abc
commit dba6207856
2 changed files with 11 additions and 0 deletions

View file

@ -97,6 +97,8 @@ void list_remove(struct list *l, void *p);
*/
void * list_lookup(struct list *l, const char *name);
ssize_t list_lookup_index(struct list *l, const char *name);
/** Return the first element of the list for which cmp returns zero */
void * list_search(struct list *l, cmp_cb_t cmp, void *ctx);

View file

@ -132,6 +132,15 @@ void * list_lookup(struct list *l, const char *name)
return list_search(l, cmp_lookup, (void *) name);
}
ssize_t list_lookup_index(struct list *l, const char *name)
{
void *ptr = list_lookup(l, name);
if (!ptr)
return -1;
return list_index(l, ptr);
}
int list_contains(struct list *l, void *p)
{
return list_count(l, cmp_contains, p);