]> git.sesse.net Git - vlc/blob - compat/tdestroy.c
tdestroy: fix compilation for system that does have search.h but not tdestroy.
[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 // Do not implement tdestroy if that's the only missing t* function
21 #ifndef HAVE_SEARCH_H
22
23 #include <sys/cdefs.h>
24 #include <assert.h>
25 #include <stdlib.h>
26
27 /* Walk the nodes of a tree */
28 static void
29 trecurse(node_t* root, void (*free_action)(void *))
30 {
31   if (root->llink != NULL)
32     trecurse(root->llink, free_action);
33   if (root->rlink != NULL)
34     trecurse(root->rlink, free_action);
35
36   (*free_action) ((void *) root->key);
37   free(root);
38 }
39
40 void
41 tdestroy(vrootp, freefct)
42        void *vrootp;
43        void (*freefct)(void *);
44 {
45   node_t *root = (node_t *) vrootp;
46
47   if (root != NULL)
48     trecurse(root, freefct);
49 }
50
51 #endif