diff options
author | nsz <nsz@port70.net> | 2012-05-13 01:34:20 +0200 |
---|---|---|
committer | nsz <nsz@port70.net> | 2012-05-13 01:34:20 +0200 |
commit | d197d6421c317145e2aff89dd41de9d03eeaa00b (patch) | |
tree | 7d908d68391a592e9843d49443874f0461bc9f51 | |
parent | b47fdcdef8e88452914636ce23ee6792f259b5dc (diff) | |
download | musl-d197d6421c317145e2aff89dd41de9d03eeaa00b.tar.gz musl-d197d6421c317145e2aff89dd41de9d03eeaa00b.tar.xz musl-d197d6421c317145e2aff89dd41de9d03eeaa00b.zip |
search: add tdestroy (gnu extension)
-rw-r--r-- | include/search.h | 2 | ||||
-rw-r--r-- | src/search/tdestroy.c | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/search.h b/include/search.h index 3fa41adc..7c4fc583 100644 --- a/include/search.h +++ b/include/search.h @@ -38,6 +38,8 @@ struct qelem { struct qelem *q_forw, *q_back; char q_data[1]; }; + +void tdestroy(void *, void (*)(void *)); #endif #ifdef __cplusplus 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); +} |