1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

list: added vlist_copy()

This commit is contained in:
Steffen Vogel 2019-02-18 01:12:19 +01:00
parent f65ed78c05
commit aa14147fd9
2 changed files with 20 additions and 0 deletions

View file

@ -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

View file

@ -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;
}