Index: b/usr/src/head/search.h =================================================================== --- a/usr/src/head/search.h +++ b/usr/src/head/search.h @@ -32,7 +32,7 @@ #ifndef _SEARCH_H #define _SEARCH_H -#include +#include #include #ifdef __cplusplus @@ -69,6 +69,10 @@ void *tfind(const void *, void *const *, void *tsearch(const void *, void **, int (*)(const void *, const void *)); void twalk(const void *, void (*)(const void *, VISIT, int)); +#if defined(__EXTENSIONS__) || defined(_GNU_SOURCE) +extern void tdestroy(void *root, void (*)(void *)); +#endif + #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) /* BSEARCH(3C) */ Index: b/usr/src/lib/libc/port/mapfile-vers =================================================================== --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -280,6 +280,7 @@ SYMBOL_VERSION DYSON_1 { program_invocation_name; program_invocation_short_name; rawmemchr; + tdestroy; wmempcpy; } ILLUMOS_0.3; Index: b/usr/src/lib/libc/port/gen/tsearch.c =================================================================== --- a/usr/src/lib/libc/port/gen/tsearch.c +++ b/usr/src/lib/libc/port/gen/tsearch.c @@ -156,3 +156,23 @@ __twalk(NODE *root, /* Root of the tree (*action)(root, endorder, level); } } + + +static void +tdestroy_recursive(NODE *r, void (*free_node)(void *nodep)) +{ + if (NULL != r->llink) + tdestroy_recursive(r->llink, free_node); + if (NULL != r->rlink) + tdestroy_recursive(r->rlink, free_node); + (*free_node) ((void*) r->key); + lfree(r, sizeof (NODE)); +} + +void tdestroy(void *root, void (*free_node)(void *nodep)) +{ + NODE *r = (NODE*) root; + if (NULL != r) + tdestroy_recursive(r, free_node); +} +