iovec-util: add new iovec_memdup() helper

This commit is contained in:
Lennart Poettering
2024-01-05 11:10:22 +01:00
parent bf38e4c0c1
commit 4cc467b67c
+16
View File
@@ -69,3 +69,19 @@ static inline int iovec_memcmp(const struct iovec *a, const struct iovec *b) {
b ? b->iov_base : NULL,
b ? b->iov_len : 0);
}
static inline struct iovec *iovec_memdup(const struct iovec *source, struct iovec *ret) {
assert(ret);
if (!iovec_is_set(source))
*ret = (struct iovec) {};
else {
void *p = memdup(source->iov_base, source->iov_len);
if (!p)
return NULL;
*ret = IOVEC_MAKE(p, source->iov_len);
}
return ret;
}