1 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2 #include <msvcrt/stdlib.h>
8 bsearch(const void *key, const void *base0, size_t nelem,
9 size_t size, int (*cmp)(const void *ck, const void *ce))
11 char *base = (char *)base0;
15 for (lim = nelem; lim != 0; lim >>= 1)
17 p = base + (lim >> 1) * size;
18 cmpval = (*cmp)(key, p);
22 { /* key > p: move right */
23 base = (char *)p + size;
25 } /* else move left */