shared: add nm_strv_ptrarray_ensure() and nm_strv_ptrarray_find_first() helpers

(cherry picked from commit 99296d4c6c)
This commit is contained in:
Thomas Haller 2020-07-22 12:24:59 +02:00 committed by Beniamino Galvani
parent 5b579d8aa7
commit 0ae9e9ec5e

View file

@ -1776,6 +1776,17 @@ GSource *nm_utils_g_main_context_create_integrate_source (GMainContext *internal
/*****************************************************************************/
static inline GPtrArray *
nm_strv_ptrarray_ensure (GPtrArray **p_arr)
{
nm_assert (p_arr);
if (G_UNLIKELY (!*p_arr))
*p_arr = g_ptr_array_new_with_free_func (g_free);
return *p_arr;
}
static inline void
nm_strv_ptrarray_add_string_take (GPtrArray *cmd,
char *str)
@ -1814,6 +1825,22 @@ nm_strv_ptrarray_take_gstring (GPtrArray *cmd,
FALSE));
}
static inline gssize
nm_strv_ptrarray_find_first (const GPtrArray *strv,
const char *str)
{
if (!strv)
return -1;
return nm_utils_strv_find_first ((char **) strv->pdata, strv->len, str);
}
static inline gboolean
nm_strv_ptrarray_contains (const GPtrArray *strv,
const char *str)
{
return nm_strv_ptrarray_find_first (strv, str) >= 0;
}
/*****************************************************************************/
int nm_utils_getpagesize (void);