]> git.sesse.net Git - vlc/blob - compat/tdestroy.c
t* remove the dependence to cdefs.h
[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 <assert.h>
24 #include <stdlib.h>
25
26 /* Walk the nodes of a tree */
27 static void
28 trecurse(node_t* root, void (*free_action)(void *))
29 {
30   if (root->llink != NULL)
31     trecurse(root->llink, free_action);
32   if (root->rlink != NULL)
33     trecurse(root->rlink, free_action);
34
35   (*free_action) ((void *) root->key);
36   free(root);
37 }
38
39 void
40 tdestroy(vrootp, freefct)
41        void *vrootp;
42        void (*freefct)(void *);
43 {
44   node_t *root = (node_t *) vrootp;
45
46   if (root != NULL)
47     trecurse(root, freefct);
48 }
49
50 #endif