Commit d13e13c1 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

list: added vlist_copy()

parent 4d66f418
......@@ -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
......@@ -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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment