diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-10-29 19:53:43 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-10-29 19:53:43 +0100 |
commit | 250a918dc4c8a15d927deecc3b3f6a0604657ae4 (patch) | |
tree | 18faf995d700c26c67ad500b81e7cce007bc0b95 /src/libsystemd-bus/bus-objects.c | |
parent | 7b1132f60d2a447c31556c23ea90ea31447ac557 (diff) |
strv: introduce new strv_from_stdarg_alloca() macro to generate a string array from stdarg function parameters
This allows us to turn lists of strings passed in easily into string
arrays without having to allocate memory.
Diffstat (limited to 'src/libsystemd-bus/bus-objects.c')
-rw-r--r-- | src/libsystemd-bus/bus-objects.c | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c index c852ad6c42..31d761e215 100644 --- a/src/libsystemd-bus/bus-objects.c +++ b/src/libsystemd-bus/bus-objects.c @@ -1976,8 +1976,7 @@ int sd_bus_emit_properties_changed( const char *interface, const char *name, ...) { - _cleanup_strv_free_ char **names = NULL; - va_list ap; + char **names; assert_return(bus, -EINVAL); assert_return(object_path_is_valid(path), -EINVAL); @@ -1988,12 +1987,7 @@ int sd_bus_emit_properties_changed( if (!name) return 0; - va_start(ap, name); - names = strv_new_ap(name, ap); - va_end(ap); - - if (!names) - return -ENOMEM; + names = strv_from_stdarg_alloca(name); return sd_bus_emit_properties_changed_strv(bus, path, interface, names); } @@ -2157,20 +2151,14 @@ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **inte } int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) { - _cleanup_strv_free_ char **interfaces = NULL; - va_list ap; + char **interfaces; assert_return(bus, -EINVAL); assert_return(object_path_is_valid(path), -EINVAL); assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); - va_start(ap, interface); - interfaces = strv_new_ap(interface, ap); - va_end(ap); - - if (!interfaces) - return -ENOMEM; + interfaces = strv_from_stdarg_alloca(interface); return sd_bus_emit_interfaces_added_strv(bus, path, interfaces); } @@ -2203,20 +2191,14 @@ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **in } int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) { - _cleanup_strv_free_ char **interfaces = NULL; - va_list ap; + char **interfaces; assert_return(bus, -EINVAL); assert_return(object_path_is_valid(path), -EINVAL); assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(!bus_pid_changed(bus), -ECHILD); - va_start(ap, interface); - interfaces = strv_new_ap(interface, ap); - va_end(ap); - - if (!interfaces) - return -ENOMEM; + interfaces = strv_from_stdarg_alloca(interface); return sd_bus_emit_interfaces_removed_strv(bus, path, interfaces); } |