From dba6207856d364f88f02f339a66efb14e77b97d5 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 09:05:00 +0200 Subject: [PATCH] list: added new function list_lookup_index() --- include/villas/list.h | 2 ++ lib/list.c | 9 +++++++++ 2 files changed, 11 insertions(+) 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);