aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/tdestroy.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-08-13 17:02:11 -0700
committerElliott Hughes <enh@google.com>2012-08-13 17:41:49 -0700
commit409302f0f9fce73ea4c82bbfd439041cd7923d34 (patch)
treebc23c82d6b9a68cfe2b114496399e1561d5db749 /libc/bionic/tdestroy.c
parent54655eaf92ca91bfe2fa293896059a181e27b6eb (diff)
downloadandroid_bionic-409302f0f9fce73ea4c82bbfd439041cd7923d34.tar.gz
android_bionic-409302f0f9fce73ea4c82bbfd439041cd7923d34.tar.bz2
android_bionic-409302f0f9fce73ea4c82bbfd439041cd7923d34.zip
Switch to upstream NetBSD tdelete/tfind/tsearch.
tdestroy is a GNU extension, so that stays. Change-Id: Iedebaff25ea7e92b1ab1dd4440da12b67b99aa40
Diffstat (limited to 'libc/bionic/tdestroy.c')
-rw-r--r--libc/bionic/tdestroy.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/libc/bionic/tdestroy.c b/libc/bionic/tdestroy.c
index 70b71f4af..decde4da8 100644
--- a/libc/bionic/tdestroy.c
+++ b/libc/bionic/tdestroy.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012, The Android Open Source Project
+ * Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,16 +18,19 @@
#include <search.h>
#include <stdlib.h>
-/* destroy a tree and free all allocated resources */
-void
-tdestroy(void *root, void (*destroy_func)(void *))
-{
- node_t *root_node = (node_t *) root;
- if (root_node == NULL) return;
- if (root_node->llink)
- tdestroy(root_node->llink, destroy_func);
- if (root_node->rlink)
- tdestroy(root_node->rlink, destroy_func);
- (*destroy_func)(root_node->key);
- free(root);
+// Destroy a tree and free all allocated resources.
+// This is a GNU extension, not available from NetBSD.
+void tdestroy(void* root, void (*destroy_func)(void*)) {
+ node_t* root_node = (node_t*) root;
+ if (root_node == NULL) {
+ return;
+ }
+ if (root_node->llink) {
+ tdestroy(root_node->llink, destroy_func);
+ }
+ if (root_node->rlink) {
+ tdestroy(root_node->rlink, destroy_func);
+ }
+ (*destroy_func)(root_node->key);
+ free(root);
}