From 6241eed3dbfb68ab8404552432042d29c4e75f94 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 19 Apr 2012 10:21:43 -0400 Subject: [PATCH] Implement virHashRemoveAll function Implement function to remove all entries of a hash table. --- src/libvirt_private.syms | 1 + src/util/virhash.c | 25 +++++++++++++++++++++++++ src/util/virhash.h | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8d29e75842..a590a319b5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -578,6 +578,7 @@ virHashForEach; virHashFree; virHashGetItems; virHashLookup; +virHashRemoveAll; virHashRemoveEntry; virHashRemoveSet; virHashSearch; diff --git a/src/util/virhash.c b/src/util/virhash.c index 50c6ac5835..5794d6f654 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -575,6 +575,31 @@ virHashRemoveSet(virHashTablePtr table, return count; } +static int +_virHashRemoveAllIter(const void *payload ATTRIBUTE_UNUSED, + const void *name ATTRIBUTE_UNUSED, + const void *data ATTRIBUTE_UNUSED) +{ + return 1; +} + +/** + * virHashRemoveAll + * @table: the hash table to clear + * + * Free the hash @table's contents. The userdata is + * deallocated with the function provided at creation time. + * + * Returns the number of items removed on success, -1 on failure + */ +ssize_t +virHashRemoveAll(virHashTablePtr table) +{ + return virHashRemoveSet(table, + _virHashRemoveAllIter, + NULL); +} + /** * virHashSearch: * @table: the hash table to search diff --git a/src/util/virhash.h b/src/util/virhash.h index 7acbcbdd62..2c04f811f2 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -126,6 +126,11 @@ int virHashUpdateEntry(virHashTablePtr table, int virHashRemoveEntry(virHashTablePtr table, const void *name); +/* + * Remove all entries from the hash table. + */ +ssize_t virHashRemoveAll(virHashTablePtr table); + /* * Retrieve the userdata. */ -- GitLab