]>
Commit | Line | Data |
---|---|---|
bd1ae178 LP |
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | #pragma once | |
3 | ||
4 | #include <stdbool.h> | |
5 | #include <sys/types.h> | |
6 | #include <sys/uio.h> | |
7 | ||
3a856171 | 8 | #include "alloc-util.h" |
bd1ae178 LP |
9 | #include "macro.h" |
10 | ||
1ca0b482 | 11 | size_t iovec_total_size(const struct iovec *iovec, size_t n); |
bd1ae178 | 12 | |
1ca0b482 | 13 | bool iovec_increment(struct iovec *iovec, size_t n, size_t k); |
bd1ae178 | 14 | |
bd1ae178 | 15 | #define IOVEC_MAKE(base, len) (struct iovec) { .iov_base = (base), .iov_len = (len) } |
9599ea28 LP |
16 | #define IOVEC_MAKE_STRING(string) \ |
17 | ({ \ | |
18 | const char *_s = (string); \ | |
19 | IOVEC_MAKE((char*) _s, strlen(_s)); \ | |
bd1ae178 LP |
20 | }) |
21 | ||
3a856171 LP |
22 | static inline void iovec_done(struct iovec *iovec) { |
23 | /* A _cleanup_() helper that frees the iov_base in the iovec */ | |
24 | assert(iovec); | |
25 | ||
26 | iovec->iov_base = mfree(iovec->iov_base); | |
27 | iovec->iov_len = 0; | |
28 | } | |
29 | ||
30 | static inline void iovec_done_erase(struct iovec *iovec) { | |
31 | assert(iovec); | |
32 | ||
33 | iovec->iov_base = erase_and_free(iovec->iov_base); | |
34 | iovec->iov_len = 0; | |
35 | } | |
36 | ||
1ca0b482 ZJS |
37 | static inline bool iovec_is_set(const struct iovec *iovec) { |
38 | return iovec && iovec->iov_len > 0 && iovec->iov_base; | |
3a856171 LP |
39 | } |
40 | ||
bd1ae178 LP |
41 | char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value); |
42 | char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value); | |
43 | ||
ba354c16 | 44 | void iovec_array_free(struct iovec *iovec, size_t n_iovec); |