toaruos/libc/stdlib/bsearch.c

16 lines
339 B
C
Raw Normal View History

2018-10-10 03:35:09 +03:00
#include <stdlib.h>
void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *)) {
/* Stupid naive implementation */
const char * b = base;
size_t i = 0;
while (i < nmemb) {
const void * a = b;
if (!compar(a,key)) return (void *)a;
i++;
b += size;
}
return NULL;
}