1 #include <search.h> 2 #include "tsearch.h" 3 4 void *tfind(const void *key, void *const *rootp, 5 int(*cmp)(const void *, const void *)) 6 { 7 if (!rootp) 8 return 0; 9 10 { 11 struct node *n = *rootp; 12 for (;;) { 13 if (!n) 14 break; 15 { 16 int c = cmp(key, n->key); 17 if (!c) 18 break; 19 n = n->a[c>0]; 20 } 21 } 22 return n; 23 } 24 } 25