1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-27 07:22:31 +03:00

Merge pull request #29679 from keszybz/drop-iovec-null

Drop IOVEC_NULL
This commit is contained in:
Yu Watanabe 2023-10-24 17:05:45 +09:00 committed by GitHub
commit 8875639a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 25 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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];