]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/iovec-util.h
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[thirdparty/systemd.git] / src / basic / iovec-util.h
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
8 #include "alloc-util.h"
9 #include "macro.h"
10
11 size_t iovec_total_size(const struct iovec *iovec, size_t n);
12
13 bool iovec_increment(struct iovec *iovec, size_t n, size_t k);
14
15 #define IOVEC_MAKE(base, len) (struct iovec) { .iov_base = (base), .iov_len = (len) }
16 #define IOVEC_MAKE_STRING(string) \
17 ({ \
18 const char *_s = (string); \
19 IOVEC_MAKE((char*) _s, strlen(_s)); \
20 })
21
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
37 static inline bool iovec_is_set(const struct iovec *iovec) {
38 return iovec && iovec->iov_len > 0 && iovec->iov_base;
39 }
40
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
44 void iovec_array_free(struct iovec *iovec, size_t n_iovec);