Having populated a POSIX binary tree with tsearch
, how is it possible to clean-up the entire tree? GCC provides tdestroy
as an extension, but if you want to use POSIX-only functions how can you do it?
My current implementation uses twalk
to walk the tree and, for endorder
and leaf
nodes, calls tdelete
, but this understandably shows warnings about const-correctness:
static void free_tree(const void *node, const VISIT which, const int depth)
{
struct search_entry *entry;
switch (which) {
case endorder:
case leaf:
entry = *(struct search_entry **)node;
tdelete(entry->key, &node, search_entry_compare);
free(entry);
}
}
What was the expected approach for POSIX-compliant applications?