Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/bsearch.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 450 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 450 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* |
2 | * bsearch.c |
3 | */ |
4 | |
5 | #include <stdlib.h> |
6 | |
7 | void *bsearch(const void *key, const void *base, size_t nmemb, |
8 | size_t size, int (*cmp) (const void *, const void *)) |
9 | { |
10 | while (nmemb) { |
11 | size_t mididx = nmemb / 2; |
12 | const void *midobj = base + mididx * size; |
13 | int diff = cmp(key, midobj); |
14 | |
15 | if (diff == 0) |
16 | return (void *)midobj; |
17 | |
18 | if (diff > 0) { |
19 | base = midobj + size; |
20 | nmemb -= mididx + 1; |
21 | } else |
22 | nmemb = mididx; |
23 | } |
24 | |
25 | return NULL; |
26 | } |