diff --git a/include/villas/list.h b/include/villas/list.h index f186da293..f3dd82bc8 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -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); diff --git a/lib/list.c b/lib/list.c index 34a4838a2..f8377c6e1 100644 --- a/lib/list.c +++ b/lib/list.c @@ -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);