chiark / gitweb /
bus: add sd_bus_message_append_strv() to easily add a NULL terminated string array...
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Oct 2013 21:02:47 +0000 (23:02 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Oct 2013 21:02:47 +0000 (23:02 +0200)
src/libsystemd-bus/bus-message.c
src/systemd/sd-bus.h

index 264a2f6..18c2d1c 100644 (file)
@@ -2304,14 +2304,10 @@ int sd_bus_message_append_string_memfd(sd_bus_message *m, sd_memfd *memfd) {
         void *a;
         int r;
 
-        if (!m)
-                return -EINVAL;
-        if (!memfd)
-                return -EINVAL;
-        if (m->sealed)
-                return -EPERM;
-        if (m->poisoned)
-                return -ESTALE;
+        assert_return(m, -EINVAL);
+        assert_return(memfd, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->poisoned, -ESTALE);
 
         r = sd_memfd_set_sealed(memfd, true);
         if (r < 0)
@@ -2376,6 +2372,27 @@ int sd_bus_message_append_string_memfd(sd_bus_message *m, sd_memfd *memfd) {
         return 0;
 }
 
+int sd_bus_message_append_strv(sd_bus_message *m, char **l) {
+        char **i;
+        int r;
+
+        assert_return(m, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->poisoned, -ESTALE);
+
+        r = sd_bus_message_open_container(m, 'a', "s");
+        if (r < 0)
+                return r;
+
+        STRV_FOREACH(i, l) {
+                r = sd_bus_message_append_basic(m, 's', *i);
+                if (r < 0)
+                        return r;
+        }
+
+        return sd_bus_message_close_container(m);
+}
+
 int bus_body_part_map(struct bus_body_part *part) {
         void *p;
         size_t psz;
index bbeec13..e7ce56d 100644 (file)
@@ -191,6 +191,7 @@ int sd_bus_message_append_array_space(sd_bus_message *m, char type, size_t size,
 int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, sd_memfd *memfd);
 int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s);
 int sd_bus_message_append_string_memfd(sd_bus_message *m, sd_memfd* memfd);
+int sd_bus_message_append_strv(sd_bus_message *m, char **l);
 int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents);
 int sd_bus_message_close_container(sd_bus_message *m);