summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-07 19:18:39 +0100
committerThomas Haller <thaller@redhat.com>2020-11-09 17:25:24 +0100
commit0cf4250021eb6f942baa4a6245668d769e0b67eb (patch)
tree882df5161b7afd9bc61b985e7b79f8148e5dd5b5
parent571aeec933ac8bd62ee4888948bea4361316dd8b (diff)
downloadNetworkManager-0cf4250021eb6f942baa4a6245668d769e0b67eb.tar.gz
shared: add nm_utils_strdict_clone() helper
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c18
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index b1a557a28e..05e8caf3ad 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -434,6 +434,24 @@ nm_g_variant_singleton_u_0(void)
/*****************************************************************************/
+GHashTable *
+nm_utils_strdict_clone(GHashTable *src)
+{
+ GHashTable * dst;
+ GHashTableIter iter;
+ const char * key;
+ const char * val;
+
+ if (!src)
+ return NULL;
+
+ dst = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free);
+ g_hash_table_iter_init(&iter, src);
+ while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val))
+ g_hash_table_insert(dst, g_strdup(key), g_strdup(val));
+ return dst;
+}
+
/* Convert a hash table with "char *" keys and values to an "a{ss}" GVariant.
* The keys will be sorted asciibetically.
* Returns a floating reference.
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index df3f55195c..b736086387 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -320,6 +320,8 @@ gboolean nm_utils_gbytes_equal_mem(GBytes *bytes, gconstpointer mem_data, gsize
GVariant *nm_utils_gbytes_to_variant_ay(GBytes *bytes);
+GHashTable *nm_utils_strdict_clone(GHashTable *src);
+
GVariant *nm_utils_strdict_to_variant_ass(GHashTable *strdict);
GVariant *nm_utils_strdict_to_variant_asv(GHashTable *strdict);