roentgen b75cab
/* $Id: lfind.c,v 1.4 2007/01/15 18:40:39 mloskot Exp $ */
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Copyright (c) 1989, 1993
roentgen b75cab
 *	The Regents of the University of California.  All rights reserved.
roentgen b75cab
 *
roentgen b75cab
 * This code is derived from software contributed to Berkeley by
roentgen b75cab
 * Roger L. Snyder.
roentgen b75cab
 *
roentgen b75cab
 * Redistribution and use in source and binary forms, with or without
roentgen b75cab
 * modification, are permitted provided that the following conditions
roentgen b75cab
 * are met:
roentgen b75cab
 * 1. Redistributions of source code must retain the above copyright
roentgen b75cab
 *    notice, this list of conditions and the following disclaimer.
roentgen b75cab
 * 2. Redistributions in binary form must reproduce the above copyright
roentgen b75cab
 *    notice, this list of conditions and the following disclaimer in the
roentgen b75cab
 *    documentation and/or other materials provided with the distribution.
roentgen b75cab
 * 3. Neither the name of the University nor the names of its contributors
roentgen b75cab
 *    may be used to endorse or promote products derived from this software
roentgen b75cab
 *    without specific prior written permission.
roentgen b75cab
 *
roentgen b75cab
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
roentgen b75cab
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
roentgen b75cab
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
roentgen b75cab
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
roentgen b75cab
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
roentgen b75cab
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
roentgen b75cab
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
roentgen b75cab
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
roentgen b75cab
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
roentgen b75cab
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
roentgen b75cab
 * SUCH DAMAGE.
roentgen b75cab
 */
roentgen b75cab
roentgen b75cab
#if 0
roentgen b75cab
static char sccsid[] = "@(#)lsearch.c	8.1 (Berkeley) 6/4/93";
roentgen b75cab
__RCSID("$NetBSD: lsearch.c,v 1.2 2005/07/06 15:47:15 drochner Exp $");
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
#ifdef _WIN32_WCE
roentgen b75cab
# include <wce_types.h></wce_types.h>
roentgen b75cab
#else
roentgen b75cab
# include <sys types.h=""></sys>
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
#ifndef NULL
roentgen b75cab
# define NULL 0
roentgen b75cab
#endif
roentgen b75cab
roentgen b75cab
void *
roentgen b75cab
lfind(const void *key, const void *base, size_t *nmemb, size_t size,
roentgen b75cab
      int(*compar)(const void *, const void *))
roentgen b75cab
{
roentgen b75cab
	char *element, *end;
roentgen b75cab
roentgen b75cab
	end = (char *)base + *nmemb * size;
roentgen b75cab
	for (element = (char *)base; element < end; element += size)
roentgen b75cab
		if (!compar(element, key))		/* key found */
roentgen b75cab
			return element;
roentgen b75cab
roentgen b75cab
	return NULL;
roentgen b75cab
}