This adds the util_iov_new function that allows the user both allocated and set an iovec to the desired value, using only one function call. --- src/shared/util.c | 10 ++++++++++ src/shared/util.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index 6a29b5068..30f054a5e 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -542,6 +542,16 @@ void *util_iov_append(struct iovec *iov, const void *data, size_t len) return util_iov_push_mem(iov, len, data); } +struct iovec *util_iov_new(void *data, size_t len) +{ + struct iovec *iov; + + iov = new0(struct iovec, 1); + util_iov_append(iov, data, len); + + return iov; +} + void *util_iov_pull(struct iovec *iov, size_t len) { if (!iov) diff --git a/src/shared/util.h b/src/shared/util.h index bd71577d6..f2ca4f29f 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -176,6 +176,7 @@ void *util_iov_push_le16(struct iovec *iov, uint16_t val); void *util_iov_push_be16(struct iovec *iov, uint16_t val); void *util_iov_push_u8(struct iovec *iov, uint8_t val); void *util_iov_append(struct iovec *iov, const void *data, size_t len); +struct iovec *util_iov_new(void *data, size_t len); void *util_iov_pull(struct iovec *iov, size_t len); void *util_iov_pull_mem(struct iovec *iov, size_t len); void *util_iov_pull_le64(struct iovec *iov, uint64_t *val); -- 2.40.1