From 4790093363f4bb625905bdb3a81a62c598d41405 Mon Sep 17 00:00:00 2001 From: Jakub Filak Date: Fri, 19 Dec 2014 00:16:44 +0100 Subject: [LIBREPORT PATCH 123/124] lib: add a clone function for map_string_t Related: #1140224, #1174833 Signed-off-by: Jakub Filak --- src/include/libreport_types.h | 2 ++ src/lib/abrt_types.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/include/libreport_types.h b/src/include/libreport_types.h index 41ed5d7..2c60972 100644 --- a/src/include/libreport_types.h +++ b/src/include/libreport_types.h @@ -33,6 +33,8 @@ typedef GHashTable map_string_t; map_string_t *new_map_string(void); #define free_map_string libreport_free_map_string void free_map_string(map_string_t *ms); +#define clone_map_string libreport_clone_map_string +map_string_t *clone_map_string(map_string_t *ms); #define size_map_string libreport_size_map_string static inline unsigned size_map_string(map_string_t *ms) diff --git a/src/lib/abrt_types.c b/src/lib/abrt_types.c index 1ad4acc..fddaa46 100644 --- a/src/lib/abrt_types.c +++ b/src/lib/abrt_types.c @@ -29,6 +29,23 @@ void free_map_string(map_string_t *ms) g_hash_table_destroy(ms); } +map_string_t *clone_map_string(map_string_t *ms) +{ + if (ms == NULL) + return NULL; + + map_string_t *clone = new_map_string(); + + const char *key; + const char *value; + map_string_iter_t iter; + init_map_string_iter(&iter, ms); + while(next_map_string_iter(&iter, &key, &value)) + insert_map_string(clone, xstrdup(key), xstrdup(value)); + + return clone; +} + const char *get_map_string_item_or_empty(map_string_t *ms, const char *key) { const char *v = (const char*)g_hash_table_lookup(ms, key); -- 1.8.3.1