Blame port/lfind.c

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