Back to index

glibc  2.9
Functions
lsearch.c File Reference
#include <search.h>
#include <string.h>

Go to the source code of this file.

Functions

void * lsearch (const void *key, void *base, size_t *nmemb, size_t size, __compar_fn_t compar)
void * lfind (const void *key, const void *base, size_t *nmemb, size_t size, __compar_fn_t compar)

Function Documentation

void* lfind ( const void *  key,
const void *  base,
size_t nmemb,
size_t  size,
__compar_fn_t  compar 
)

Definition at line 45 of file lsearch.c.

{
  const void *result = base;
  size_t cnt = 0;

  while (cnt < *nmemb && (*compar) (key, result) != 0)
    {
      result += size;
      ++cnt;
    }

  return cnt < *nmemb ? (void *) result : NULL;
}

Here is the caller graph for this function:

void* lsearch ( const void *  key,
void *  base,
size_t nmemb,
size_t  size,
__compar_fn_t  compar 
)

Definition at line 26 of file lsearch.c.

{
  void *result;

  /* Try to find it.  */
  result = lfind (key, base, nmemb, size, compar);
  if (result == NULL)
    {
      /* Not available.  Insert at the end.  */
      result = memcpy (base + (*nmemb) * size, key, size);
      ++(*nmemb);
    }

  return result;
}

Here is the call graph for this function: