You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB

From 4790093363f4bb625905bdb3a81a62c598d41405 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
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 <jfilak@redhat.com>
---
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