]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: add new iovec_memdup() helper
authorLennart Poettering <lennart@poettering.net>
Tue, 21 Nov 2023 12:12:08 +0000 (13:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2024 10:10:22 +0000 (11:10 +0100)
src/basic/iovec-util.h

index 3b843e2594a6ecbecff1d80294be9ffaf222a0df..abfa8c07dab8e2348c2151b887bdc33031f2744f 100644 (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;
+}