home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / misc / lfind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-20  |  802 b   |  27 lines

  1. /* $Id: lfind.c,v 1.1 1994/05/21 13:23:03 chris Exp $ */
  2.  
  3. #include <ansidecl.h>
  4. #include <search.h>
  5.  
  6. /* Perform a linear search for KEY in BASE which has *NMEMB elements
  7.    of SIZE bytes each.  The comparisons are done by (*COMPAR)(), which
  8.    must return zero if the elements being compared are equal, and
  9.    non-zero otherwise. 
  10.    Returns NULL if not found */
  11. PTR
  12. DEFUN(lfind, (key, base, pnmemb, size, compar),
  13.       register CONST PTR key AND CONST PTR base AND
  14.       register size_t *nmemb AND register size_t size AND
  15.       register int EXFUN((*compar), (CONST PTR, CONST PTR)))
  16. {
  17.   register size_t i;
  18.   register CONST PTR p;
  19.  
  20.   for(i = 0, p = base; i < *nmemb; 
  21.              p = (PTR) (((CONST char *) p) + size), i++)
  22.       if ( !((*compar)(key, p)))
  23.         return (PTR) p;
  24.  
  25.   return NULL;
  26. }
  27.