119304Speter/*- 219304Speter * Copyright (c) 1990, 1993 319304Speter * The Regents of the University of California. All rights reserved. 419304Speter * 519304Speter * This code is derived from software contributed to Berkeley by 619304Speter * Chris Torek. 719304Speter * 819304Speter * Redistribution and use in source and binary forms, with or without 919304Speter * modification, are permitted provided that the following conditions 1019304Speter * are met: 1119304Speter * 1. Redistributions of source code must retain the above copyright 1219304Speter * notice, this list of conditions and the following disclaimer. 1319304Speter * 2. Redistributions in binary form must reproduce the above copyright 1419304Speter * notice, this list of conditions and the following disclaimer in the 1519304Speter * documentation and/or other materials provided with the distribution. 1619304Speter * 3. All advertising materials mentioning features or use of this software 1719304Speter * must display the following acknowledgement: 1819304Speter * This product includes software developed by the University of 1919304Speter * California, Berkeley and its contributors. 2019304Speter * 4. Neither the name of the University nor the names of its contributors 2119304Speter * may be used to endorse or promote products derived from this software 2219304Speter * without specific prior written permission. 2319304Speter * 2419304Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2519304Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2619304Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2719304Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2819304Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2919304Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3019304Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3119304Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3219304Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3319304Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3419304Speter * SUCH DAMAGE. 3519304Speter */ 3619304Speter 3719304Speter#include "config.h" 3819304Speter 3919304Speter#if defined(LIBC_SCCS) && !defined(lint) 4019304Speterstatic const char sccsid[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93"; 4119304Speter#endif /* LIBC_SCCS and not lint */ 4219304Speter 4319304Speter#include <string.h> 4419304Speter 4519304Speter/* 4619304Speter * PUBLIC: #ifndef HAVE_MEMCHR 4719304Speter * PUBLIC: void *memchr __P((const void *, int, size_t)); 4819304Speter * PUBLIC: #endif 4919304Speter */ 5019304Spetervoid * 5119304Spetermemchr(s, c, n) 5219304Speter const void *s; 5319304Speter register unsigned char c; 5419304Speter register size_t n; 5519304Speter{ 5619304Speter if (n != 0) { 5719304Speter register const unsigned char *p = s; 5819304Speter 5919304Speter do { 6019304Speter if (*p++ == c) 6119304Speter return ((void *)(p - 1)); 6219304Speter } while (--n != 0); 6319304Speter } 6419304Speter return (NULL); 6519304Speter} 66