summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-31 16:21:33 +0200
committerThomas Haller <thaller@redhat.com>2020-08-05 10:22:10 +0200
commit3c846baa830ed81bdeade774d88cf0393c5a242d (patch)
treee4b4ddab985a790e7160e932f5eba65c202f2e66
parent77c000aa0b1eb8d5f7dc010f7b07e8673feff0b6 (diff)
downloadNetworkManager-3c846baa830ed81bdeade774d88cf0393c5a242d.tar.gz
shared: add nm_strv_ptrarray_get_unsafe() helper
It's called "unsafe" because the returned pointer array is not NULL terminated. This is due to a limitation of GPtrArray which doesn't support that. If you want a NULL terminated strv array, use a GArray based API, like nm_strvarray_*().
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index d44321d34e..7d7ed16fe7 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -1821,6 +1821,23 @@ nm_strv_ptrarray_ensure (GPtrArray **p_arr)
return *p_arr;
}
+static inline const char *const*
+nm_strv_ptrarray_get_unsafe (GPtrArray *arr,
+ guint *out_len)
+{
+ /* warning: the GPtrArray is not NULL terminated. So, it
+ * isn't really a strv array (sorry the misnomer). That's why
+ * the function is potentially "unsafe" and you must provide a
+ * out_len parameter. */
+ if ( !arr
+ || arr->len == 0) {
+ *out_len = 0;
+ return NULL;
+ }
+ *out_len = arr->len;
+ return (const char *const*) arr->pdata;
+}
+
static inline GPtrArray *
nm_strv_ptrarray_clone (const GPtrArray *src, gboolean null_if_empty)
{