diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-05-30 01:37:13 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-05-30 01:37:13 +0000 |
commit | d951286f645cc1d6f719c0c715620fc395c049d4 (patch) | |
tree | ff756b3d8cb561d733337cf27bca2e26358852ba /misc/tsearch.c | |
parent | 76b87c039ba8d20add4f52ba43f3471fd92e210b (diff) | |
download | glibc-d951286f645cc1d6f719c0c715620fc395c049d4.tar.gz glibc-d951286f645cc1d6f719c0c715620fc395c049d4.tar.xz glibc-d951286f645cc1d6f719c0c715620fc395c049d4.zip |
Update. cvs/libc-ud-970539 cvs/libc-ud-970529
* io/Makefile (test-srcs): Add ftwtest. (distribute): Add ftwtest-sh. (tests): Call ftwtest-sh for this goal. * io/ftwtest-sh: New file. Sets up test environment, calls test program and compares the result. * io/ftwtest.c: Test program for ftw. * misc/search.h: Add comments. Declare tdestroy. * misc/tsearch.c (tdestroy): New function.
Diffstat (limited to 'misc/tsearch.c')
-rw-r--r-- | misc/tsearch.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/misc/tsearch.c b/misc/tsearch.c index 466536bf34..c06930d509 100644 --- a/misc/tsearch.c +++ b/misc/tsearch.c @@ -300,7 +300,7 @@ weak_alias (__tsearch, tsearch) void * __tfind (key, vrootp, compar) const void *key; - const void **vrootp; + void *const *vrootp; __compar_fn_t compar; { node *rootp = (node *) vrootp; @@ -625,3 +625,36 @@ __twalk (const void *vroot, __action_fn_t action) trecurse (root, action, 0); } weak_alias (__twalk, twalk) + + + +/* The standardized functions miss an important functionality: the + tree cannot be removed easily. We provide a function to do this. */ +static void +tdestroy_recurse (node root, __free_fn_t freefct) +{ + if (root->left == NULL && root->right == NULL) + (*freefct) (root->key); + else + { + if (root->left != NULL) + tdestroy_recurse (root->left, freefct); + if (root->right != NULL) + tdestroy_recurse (root->right, freefct); + (*freefct) (root->key); + } + /* Free the node itself. */ + free (root); +} + +void +__tdestroy (void *vroot, __free_fn_t freefct) +{ + node root = (node) vroot; + + CHECK_TREE (root); + + if (root != NULL) + tdestroy_recurse (root, freefct); +} +weak_alias (__tdestroy, tdestroy) |