diff --git a/include/villas/list.h b/include/villas/list.h index ab79d6774..14de55a43 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -134,6 +134,9 @@ int list_set(struct list *l, int index, void *value); */ ssize_t list_index(struct list *l, void *value); +/** Extend the list to the given length by filling new slots with given value. */ +void list_extend(struct list *l, size_t len, void *val); + #ifdef __cplusplus } #endif diff --git a/lib/list.c b/lib/list.c index f8377c6e1..70f81a543 100644 --- a/lib/list.c +++ b/lib/list.c @@ -231,3 +231,9 @@ found: pthread_mutex_unlock(&l->lock); return f; } + +void list_extend(struct list *l, size_t len, void *val) +{ + while (list_length(l) < len) + list_push(l, val); +}