qapi: New strv_from_str_list()
authorSteve Sistare <steven.sistare@oracle.com>
Tue, 27 Feb 2024 15:33:20 +0000 (16:33 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 4 Mar 2024 06:12:40 +0000 (07:12 +0100)
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20240227153321.467343-3-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
include/qapi/type-helpers.h
qapi/qapi-type-helpers.c

index be1f18152648e2af8af57b8a31494047b0e14b9e..fc8352cdec07eee8da44adc36a3c1e6718a941f3 100644 (file)
 #include "qapi/qapi-types-common.h"
 
 HumanReadableText *human_readable_text_from_str(GString *str);
+
+/*
+ * Produce and return a NULL-terminated array of strings from @list.
+ * The result is g_malloc()'d and all strings are g_strdup()'d.  It
+ * can be freed with g_strfreev(), or by g_auto(GStrv) automatic
+ * cleanup.
+ */
+char **strv_from_str_list(const strList *list);
index f76b34f647ebaa169510a7f2ee900286176d1546..266da013ad6464b29e123fb7e3df50e2be7092f0 100644 (file)
@@ -21,3 +21,17 @@ HumanReadableText *human_readable_text_from_str(GString *str)
 
     return ret;
 }
+
+char **strv_from_str_list(const strList *list)
+{
+    const strList *tail;
+    int i = 0;
+    char **strv = g_new(char *, QAPI_LIST_LENGTH(list) + 1);
+
+    for (tail = list; tail != NULL; tail = tail->next) {
+        strv[i++] = g_strdup(tail->value);
+    }
+    strv[i] = NULL;
+
+    return strv;
+}