source:
trunk/sys/dietlibc/bsearch.c
@
363
Last change on this file since 363 was 1, checked in by , 8 years ago | |
---|---|
File size: 443 bytes |
Line | |
---|---|
1 | #include <assert.h> |
2 | #include <stdlib.h> |
3 | |
4 | void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void* , const void* )) { |
5 | size_t m; |
6 | while (nmemb) { |
7 | int tmp; |
8 | void *p; |
9 | m=nmemb/2; |
10 | p=(void *) (((const char *) base) + (m * size)); |
11 | if ((tmp=(*compar)(key,p))<0) { |
12 | nmemb=m; |
13 | } else if (tmp>0) { |
14 | base=p+size; |
15 | nmemb-=m+1; |
16 | } else |
17 | return p; |
18 | } |
19 | return 0; |
20 | } |
Note: See TracBrowser
for help on using the repository browser.