mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-08 21:10:25 +01:00
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:
parent
77c000aa0b
commit
3c846baa83
1 changed files with 17 additions and 0 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue