ReactOS 0.4.15-dev-7906-g1b85a5f
bsearch.c
Go to the documentation of this file.
1/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2#include <stdlib.h>
3
4/*
5 * @implemented
6 */
7void *
9bsearch(const void *key, const void *base0, size_t nelem,
10 size_t size, int (__cdecl *cmp)(const void *ck, const void *ce))
11{
12 char *base = (char *)base0;
13 size_t lim;
14 int cmpval;
15 void *p;
16
17 for (lim = nelem; lim != 0; lim >>= 1)
18 {
19 p = base + (lim >> 1) * size;
20 cmpval = (*cmp)(key, p);
21 if (cmpval == 0)
22 return p;
23 if (cmpval > 0)
24 { /* key > p: move right */
25 base = (char *)p + size;
26 lim--;
27 } /* else move left */
28 }
29 return 0;
30}
#define __cdecl
Definition: accygwin.h:79
GLsizeiptr size
Definition: glext.h:5919
GLfloat GLfloat p
Definition: glext.h:8902
#define cmp(status, error)
Definition: error.c:114
#define nelem(x)
Definition: shaptest.c:19
Definition: copy.c:22
#define bsearch