]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/iovec-util.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "iovec-util.h"
4 #include "string-util.h"
6 size_t iovec_total_size(const struct iovec
*iovec
, size_t n
) {
9 assert(iovec
|| n
== 0);
11 FOREACH_ARRAY(j
, iovec
, n
)
17 bool iovec_increment(struct iovec
*iovec
, size_t n
, size_t k
) {
18 assert(iovec
|| n
== 0);
20 /* Returns true if there is nothing else to send (bytes written cover all of the iovec),
21 * false if there's still work to do. */
23 FOREACH_ARRAY(j
, iovec
, n
) {
31 sub
= MIN(j
->iov_len
, k
);
33 j
->iov_base
= (uint8_t*) j
->iov_base
+ sub
;
37 assert(k
== 0); /* Anything else would mean that we wrote more bytes than available,
38 * or the kernel reported writing more bytes than sent. */
42 char* set_iovec_string_field(struct iovec
*iovec
, size_t *n_iovec
, const char *field
, const char *value
) {
48 x
= strjoin(field
, value
);
50 iovec
[(*n_iovec
)++] = IOVEC_MAKE_STRING(x
);
54 char* set_iovec_string_field_free(struct iovec
*iovec
, size_t *n_iovec
, const char *field
, char *value
) {
60 x
= set_iovec_string_field(iovec
, n_iovec
, field
, value
);
65 void iovec_array_free(struct iovec
*iovec
, size_t n
) {
66 FOREACH_ARRAY(i
, iovec
, n
)