diff --git a/base/usr/include/toaru/list.h b/base/usr/include/toaru/list.h index 34d68fad..95165bd7 100644 --- a/base/usr/include/toaru/list.h +++ b/base/usr/include/toaru/list.h @@ -42,6 +42,7 @@ extern node_t * list_pop(list_t * list); extern node_t * list_dequeue(list_t * list); extern list_t * list_copy(list_t * original); extern void list_merge(list_t * target, list_t * source); +extern void * list_index(list_t * list, int index); extern void list_append_after(list_t * list, node_t * before, node_t * node); extern node_t * list_insert_after(list_t * list, node_t * before, void * item); diff --git a/lib/list.c b/lib/list.c index b76da626..f27de711 100644 --- a/lib/list.c +++ b/lib/list.c @@ -166,6 +166,15 @@ int list_index_of(list_t * list, void * value) { return -1; /* not find */ } +void * list_index(list_t * list, int index) { + int i = 0; + foreach(item, list) { + if (i == index) return item->value; + i++; + } + return NULL; +} + void list_remove(list_t * list, size_t index) { /* remove index from the list */ if (index > list->length) return;