reactos/lib/sdk/crt/search/bsearch.c
Cameron Gutman c2d0d784c7 [USB-BRINGUP-TRUNK]
- Create a branch to do a proper merge of USB work from a trunk base instead of from cmake-bringup
- In the future, DO NOT under any circumstances branch another branch. This leads to merge problems!

svn path=/branches/usb-bringup-trunk/; revision=55018
2012-01-20 20:58:46 +00:00

30 lines
600 B
C

/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
/*
* @implemented
*/
void *
bsearch(const void *key, const void *base0, size_t nelem,
size_t size, int (__cdecl *cmp)(const void *ck, const void *ce))
{
char *base = (char *)base0;
size_t lim;
int cmpval;
void *p;
for (lim = nelem; lim != 0; lim >>= 1)
{
p = base + (lim >> 1) * size;
cmpval = (*cmp)(key, p);
if (cmpval == 0)
return p;
if (cmpval > 0)
{ /* key > p: move right */
base = (char *)p + size;
lim--;
} /* else move left */
}
return 0;
}