iovec-util: Reduce transitive includes

This commit is contained in:
Daan De Meyer
2025-05-07 22:04:46 +09:00
committed by Yu Watanabe
parent dc7b151264
commit e53d4f343d
27 changed files with 71 additions and 39 deletions
+42
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "iovec-util.h"
#include "string-util.h"
@@ -51,6 +52,20 @@ bool iovec_increment(struct iovec *iovec, size_t n, size_t k) {
return true;
}
struct iovec* iovec_make_string(struct iovec *iovec, const char *s) {
assert(iovec);
*iovec = IOVEC_MAKE(s, strlen_ptr(s));
return iovec;
}
void iovec_done_erase(struct iovec *iovec) {
assert(iovec);
iovec->iov_base = erase_and_free(iovec->iov_base);
iovec->iov_len = 0;
}
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) {
char *x;
@@ -83,6 +98,33 @@ void iovec_array_free(struct iovec *iovec, size_t n_iovec) {
free(iovec);
}
int iovec_memcmp(const struct iovec *a, const struct iovec *b) {
if (a == b)
return 0;
return memcmp_nn(a ? a->iov_base : NULL,
a ? a->iov_len : 0,
b ? b->iov_base : NULL,
b ? b->iov_len : 0);
}
struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret) {
assert(ret);
if (!iovec_is_set(source))
*ret = (struct iovec) {};
else {
void *p = memdup(source->iov_base, source->iov_len);
if (!p)
return NULL;
*ret = IOVEC_MAKE(p, source->iov_len);
}
return ret;
}
struct iovec* iovec_append(struct iovec *iovec, const struct iovec *append) {
assert(iovec_is_valid(iovec));
+4 -38
View File
@@ -5,7 +5,6 @@
#include <sys/types.h>
#include <sys/uio.h>
#include "alloc-util.h"
#include "iovec-util-fundamental.h"
#include "macro.h"
@@ -16,12 +15,7 @@ size_t iovec_total_size(const struct iovec *iovec, size_t n) _nonnull_if_nonzero
bool iovec_increment(struct iovec *iovec, size_t n, size_t k) _nonnull_if_nonzero_(1, 2);
static inline struct iovec* iovec_make_string(struct iovec *iovec, const char *s) {
assert(iovec);
/* We don't use strlen_ptr() here, because we don't want to include string-util.h for now */
*iovec = IOVEC_MAKE(s, s ? strlen(s) : 0);
return iovec;
}
struct iovec* iovec_make_string(struct iovec *iovec, const char *s);
#define IOVEC_MAKE_STRING(s) \
*iovec_make_string(&(struct iovec) {}, s)
@@ -32,43 +26,15 @@ static inline struct iovec* iovec_make_string(struct iovec *iovec, const char *s
.iov_len = STRLEN(s), \
}
static inline void iovec_done_erase(struct iovec *iovec) {
assert(iovec);
iovec->iov_base = erase_and_free(iovec->iov_base);
iovec->iov_len = 0;
}
void iovec_done_erase(struct iovec *iovec);
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);
char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value);
void iovec_array_free(struct iovec *iovec, size_t n_iovec) _nonnull_if_nonzero_(1, 2);
static inline int iovec_memcmp(const struct iovec *a, const struct iovec *b) {
int iovec_memcmp(const struct iovec *a, const struct iovec *b) _pure_;
if (a == b)
return 0;
return memcmp_nn(a ? a->iov_base : NULL,
a ? a->iov_len : 0,
b ? b->iov_base : NULL,
b ? b->iov_len : 0);
}
static inline struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret) {
assert(ret);
if (!iovec_is_set(source))
*ret = (struct iovec) {};
else {
void *p = memdup(source->iov_base, source->iov_len);
if (!p)
return NULL;
*ret = IOVEC_MAKE(p, source->iov_len);
}
return ret;
}
struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret);
struct iovec* iovec_append(struct iovec *iovec, const struct iovec *append);
+1
View File
@@ -2,6 +2,7 @@
#include <threads.h>
#include "alloc-util.h"
#include "env-util.h"
#include "iovec-util.h"
#include "log.h"