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