diff options
author | theraven <theraven@FreeBSD.org> | 2014-04-02 16:07:48 +0000 |
---|---|---|
committer | theraven <theraven@FreeBSD.org> | 2014-04-02 16:07:48 +0000 |
commit | 0127b103f27578fc7f9cc3389b299f221deb1d4c (patch) | |
tree | 6b79951e49825ea224053fd3b29a53481afa5e00 /lib/libc/stdlib/bsearch.c | |
parent | 2b2f1d5e5ca561f2d22a5740eb522aba203a4bd9 (diff) | |
download | FreeBSD-src-0127b103f27578fc7f9cc3389b299f221deb1d4c.zip FreeBSD-src-0127b103f27578fc7f9cc3389b299f221deb1d4c.tar.gz |
Add support for some block functions that come from OS X. These are
intended to build with any C compiler.
Reviewed by: pfg
MFC after: 3 weeks
Diffstat (limited to 'lib/libc/stdlib/bsearch.c')
-rw-r--r-- | lib/libc/stdlib/bsearch.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/libc/stdlib/bsearch.c b/lib/libc/stdlib/bsearch.c index 4bcaaf3..4a1dd52 100644 --- a/lib/libc/stdlib/bsearch.c +++ b/lib/libc/stdlib/bsearch.c @@ -36,6 +36,13 @@ __FBSDID("$FreeBSD$"); #include <stddef.h> #include <stdlib.h> +#ifdef I_AM_BSEARCH_B +#include "block_abi.h" +#define COMPAR(x,y) CALL_BLOCK(compar, x, y) +#else +#define COMPAR(x,y) compar(x, y) +#endif + /* * Perform a binary search. * @@ -52,6 +59,15 @@ __FBSDID("$FreeBSD$"); * have to make lim 3, then halve, obtaining 1, so that we will only * look at item 3. */ +#ifdef I_AM_BSEARCH_B +void * +bsearch_b(key, base0, nmemb, size, compar) + const void *key; + const void *base0; + size_t nmemb; + size_t size; + DECLARE_BLOCK(int, compar, const void *, const void *); +#else void * bsearch(key, base0, nmemb, size, compar) const void *key; @@ -59,6 +75,7 @@ bsearch(key, base0, nmemb, size, compar) size_t nmemb; size_t size; int (*compar)(const void *, const void *); +#endif { const char *base = base0; size_t lim; @@ -67,7 +84,7 @@ bsearch(key, base0, nmemb, size, compar) for (lim = nmemb; lim != 0; lim >>= 1) { p = base + (lim >> 1) * size; - cmp = (*compar)(key, p); + cmp = COMPAR(key, p); if (cmp == 0) return ((void *)p); if (cmp > 0) { /* key > p: move right */ |