.iov_len = 0,
};
+int iovec_alloc(size_t n, struct iovec *ret) {
+ assert(ret);
+
+ void *buf = malloc(n ?: 1);
+ if (!buf)
+ return -ENOMEM;
+
+ *ret = IOVEC_MAKE(buf, n);
+ return 0;
+}
+
size_t iovec_total_size(const struct iovec *iovec, size_t n) {
size_t sum = 0;
return iovec;
}
+void iovec_erase(struct iovec *iovec) {
+ assert(iovec);
+
+ /* Unlike iovec_done_erase(), which derives the buffer size with MALLOC_SIZEOF_SAFE(), this uses
+ * iov_len as the buffer size. Hence, it can be used with iovec referring to a static array or a
+ * buffer allocated on the stack. */
+ explicit_bzero_safe(iovec->iov_base, iovec->iov_len);
+}
+
void iovec_done_erase(struct iovec *iovec) {
assert(iovec);
extern const struct iovec iovec_nul_byte; /* Points to a single NUL byte */
extern const struct iovec iovec_empty; /* Points to an empty, but valid (i.e. non-NULL) pointer */
+int iovec_alloc(size_t n, struct iovec *ret);
+
size_t iovec_total_size(const struct iovec *iovec, size_t n) _nonnull_if_nonzero_(1, 2);
bool iovec_inc_many(struct iovec *iovec, size_t n, size_t k) _nonnull_if_nonzero_(1, 2);
.iov_len = 1, \
}
+#define IOVEC_ALLOCA(n) \
+ ({ \
+ size_t _n_ = (n); \
+ IOVEC_MAKE(alloca_safe(_n_), _n_); \
+ })
+
+void iovec_erase(struct iovec *iovec);
void iovec_done_erase(struct iovec *iovec);
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);