From ae41fdb66af358467aa278b1a99c153465bc8bba Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Tue, 25 Jun 2019 16:57:06 +0200 Subject: [PATCH] io-util: introduce iovw_put_string_field() helper --- src/basic/io-util.c | 21 +++++++++++++++++++++ src/basic/io-util.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 38de26a72c..d19c78c2ca 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -308,6 +308,27 @@ int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len) { return 0; } +int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value) { + _cleanup_free_ char *x = NULL; + int r; + + x = strappend(field, value); + if (!x) + return log_oom(); + + r = iovw_put(iovw, x, strlen(x)); + if (r >= 0) + TAKE_PTR(x); + + return r; +} + +int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value) { + _cleanup_free_ _unused_ char *free_ptr = value; + + return iovw_put_string_field(iovw, field, value); +} + void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new) { size_t i; diff --git a/src/basic/io-util.h b/src/basic/io-util.h index e689fe1f43..719e19e85d 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -86,5 +86,7 @@ struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw); struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw); void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors); int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len); +int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const char *value); +int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value); void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new); size_t iovw_size(struct iovec_wrapper *iovw); -- 2.25.1