diff --git a/src/basic/iovec-util.c b/src/basic/iovec-util.c index 11aa630ae6a..991889a14eb 100644 --- a/src/basic/iovec-util.c +++ b/src/basic/iovec-util.c @@ -3,24 +3,24 @@ #include "iovec-util.h" #include "string-util.h" -size_t iovec_total_size(const struct iovec *i, size_t n) { +size_t iovec_total_size(const struct iovec *iovec, size_t n) { size_t sum = 0; - assert(i || n == 0); + assert(iovec || n == 0); - FOREACH_ARRAY(j, i, n) + FOREACH_ARRAY(j, iovec, n) sum += j->iov_len; return sum; } -bool iovec_increment(struct iovec *i, size_t n, size_t k) { - assert(i || n == 0); +bool iovec_increment(struct iovec *iovec, size_t n, size_t k) { + assert(iovec || n == 0); /* Returns true if there is nothing else to send (bytes written cover all of the iovec), * false if there's still work to do. */ - FOREACH_ARRAY(j, i, n) { + FOREACH_ARRAY(j, iovec, n) { size_t sub; if (j->iov_len == 0) @@ -62,12 +62,9 @@ char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const ch return x; } -void iovec_array_free(struct iovec *iov, size_t n) { - if (!iov) - return; +void iovec_array_free(struct iovec *iovec, size_t n) { + FOREACH_ARRAY(i, iovec, n) + free(i->iov_base); - for (size_t i = 0; i < n; i++) - free(iov[i].iov_base); - - free(iov); + free(iovec); } diff --git a/src/basic/iovec-util.h b/src/basic/iovec-util.h index 1f652a0ede6..39feabd4260 100644 --- a/src/basic/iovec-util.h +++ b/src/basic/iovec-util.h @@ -8,11 +8,9 @@ #include "alloc-util.h" #include "macro.h" -size_t iovec_total_size(const struct iovec *i, size_t n); +size_t iovec_total_size(const struct iovec *iovec, size_t n); -bool iovec_increment(struct iovec *i, size_t n, size_t k); - -#define IOVEC_NULL (const struct iovec) {} +bool iovec_increment(struct iovec *iovec, size_t n, size_t k); #define IOVEC_MAKE(base, len) (struct iovec) { .iov_base = (base), .iov_len = (len) } #define IOVEC_MAKE_STRING(string) \ @@ -21,8 +19,6 @@ 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); @@ -38,11 +34,11 @@ static inline void iovec_done_erase(struct iovec *iovec) { iovec->iov_len = 0; } -static inline bool iovec_is_set(const struct iovec *iov) { - return iov && iov->iov_len > 0 && iov->iov_base; +static inline bool iovec_is_set(const struct iovec *iovec) { + return iovec && iovec->iov_len > 0 && iovec->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); -void iovec_array_free(struct iovec *iov, size_t n); +void iovec_array_free(struct iovec *iovec, size_t n); diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c index 1ca721e6c94..be23b2fe75d 100644 --- a/src/libsystemd/sd-journal/journal-send.c +++ b/src/libsystemd/sd-journal/journal-send.c @@ -530,7 +530,7 @@ _public_ int sd_journal_send_with_location(const char *file, const char *line, c r = sd_journal_sendv(iov, n_iov); - iov[0] = iov[1] = iov[2] = IOVEC_NULL; + iov[0] = iov[1] = iov[2] = (struct iovec) {}; return r; } diff --git a/src/partition/repart.c b/src/partition/repart.c index 4e57f977266..9109ea18237 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -4087,7 +4087,7 @@ static int partition_format_verity_hash( p->new_uuid_is_set = true; } - p->roothash = TAKE_IOVEC(rh); + p->roothash = TAKE_STRUCT(rh); return 0; #else @@ -4139,7 +4139,7 @@ static int sign_verity_roothash( static int partition_format_verity_sig(Context *context, Partition *p) { _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; - _cleanup_(iovec_done) struct iovec sig = IOVEC_NULL; + _cleanup_(iovec_done) struct iovec sig = {}; _cleanup_free_ char *text = NULL, *hint = NULL; Partition *hp; uint8_t fp[X509_FINGERPRINT_SIZE];