Commit d5c212b1 authored by Thomas Haller's avatar Thomas Haller

shared: add nm_utils_strv_make_deep_copied() helper

At several places we create strv arrays where the
strings themself are not deep-copied.

This helper function iterates over such an "const char **"
array, clones the strings, and updates the strv array
inplace to be a "char **" strv array.

This helper function is to reduce code duplication.
parent fe7b4641
......@@ -1175,3 +1175,20 @@ nm_utils_strdict_get_keys (const GHashTable *hash,
NM_SET_OUT (out_length, length);
return names;
char **
nm_utils_strv_make_deep_copied (const char **strv)
gsize i;
/* it takes a strv dictionary, and copies each
* strings. Note that this updates @strv *in-place*
* and returns it. */
if (!strv)
return NULL;
for (i = 0; strv[i]; i++)
strv[i] = g_strdup (strv[i]);
return (char **) strv;
......@@ -447,6 +447,14 @@ const char **nm_utils_strdict_get_keys (const GHashTable *hash,
gboolean sorted,
guint *out_length);
char **nm_utils_strv_make_deep_copied (const char **strv);
static inline char **
nm_utils_strv_make_deep_copied_nonnull (const char **strv)
return nm_utils_strv_make_deep_copied (strv) ?: g_new0 (char *, 1);
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment