Back to index

cell-binutils  2.17cvs20070401
Functions
bsearch.c File Reference
#include "config.h"
#include "ansidecl.h"
#include <sys/types.h>
#include <stdio.h>

Go to the source code of this file.

Functions

void * bsearch (register const void *key, const void *base0, size_t nmemb, register size_t size, register int(*compar)(const void *, const void *))

Function Documentation

void* bsearch ( register const void *  key,
const void *  base0,
size_t  nmemb,
register size_t  size,
register int(*)(const void *, const void *)  compar 
)

Definition at line 70 of file bsearch.c.

{
       register const char *base = (const char *) base0;
       register int lim, cmp;
       register const void *p;

       for (lim = nmemb; lim != 0; lim >>= 1) {
              p = base + (lim >> 1) * size;
              cmp = (*compar)(key, p);
              if (cmp == 0)
                     return (void *)p;
              if (cmp > 0) {       /* key > p: move right */
                     base = (const char *)p + size;
                     lim--;
              } /* else move left */
       }
       return (NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function: