]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: add some useful helpers for dealing with iovecs that refer to dynamic...
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Oct 2023 15:04:04 +0000 (17:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Oct 2023 12:38:16 +0000 (14:38 +0200)
src/basic/iovec-util.h

index 1f72898cba08fc4a73f961dd51872a3dd332c209..1f652a0ede6d75a04a11858991f4c43e5bda9d7b 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 
+#include "alloc-util.h"
 #include "macro.h"
 
 size_t iovec_total_size(const struct iovec *i, size_t n);
@@ -20,6 +21,27 @@ bool iovec_increment(struct iovec *i, size_t n, size_t k);
                 IOVEC_MAKE((char*) _s, strlen(_s));     \
         })
 
+#define TAKE_IOVEC(p) TAKE_GENERIC((p), struct iovec, IOVEC_NULL)
+
+static inline void iovec_done(struct iovec *iovec) {
+        /* A _cleanup_() helper that frees the iov_base in the iovec */
+        assert(iovec);
+
+        iovec->iov_base = mfree(iovec->iov_base);
+        iovec->iov_len = 0;
+}
+
+static inline void iovec_done_erase(struct iovec *iovec) {
+        assert(iovec);
+
+        iovec->iov_base = erase_and_free(iovec->iov_base);
+        iovec->iov_len = 0;
+}
+
+static inline bool iovec_is_set(const struct iovec *iov) {
+        return iov && iov->iov_len > 0 && iov->iov_base;
+}
+
 char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);
 char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value);