diff options
| author | Thomas Haller <thaller@redhat.com> | 2017-12-10 12:18:21 +0100 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2017-12-18 12:10:11 +0100 |
| commit | d5c212b145b84461deea8523a64b42540d99c663 (patch) | |
| tree | 9cae61ab709f48d65a7eb9d28503c6650ca8181c /shared/nm-utils/nm-shared-utils.c | |
| parent | fe7b4641d6a91c85d5db3e32fdb4009fe5596ec4 (diff) | |
| download | NetworkManager-d5c212b145b84461deea8523a64b42540d99c663.tar.gz | |
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.
Diffstat (limited to 'shared/nm-utils/nm-shared-utils.c')
| -rw-r--r-- | shared/nm-utils/nm-shared-utils.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 8a7890b093..25b867538c 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -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; +} |
