Chameleon

Chameleon Svn Source Tree

Root/tags/2.0/i386/modules/klibc/bsearch.c

Source at commit 1808 created 12 years 4 months ago.
By blackosx, Revise layout of package installer 'Welcome' file so it looks cleaner. Change the copyright notice to begin from 2009 as seen in the Chameleon 2.0 r431 installer. Should this date be set earlier?
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: 1808