From: Yu Watanabe Date: Wed, 8 Oct 2025 19:10:20 +0000 (+0900) Subject: iovec-wrapper: introduce iovw_put_string_fieldf() X-Git-Tag: v259-rc1~277^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d10596a6e02299ad86008fd5230a1420677c4c6e;p=thirdparty%2Fsystemd.git iovec-wrapper: introduce iovw_put_string_fieldf() --- diff --git a/src/basic/iovec-wrapper.c b/src/basic/iovec-wrapper.c index 0071893411e..b4519f808d5 100644 --- a/src/basic/iovec-wrapper.c +++ b/src/basic/iovec-wrapper.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "alloc-util.h" #include "iovec-util.h" #include "iovec-wrapper.h" @@ -84,6 +86,22 @@ int iovw_put_string_field_full(struct iovec_wrapper *iovw, bool replace, const c return r; } +int iovw_put_string_fieldf_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *format, ...) { + _cleanup_free_ char *value = NULL; + va_list ap; + int r; + + assert(format); + + va_start(ap, format); + r = vasprintf(&value, format, ap); + va_end(ap); + if (r < 0) + return -ENOMEM; + + return iovw_put_string_field_full(iovw, replace, field, value); +} + int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value) { _cleanup_free_ _unused_ char *free_ptr = value; diff --git a/src/basic/iovec-wrapper.h b/src/basic/iovec-wrapper.h index 33a91df1ca6..94b39feb152 100644 --- a/src/basic/iovec-wrapper.h +++ b/src/basic/iovec-wrapper.h @@ -40,6 +40,9 @@ static inline int iovw_put_string_field(struct iovec_wrapper *iovw, const char * static inline int iovw_replace_string_field(struct iovec_wrapper *iovw, const char *field, const char *value) { return iovw_put_string_field_full(iovw, true, field, value); } +int iovw_put_string_fieldf_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *format, ...) _printf_(4, 5); +#define iovw_put_string_fieldf(iovw, ...) iovw_put_string_fieldf_full(iovw, false, __VA_ARGS__) +#define iovw_replace_string_fieldf(iovw, ...) iovw_put_string_fieldf_full(iovw, true, __VA_ARGS__) int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value); void iovw_rebase(struct iovec_wrapper *iovw, void *old, void *new); size_t iovw_size(const struct iovec_wrapper *iovw);