From dadd38c484238f70400f86c01676a65eae6936f5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 May 2019 14:01:44 +0200 Subject: [PATCH] shared: add nm_utils_strv_make_deep_copied_n() helper --- shared/nm-glib-aux/nm-shared-utils.c | 19 ++++++++++++++++++- shared/nm-glib-aux/nm-shared-utils.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index 6b4fed34d..be3746511 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -2288,7 +2288,7 @@ nm_utils_strv_make_deep_copied (const char **strv) { gsize i; - /* it takes a strv dictionary, and copies each + /* it takes a strv list, and copies each * strings. Note that this updates @strv *in-place* * and returns it. */ @@ -2300,6 +2300,23 @@ nm_utils_strv_make_deep_copied (const char **strv) return (char **) strv; } +char ** +nm_utils_strv_make_deep_copied_n (const char **strv, gsize len) +{ + gsize i; + + /* it takes a strv array with len elements, and copies each + * strings. Note that this updates @strv *in-place* + * and returns it. */ + + if (!strv) + return NULL; + for (i = 0; i < len; i++) + strv[i] = g_strdup (strv[i]); + + return (char **) strv; +} + /*****************************************************************************/ gssize diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 120c228c7..51c284d49 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -951,6 +951,8 @@ nm_utils_strdict_get_keys (const GHashTable *hash, char **nm_utils_strv_make_deep_copied (const char **strv); +char **nm_utils_strv_make_deep_copied_n (const char **strv, gsize len); + static inline char ** nm_utils_strv_make_deep_copied_nonnull (const char **strv) {