| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "basic-forward.h" |
| 5 |
|
| 6 |
struct iovec_wrapper { |
| 7 |
struct iovec *iovec; |
| 8 |
size_t count; |
| 9 |
}; |
| 10 |
|
| 11 |
void iovw_done_free(struct iovec_wrapper *iovw); |
| 12 |
void iovw_done(struct iovec_wrapper *iovw); |
| 13 |
|
| 14 |
struct iovec_wrapper* iovw_free(struct iovec_wrapper *iovw); |
| 15 |
DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free); |
| 16 |
|
| 17 |
struct iovec_wrapper* iovw_free_free(struct iovec_wrapper *iovw); |
| 18 |
DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free_free); |
| 19 |
|
| 20 |
int iovw_compare(const struct iovec_wrapper *a, const struct iovec_wrapper *b) _pure_; |
| 21 |
static inline bool iovw_equal(const struct iovec_wrapper *a, const struct iovec_wrapper *b) { |
| 22 |
return iovw_compare(a, b) == 0; |
| 23 |
} |
| 24 |
|
| 25 |
int iovw_put_full(struct iovec_wrapper *iovw, bool accept_zero, void *data, size_t len); |
| 26 |
static inline int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len) { |
| 27 |
return iovw_put_full(iovw, false, data, len); |
| 28 |
} |
| 29 |
int iovw_put_iov_full(struct iovec_wrapper *iovw, bool accept_zero, const struct iovec *iov); |
| 30 |
static inline int iovw_put_iov(struct iovec_wrapper *iovw, const struct iovec *iov) { |
| 31 |
return iovw_put_iov_full(iovw, false, iov); |
| 32 |
} |
| 33 |
int iovw_put_iovw_full(struct iovec_wrapper *iovw, bool accept_zero, const struct iovec_wrapper *source); |
| 34 |
static inline int iovw_put_iovw(struct iovec_wrapper *iovw, const struct iovec_wrapper *source) { |
| 35 |
return iovw_put_iovw_full(iovw, false, source); |
| 36 |
} |
| 37 |
int iovw_consume_full(struct iovec_wrapper *iovw, bool accept_zero, void *data, size_t len); |
| 38 |
static inline int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len) { |
| 39 |
return iovw_consume_full(iovw, false, data, len); |
| 40 |
} |
| 41 |
int iovw_consume_iov_full(struct iovec_wrapper *iovw, bool accept_zero, struct iovec *iov); |
| 42 |
static inline int iovw_consume_iov(struct iovec_wrapper *iovw, struct iovec *iov) { |
| 43 |
return iovw_consume_iov_full(iovw, false, iov); |
| 44 |
} |
| 45 |
int iovw_extend_full(struct iovec_wrapper *iovw, bool accept_zero, const void *data, size_t len); |
| 46 |
static inline int iovw_extend(struct iovec_wrapper *iovw, const void *data, size_t len) { |
| 47 |
return iovw_extend_full(iovw, false, data, len); |
| 48 |
} |
| 49 |
int iovw_extend_iov_full(struct iovec_wrapper *iovw, bool accept_zero, const struct iovec *iov); |
| 50 |
static inline int iovw_extend_iov(struct iovec_wrapper *iovw, const struct iovec *iov) { |
| 51 |
return iovw_extend_iov_full(iovw, false, iov); |
| 52 |
} |
| 53 |
int iovw_extend_iovw_full(struct iovec_wrapper *iovw, bool accept_zero, const struct iovec_wrapper *source); |
| 54 |
static inline int iovw_extend_iovw(struct iovec_wrapper *iovw, const struct iovec_wrapper *source) { |
| 55 |
return iovw_extend_iovw_full(iovw, false, source); |
| 56 |
} |
| 57 |
|
| 58 |
static inline bool iovw_isempty(const struct iovec_wrapper *iovw) { |
| 59 |
return !iovw || iovw->count == 0; |
| 60 |
} |
| 61 |
|
| 62 |
int iovw_put_string_field_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *value); |
| 63 |
static inline int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value) { |
| 64 |
return iovw_put_string_field_full(iovw, false, field, value); |
| 65 |
} |
| 66 |
static inline int iovw_replace_string_field(struct iovec_wrapper *iovw, const char *field, const char *value) { |
| 67 |
return iovw_put_string_field_full(iovw, true, field, value); |
| 68 |
} |
| 69 |
int iovw_put_string_fieldf_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *format, ...) _printf_(4, 5); |
| 70 |
#define iovw_put_string_fieldf(iovw, ...) iovw_put_string_fieldf_full(iovw, false, __VA_ARGS__) |
| 71 |
#define iovw_replace_string_fieldf(iovw, ...) iovw_put_string_fieldf_full(iovw, true, __VA_ARGS__) |
| 72 |
int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value); |
| 73 |
void iovw_rebase(struct iovec_wrapper *iovw, void *old, void *new); |
| 74 |
size_t iovw_size(const struct iovec_wrapper *iovw); |
| 75 |
int iovw_concat(const struct iovec_wrapper *iovw, struct iovec *ret); |
| 76 |
char* iovw_to_cstring(const struct iovec_wrapper *iovw); |
| 77 |
|
| 78 |
int iovec_split(const struct iovec *iov, size_t length_size, struct iovec_wrapper *ret); |
| 79 |
int iovw_merge(const struct iovec_wrapper *iovw, size_t length_size, struct iovec *ret); |