summaryrefslogtreecommitdiffstats
path: root/src/basic/iovec-wrapper.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/basic/iovec-wrapper.h
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/basic/iovec-wrapper.h')
-rw-r--r--src/basic/iovec-wrapper.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/basic/iovec-wrapper.h b/src/basic/iovec-wrapper.h
new file mode 100644
index 0000000..05e220c
--- /dev/null
+++ b/src/basic/iovec-wrapper.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#include "macro.h"
+
+struct iovec_wrapper {
+ struct iovec *iovec;
+ size_t count;
+};
+
+struct iovec_wrapper *iovw_new(void);
+struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw);
+struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free_free);
+
+void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
+
+int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
+static inline int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {
+ /* Move data into iovw or free on error */
+ int r;
+
+ r = iovw_put(iovw, data, len);
+ if (r < 0)
+ free(data);
+
+ return r;
+}
+
+static inline bool iovw_isempty(const struct iovec_wrapper *iovw) {
+ return !iovw || iovw->count == 0;
+}
+
+int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value);
+int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value);
+void iovw_rebase(struct iovec_wrapper *iovw, void *old, void *new);
+size_t iovw_size(const struct iovec_wrapper *iovw);
+int iovw_append(struct iovec_wrapper *target, const struct iovec_wrapper *source);