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