]> git.sesse.net Git - vlc/blob - compat/tdestroy.c
Implement tsearch functions for systems that does not know about it.
[vlc] / compat / tdestroy.c
1 /*      $NetBSD: tdestroy.c,v 1.2 1999/09/16 11:45:37 lukem Exp $       */
2
3 /*
4  * Tree search generalized from Knuth (6.2.2) Algorithm T just like
5  * the AT&T man page says.
6  *
7  * The node_t structure is for internal use only, lint doesn't grok it.
8  *
9  * Written by reading the System V Interface Definition, not the code.
10  *
11  * Totally public domain.
12  */
13
14 #define _SEARCH_PRIVATE
15
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
19
20 #include <sys/cdefs.h>
21 #include <assert.h>
22 #include <stdlib.h>
23
24 /* Walk the nodes of a tree */
25 static void
26 trecurse(node_t* root, void (*free_action)(void *))
27 {
28   if (root->llink != NULL)
29     trecurse(root->llink, free_action);
30   if (root->rlink != NULL)
31     trecurse(root->rlink, free_action);
32
33   (*free_action) ((void *) root->key);
34   free(root);
35 }
36
37 void
38 tdestroy(vrootp, freefct)
39        void *vrootp;
40        void (*freefct)(void *);
41 {
42   node_t *root = (node_t *) vrootp;
43
44   if (root != NULL)
45     trecurse(root, freefct);
46 }