#include "iovec-util.h"
#include "string-util.h"
+size_t iovec_total_size(const struct iovec *i, size_t n) {
+ size_t sum = 0;
+
+ assert(i || n == 0);
+
+ FOREACH_ARRAY(j, i, n)
+ sum += j->iov_len;
+
+ return sum;
+}
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
char *x;
#include "macro.h"
-static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) {
- size_t r = 0;
-
- for (size_t j = 0; j < n; j++)
- r += i[j].iov_len;
-
- return r;
-}
+size_t iovec_total_size(const struct iovec *i, size_t n);
static inline bool IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
/* Returns true if there is nothing else to send (bytes written cover all of the iovec),
return;
}
- log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
+ log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, iovec_total_size(iovec, n));
if (!shall_try_append_again(f, r))
return;
if (r < 0)
log_ratelimit_error_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT,
"Failed to write entry to %s (%zu items, %zu bytes) despite vacuuming, ignoring: %m",
- f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
+ f->path, n, iovec_total_size(iovec, n));
else
server_schedule_sync(s, priority);
}
assert_return(iov || n == 0, -EINVAL);
assert_return(!m->poisoned, -ESTALE);
- size = IOVEC_TOTAL_SIZE(iov, n);
+ size = iovec_total_size(iov, n);
r = sd_bus_message_append_string_space(m, size, &p);
if (r < 0)
assert_return(iov || n == 0, -EINVAL);
assert_return(!m->poisoned, -ESTALE);
- size = IOVEC_TOTAL_SIZE(iov, n);
+ size = iovec_total_size(iov, n);
r = sd_bus_message_append_array_space(m, type, size, &p);
if (r < 0)
send_ucred = false;
} else {
/* Unless we're using SOCK_STREAM, we expect to write all the contents immediately. */
- if (type != SOCK_STREAM && (size_t) n < IOVEC_TOTAL_SIZE(msghdr.msg_iov, msghdr.msg_iovlen))
+ if (type != SOCK_STREAM && (size_t) n < iovec_total_size(msghdr.msg_iov, msghdr.msg_iovlen))
return -EIO;
/* Make sure we only send fds and ucred once, even if we're using SOCK_STREAM. */
assert(stream->encrypted);
assert(stream->dnstls_data.session);
assert(iov);
- assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0);
+ assert(iovec_total_size(iov, iovcnt) > 0);
gnutls_record_cork(stream->dnstls_data.session);
assert(stream->encrypted);
assert(stream->dnstls_data.ssl);
assert(iov);
- assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0);
+ assert(iovec_total_size(iov, iovcnt) > 0);
if (iovcnt == 1)
return dnstls_stream_write(stream, iov[0].iov_base, iov[0].iov_len);
/* As of now, OpenSSL can not accumulate multiple writes, so join into a
single buffer. Suboptimal, but better than multiple SSL_write calls. */
- count = IOVEC_TOTAL_SIZE(iov, iovcnt);
+ count = iovec_total_size(iov, iovcnt);
buf = new(char, count);
for (size_t i = 0, pos = 0; i < iovcnt; pos += iov[i].iov_len, i++)
memcpy(buf + pos, iov[i].iov_base, iov[i].iov_len);