iovec-wrapper: introduce iovw_put_string_fieldf()
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user