diff --git a/include/villas/list.h b/include/villas/list.h index 6615c665f..18c2d99bd 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -97,4 +97,7 @@ int list_count(struct list *l, cmp_cb_t cmp, void *ctx); int list_contains(struct list *l, void *p); /** Sort the list using the quicksort algorithm of libc */ -void list_sort(struct list *l, cmp_cb_t cmp); \ No newline at end of file +void list_sort(struct list *l, cmp_cb_t cmp); + +/** Set single element in list */ +int list_set(struct list *l, int index, void *value); \ No newline at end of file diff --git a/lib/list.c b/lib/list.c index 9719ee773..758343411 100644 --- a/lib/list.c +++ b/lib/list.c @@ -188,4 +188,14 @@ void list_sort(struct list *l, cmp_cb_t cmp) qsort_r(l->array, l->length, sizeof(void *), cmp_sort, (void *) cmp); pthread_mutex_unlock(&l->lock); +} + +int list_set(struct list *l, int index, void *value) +{ + if (index >= l->length) + return -1; + + l->array[index] = value; + + return 0; } \ No newline at end of file