From eb8b1fd4211e645289687e3fe453877fa0892ada Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 5 Jun 2018 20:11:32 +0200 Subject: [PATCH] properties: add setva function --- src/pipewire/properties.c | 15 ++++++++++++--- src/pipewire/properties.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index 6b727bf69..190eaddcc 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -291,6 +291,15 @@ int pw_properties_set(struct pw_properties *properties, const char *key, const c return do_replace(properties, strdup(key), value ? strdup(value) : NULL); } +int +pw_properties_setva(struct pw_properties *properties, + const char *key, const char *format, va_list args) +{ + char *value; + vasprintf(&value, format, args); + return do_replace(properties, strdup(key), value); +} + /** Set a property value by format * * \param properties a \ref pw_properties @@ -305,14 +314,14 @@ int pw_properties_set(struct pw_properties *properties, const char *key, const c */ int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format, ...) { + int res; va_list varargs; - char *value; va_start(varargs, format); - vasprintf(&value, format, varargs); + res = pw_properties_setva(properties, key, format, varargs); va_end(varargs); - return do_replace(properties, strdup(key), value); + return res; } /** Get a property diff --git a/src/pipewire/properties.h b/src/pipewire/properties.h index 693542dee..55ba0a3c7 100644 --- a/src/pipewire/properties.h +++ b/src/pipewire/properties.h @@ -64,6 +64,9 @@ pw_properties_set(struct pw_properties *properties, const char *key, const char int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format, ...) SPA_PRINTF_FUNC(3, 4); +int +pw_properties_setva(struct pw_properties *properties, + const char *key, const char *format, va_list args); const char * pw_properties_get(const struct pw_properties *properties, const char *key);