chiark / gitweb /
shared: call va_end in all cases
[elogind.git] / src / shared / hashmap.c
index e2395d4d4290caab9eb1e5a2024ba7fb294d1324..eb5c549e404a9ce80e08fed07f5a2f56dc2f97ca 100644 (file)
@@ -265,6 +265,8 @@ static void remove_entry(Hashmap *h, struct hashmap_entry *e) {
 
 void hashmap_free(Hashmap*h) {
 
+        /* Free the hashmap, but nothing in it */
+
         if (!h)
                 return;
 
@@ -277,6 +279,10 @@ void hashmap_free(Hashmap*h) {
 }
 
 void hashmap_free_free(Hashmap *h) {
+
+        /* Free the hashmap and all data objects in it, but not the
+         * keys */
+
         if (!h)
                 return;
 
@@ -371,13 +377,27 @@ void* hashmap_get(Hashmap *h, const void *key) {
                 return NULL;
 
         hash = h->hash_func(key) % NBUCKETS;
-
-        if (!(e = hash_scan(h, hash, key)))
+        e = hash_scan(h, hash, key);
+        if (!e)
                 return NULL;
 
         return e->value;
 }
 
+bool hashmap_contains(Hashmap *h, const void *key) {
+        unsigned hash;
+
+        if (!h)
+                return false;
+
+        hash = h->hash_func(key) % NBUCKETS;
+
+        if (!hash_scan(h, hash, key))
+                return false;
+
+        return true;
+}
+
 void* hashmap_remove(Hashmap *h, const void *key) {
         struct hashmap_entry *e;
         unsigned hash;