diff options
-rw-r--r-- | src/list.c | 10 | ||||
-rw-r--r-- | src/list.h | 6 |
2 files changed, 16 insertions, 0 deletions
@@ -108,4 +108,14 @@ struct list *list_from_string(const char *string, char delim) return list; } +int list_find(struct list *list, int (*cmp)(const void *, const void *), const void *key) +{ + for(size_t i = 0; i < list->len; ++i) { + if(!cmp(list->items[i], key)) { + return (int)i; + } + } + return -1; +} + /* vim:set ts=2 sts=2 sw=2 et: */ @@ -43,6 +43,12 @@ void list_insert(struct list *list, size_t index, void *item); struct list *list_from_string(const char *string, char delim); +int list_find( + struct list *list, + int (*cmp)(const void *item, const void *key), + const void *key +); + #endif /* vim:set ts=2 sts=2 sw=2 et: */ |