toaruos/libc/stdlib/bsearch.c
2018-10-10 09:35:09 +09:00

16 lines
339 B
C

#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;
}