X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fhashmap.c;h=53502576ad8b9773d08a528853ce7c27948c865c;hb=e025b4c306d4b0895786839ebbb934188edc6e61;hp=6b6e909ba385a3542dc7944d95b2eb7006ba2e42;hpb=d6c9574fb558d9e304699b1cc7522c3b133adfc9;p=elogind.git diff --git a/src/hashmap.c b/src/hashmap.c index 6b6e909ba..53502576a 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -173,6 +173,15 @@ void hashmap_free(Hashmap*h) { free(h); } +void hashmap_free_free(Hashmap *h) { + void *p; + + while ((p = hashmap_steal_first(h))) + free(p); + + hashmap_free(h); +} + void hashmap_clear(Hashmap *h) { if (!h) return; @@ -467,6 +476,21 @@ void* hashmap_steal_first(Hashmap *h) { return data; } +void* hashmap_steal_first_key(Hashmap *h) { + void *key; + + if (!h) + return NULL; + + if (!h->iterate_list_head) + return NULL; + + key = (void*) h->iterate_list_head->key; + remove_entry(h, h->iterate_list_head); + + return key; +} + unsigned hashmap_size(Hashmap *h) { if (!h) @@ -568,3 +592,21 @@ Hashmap *hashmap_copy(Hashmap *h) { return copy; } + +char **hashmap_get_strv(Hashmap *h) { + char **sv; + Iterator it; + char *path; + int n; + + sv = malloc((h->n_entries+1) * sizeof(char *)); + if (sv == NULL) + return NULL; + + n = 0; + HASHMAP_FOREACH(path, h, it) + sv[n++] = path; + sv[n] = NULL; + + return sv; +}