summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-11-17 09:25:48 +0100
committerThomas Haller <thaller@redhat.com>2023-11-30 15:53:21 +0100
commit7c16eb36abecb56bda60fa321209f7fd5f5f3743 (patch)
tree05bc258b1e7f64c89eb45c3059b2cb0252be971f
parent541979d09838cabc9038feef898fef2213449dd9 (diff)
glib-aux: add nm_strv_ptrarray_to_strv() helper
This will replace _nm_utils_ptrarray_to_strv(). One difference is, that this will fail an assertion if there are any NULL string in the GPtrArray.
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index 74d7b1b921..a99ae61229 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -2536,6 +2536,21 @@ nm_strv_ptrarray_get_unsafe(GPtrArray *arr, guint *out_len)
return (const char *const *) arr->pdata;
}
+static inline char **
+nm_strv_ptrarray_to_strv_full(const GPtrArray *a, gboolean not_null)
+{
+ if (!a)
+ return not_null ? nm_strv_empty_new() : NULL;
+ return nm_strv_dup_full((const char *const *) a->pdata, a->len, TRUE, TRUE);
+}
+
+static inline char **
+nm_strv_ptrarray_to_strv(const GPtrArray *a)
+{
+ /* Returns never NULL ("not_null"!) */
+ return nm_strv_ptrarray_to_strv_full(a, TRUE);
+}
+
static inline GPtrArray *
nm_strv_ptrarray_clone(const GPtrArray *src, gboolean null_if_empty)
{