libroot: Reinstate tdestroy.

It was removed in hrev55422 as we never had declared it in any headers.
But it seems some software came to depend on it anyway. Reinstate it,
and add a declaration for it, behind _GNU_SOURCE.
This commit is contained in:
Augustin Cavalier 2021-09-17 15:34:10 -04:00
parent aa04f48dcf
commit ffbe2ad946
3 changed files with 21 additions and 0 deletions

View File

@ -49,6 +49,10 @@ extern void *tsearch(const void *key, void **_root,
extern void twalk(const void *root,
void (*action)(const void *, VISIT, int ));
#ifdef _GNU_SOURCE
extern void tdestroy(void *root, void (*free_key)(void *))
#endif
#ifdef __cplusplus
}
#endif

View File

@ -13,6 +13,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
insque.c
lsearch.c
tdelete.c
tdestroy.c
tfind.c
tsearch.c
twalk.c

View File

@ -0,0 +1,16 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <search.h>
#include "tsearch.h"
void tdestroy(void *root, void (*freekey)(void *))
{
struct node *r = root;
if (r == 0)
return;
tdestroy(r->a[0], freekey);
tdestroy(r->a[1], freekey);
if (freekey) freekey((void *)r->key);
free(r);
}