Blame SOURCES/0123-lib-add-a-clone-function-for-map_string_t.patch

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