X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fhashmap.c;h=26a4eff07fb3b7336d95e585e3e6bd338bdbd4e2;hb=915bf0f60fa77ffc2e7e229fff8fdc262912f912;hp=0a044b85ad25a7901025d1a8ae2474a83ab00d66;hpb=9f89986d2beb2c45436cc9e5b4da8bd4a79f100c;p=elogind.git diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c index 0a044b85a..26a4eff07 100644 --- a/src/shared/hashmap.c +++ b/src/shared/hashmap.c @@ -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,8 +377,8 @@ 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; @@ -752,3 +758,25 @@ char **hashmap_get_strv(Hashmap *h) { return sv; } + +void *hashmap_next(Hashmap *h, const void *key) { + unsigned hash; + struct hashmap_entry *e; + + assert(h); + assert(key); + + if (!h) + return NULL; + + hash = h->hash_func(key) % NBUCKETS; + e = hash_scan(h, hash, key); + if (!e) + return NULL; + + e = e->iterate_next; + if (!e) + return NULL; + + return e->value; +}