]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/iovec-util.h
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[thirdparty/systemd.git] / src / basic / iovec-util.h
CommitLineData
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 11size_t iovec_total_size(const struct iovec *iovec, size_t n);
bd1ae178 12
1ca0b482 13bool 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
22static 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
30static 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
37static 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
41char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);
42char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value);
43
ba354c16 44void iovec_array_free(struct iovec *iovec, size_t n_iovec);