Chameleon

Chameleon Svn Source Tree

Root/branches/meklortOld/i386/modules/klibc/bsearch.c

Source at commit 1166 created 13 years 10 days ago.
By meklort, Fixed recent Makefile changes. Please do not use /Users/evan/SourceCode/tmp/chameleon/trunk or VPATH. the *only* time you should use /Users/evan/SourceCode/tmp/chameleon/trunk is when setting the SRCROOT variable. Also note that very soon make pkg is going to be removed. The pkg build script in trunk is very out of date. Instead please use the package maker at http://forge.voodooprojects.org/p/chameleonApplications/. Once this is ready for trunk it will be merged.
1/*
2 * bsearch.c
3 */
4
5#include <stdlib.h>
6
7void *bsearch(const void *key, const void *base, size_t nmemb,
8 size_t size, int (*cmp) (const void *, const void *))
9{
10while (nmemb) {
11size_t mididx = nmemb / 2;
12const void *midobj = base + mididx * size;
13int diff = cmp(key, midobj);
14
15if (diff == 0)
16return (void *)midobj;
17
18if (diff > 0) {
19base = midobj + size;
20nmemb -= mididx + 1;
21} else
22nmemb = mididx;
23}
24
25return NULL;
26}
27

Archive Download this file

Revision: 1166