memchr.c revision 225736
155714Skris/*-
255714Skris * Copyright (c) 1990, 1993
355714Skris *	The Regents of the University of California.  All rights reserved.
455714Skris *
555714Skris * This code is derived from software contributed to Berkeley by
655714Skris * Chris Torek.
755714Skris *
8280304Sjkim * Redistribution and use in source and binary forms, with or without
955714Skris * modification, are permitted provided that the following conditions
1055714Skris * are met:
1155714Skris * 1. Redistributions of source code must retain the above copyright
1255714Skris *    notice, this list of conditions and the following disclaimer.
1355714Skris * 2. Redistributions in binary form must reproduce the above copyright
1455714Skris *    notice, this list of conditions and the following disclaimer in the
15280304Sjkim *    documentation and/or other materials provided with the distribution.
1655714Skris * 4. Neither the name of the University nor the names of its contributors
1755714Skris *    may be used to endorse or promote products derived from this software
1855714Skris *    without specific prior written permission.
1955714Skris *
2055714Skris * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2155714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22280304Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2355714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2455714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2555714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2655714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2755714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2855714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2955714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3055714Skris * SUCH DAMAGE.
3155714Skris */
3255714Skris
3355714Skris#if defined(LIBC_SCCS) && !defined(lint)
3455714Skrisstatic char sccsid[] = "@(#)memchr.c	8.1 (Berkeley) 6/4/93";
3555714Skris#endif /* LIBC_SCCS and not lint */
3655714Skris#include <sys/cdefs.h>
37280304Sjkim__FBSDID("$FreeBSD: stable/9/lib/libc/string/memchr.c 188295 2009-02-07 19:34:44Z imp $");
3855714Skris
3955714Skris#include <string.h>
40280304Sjkim
4155714Skrisvoid *
4255714Skrismemchr(const void *s, int c, size_t n)
4355714Skris{
4455714Skris	if (n != 0) {
4555714Skris		const unsigned char *p = s;
4655714Skris
4755714Skris		do {
4855714Skris			if (*p++ == (unsigned char)c)
4955714Skris				return ((void *)(p - 1));
5055714Skris		} while (--n != 0);
5155714Skris	}
52280304Sjkim	return (NULL);
5355714Skris}
5455714Skris