]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
io-util: introduce iovw_put_string_field() helper
authorFranck Bui <fbui@suse.com>
Tue, 25 Jun 2019 14:57:06 +0000 (16:57 +0200)
committerFranck Bui <fbui@suse.com>
Thu, 27 Jun 2019 17:14:27 +0000 (19:14 +0200)
src/basic/io-util.c
src/basic/io-util.h

index 38de26a72cb8c323b1d10f0a3eec7dc5eeac83db..d19c78c2ca663385d9c8b5bd4a4856fd6bcb23c4 100644 (file)
@@ -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;
 
index e689fe1f43cd7d893653eb4ff282051a188a5183..719e19e85d6124e86b9f7f18ff01393297f1fb88 100644 (file)
@@ -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);