source: trunk/sys/dietlibc/bsearch.c @ 181

Last change on this file since 181 was 1, checked in by alain, 7 years ago

First import

File size: 443 bytes
Line 
1#include <assert.h>
2#include <stdlib.h>
3
4void *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.