diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8d29e75842837690acbd6d37268cb90ac7b98207..a590a319b5685b371612228d27797172f5c6e734 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 50c6ac58352be0d7651a92046a01c7564118b317..5794d6f654d2cdb583340862a63fb2a661911574 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 7acbcbdd625dc048a1a823946b05d04183bafe6f..2c04f811f2b122f7b0a38e23ab18d21864aca42a 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. */