home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
c
/
bsearch
< prev
next >
Wrap
Text File
|
1994-03-08
|
896b
|
50 lines
#ifdef __STDC__
static char sccs_id[] = "@(#) bsearch.c 1.1 " __DATE__ " HJR";
#else
static char sccs_id[] = "@(#) bsearch.c 1.1 26/9/90 HJR";
#endif
/* bsearch.c (c) Copyright 1990 H.Rogers */
#ifdef __STDC__
#include <stddef.h>
#include <stdlib.h>
#else
#include "sys/types.h"
void *bsearch ();
#endif
#ifdef __STDC__
void *
bsearch (register const void *k, const void *v, register size_t n,
register size_t z, register int (*c) (const void *, const void *))
#else
void *
bsearch (k, v, n, z, c)
register const void *k;
const void *v;
register size_t n;
register size_t z;
register int (*c) ();
#endif
{
register char *b, *m;
register int p;
b = (char *) v;
while (n)
{
m = b + ((n >> 1) * z);
p = (*c) (k, m);
if (!p)
return (m);
if (p > 0)
b = m + z, n = n - (n >> 1) - 1;
else
n = (n >> 1);
}
return (0);
}