about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-05-22 20:02:19 +0100
committerJames Booth <boothj5@gmail.com>2014-05-22 20:02:19 +0100
commit6dbcc0354324d194fa6c2091a030e2106042a172 (patch)
treed83c2f7523719b53d0c41329a0f79c88485edb50
parentce8f574444dcc11ac762d45e218026f7a18fb394 (diff)
downloadprofani-tty-6dbcc0354324d194fa6c2091a030e2106042a172.tar.gz
Added g_hash_table_contains for glib < 2.32
-rw-r--r--src/common.c9
-rw-r--r--src/common.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c
index 2d9e5183..287572f9 100644
--- a/src/common.c
+++ b/src/common.c
@@ -81,6 +81,7 @@ p_list_free_full(GList *items, GDestroyNotify free_func)
 gboolean
 p_hash_table_add(GHashTable *hash_table, gpointer key)
 {
+    // doesn't handle when key exists, but value == NULL
     gpointer found = g_hash_table_lookup(hash_table, key);
     g_hash_table_replace(hash_table, key, key);
 
@@ -88,6 +89,14 @@ p_hash_table_add(GHashTable *hash_table, gpointer key)
 }
 
 gboolean
+p_hash_table_contains(GHashTable  *hash_table, gconstpointer key)
+{
+    // doesn't handle when key exists, but value == NULL
+    gpointer found = g_hash_table_lookup(hash_table, key);
+    return (found != NULL);
+}
+
+gboolean
 create_dir(char *name)
 {
     struct stat sb;
diff --git a/src/common.h b/src/common.h
index 1c402319..111ff376 100644
--- a/src/common.h
+++ b/src/common.h
@@ -38,6 +38,7 @@
 
 #if !GLIB_CHECK_VERSION(2,32,0)
 #define g_hash_table_add(hash_table, key)           p_hash_table_add(hash_table, key)
+#define g_hash_table_contains(hash_table, key)      p_hash_table_contains(hash_table, key);
 #endif
 
 #ifndef NOTIFY_CHECK_VERSION
@@ -79,6 +80,7 @@ gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos);
 void p_slist_free_full(GSList *items, GDestroyNotify free_func);
 void p_list_free_full(GList *items, GDestroyNotify free_func);
 gboolean p_hash_table_add(GHashTable *hash_table, gpointer key);
+gboolean p_hash_table_contains(GHashTable  *hash_table, gconstpointer  key);
 
 gboolean create_dir(char *name);
 gboolean mkdir_recursive(const char *dir);