about summary refs log tree commit diff
path: root/src/search/tdestroy.c
diff options
context:
space:
mode:
authornsz <nsz@port70.net>2012-05-13 01:34:20 +0200
committernsz <nsz@port70.net>2012-05-13 01:34:20 +0200
commitd197d6421c317145e2aff89dd41de9d03eeaa00b (patch)
tree7d908d68391a592e9843d49443874f0461bc9f51 /src/search/tdestroy.c
parentb47fdcdef8e88452914636ce23ee6792f259b5dc (diff)
downloadmusl-d197d6421c317145e2aff89dd41de9d03eeaa00b.tar.gz
musl-d197d6421c317145e2aff89dd41de9d03eeaa00b.tar.xz
musl-d197d6421c317145e2aff89dd41de9d03eeaa00b.zip
search: add tdestroy (gnu extension)
Diffstat (limited to 'src/search/tdestroy.c')
-rw-r--r--src/search/tdestroy.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/search/tdestroy.c b/src/search/tdestroy.c
new file mode 100644
index 00000000..6f430bda
--- /dev/null
+++ b/src/search/tdestroy.c
@@ -0,0 +1,21 @@
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <search.h>
+
+struct node {
+	void *key;
+	struct node *left;
+	struct node *right;
+};
+
+void tdestroy(void *root, void (*freekey)(void *))
+{
+	struct node *r = root;
+
+	if (r == 0)
+		return;
+	tdestroy(r->left, freekey);
+	tdestroy(r->right, freekey);
+	freekey(r->key);
+	free(r);
+}