iovec-util: add iovw_isempty() helper

Follow-up for: 3746131aac
This commit is contained in:
Lennart Poettering 2023-08-11 11:11:09 +02:00 committed by Luca Boccassi
parent 579fbe5b78
commit 82ee54b2d8
3 changed files with 10 additions and 4 deletions

View File

@ -382,7 +382,7 @@ int iovw_append(struct iovec_wrapper *target, const struct iovec_wrapper *source
/* This duplicates the source and merges it into the target. */
if (!source || source->count == 0)
if (iovw_isempty(source))
return 0;
original_count = target->count;

View File

@ -101,12 +101,19 @@ void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
static inline int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) {
/* Move data into iovw or free on error */
int r = iovw_put(iovw, data, len);
int r;
r = iovw_put(iovw, data, len);
if (r < 0)
free(data);
return r;
}
static inline bool iovw_isempty(const struct iovec_wrapper *iovw) {
return !iovw || iovw->count == 0;
}
int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value);
int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value);
void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new);

View File

@ -88,8 +88,7 @@ int writer_write(Writer *w,
int r;
assert(w);
assert(iovw);
assert(iovw->count > 0);
assert(!iovw_isempty(iovw));
if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) {
log_info("%s: Journal header limits reached or header out-of-date, rotating",