diff --git a/common/include/villas/list.h b/common/include/villas/list.h index 98647d53c..09e4f1aa4 100644 --- a/common/include/villas/list.h +++ b/common/include/villas/list.h @@ -129,6 +129,9 @@ ssize_t vlist_index(struct vlist *l, void *value); /** Extend the list to the given length by filling new slots with given value. */ void vlist_extend(struct vlist *l, size_t len, void *val); +/** Shallow copy a list. */ +int vlist_copy(struct vlist *dst, const struct vlist *src); + #ifdef __cplusplus } #endif diff --git a/common/lib/list.c b/common/lib/list.c index 40cfeca4b..533ed5e14 100644 --- a/common/lib/list.c +++ b/common/lib/list.c @@ -245,3 +245,20 @@ void vlist_extend(struct vlist *l, size_t len, void *val) while (vlist_length(l) < len) vlist_push(l, val); } + +int vlist_copy(struct vlist *dst, const struct vlist *src) +{ + int ret; + + ret = vlist_init(dst); + if (ret) + return ret; + + for (size_t i = 0; i < vlist_length(src); i++) { + void *p = vlist_at(src, i); + + vlist_push(dst, p); + } + + return 0; +}