diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2017-11-23 19:12:26 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2017-11-23 21:34:11 +0000 |
commit | 96c320e999927d964fbd128724022e7eeb976b8d (patch) | |
tree | b2df386912cdba848a94fb234f87a6e7c643d17e | |
parent | 57eb6a9168219d3afd90589e15b14778e832cd28 (diff) | |
download | imv-96c320e999927d964fbd128724022e7eeb976b8d.tar.gz |
Add list_find function
-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: */ |