diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-04-07 17:39:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-04-07 17:39:39 -0700 |
commit | d93fd8156ba2530d5ff12caaf9b0eaf557f60de5 (patch) | |
tree | 1f14dcda503ae7ad02be897b0c458abbf699a92a /system/lib/libc/musl/src/stdlib/bsearch.c | |
parent | d19741ee04ee2c87af48c22902afdc06c22f4aac (diff) | |
parent | a04fd2a2c6110b5c7f65c1d993a582fb12e505e4 (diff) |
Merge pull request #2256 from juj/more_musl1.14.1
More musl.
Diffstat (limited to 'system/lib/libc/musl/src/stdlib/bsearch.c')
-rw-r--r-- | system/lib/libc/musl/src/stdlib/bsearch.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/system/lib/libc/musl/src/stdlib/bsearch.c b/system/lib/libc/musl/src/stdlib/bsearch.c new file mode 100644 index 00000000..61d89367 --- /dev/null +++ b/system/lib/libc/musl/src/stdlib/bsearch.c @@ -0,0 +1,20 @@ +#include <stdlib.h> + +void *bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *)) +{ + void *try; + int sign; + while (nel > 0) { + try = (char *)base + width*(nel/2); + sign = cmp(key, try); + if (!sign) return try; + else if (nel == 1) break; + else if (sign < 0) + nel /= 2; + else { + base = try; + nel -= nel/2; + } + } + return NULL; +} |