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_*().
This commit is contained in:
Thomas Haller 2020-07-31 16:21:33 +02:00
parent 77c000aa0b
commit 3c846baa83
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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)
{