Blame port/lfind.c

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