1208751Sraj/*- 2208751Sraj * Copyright (c) 1990, 1993 3208751Sraj * The Regents of the University of California. All rights reserved. 4208751Sraj * 5208751Sraj * This code is derived from software contributed to Berkeley by 6208751Sraj * Chris Torek. 7208751Sraj * 8208751Sraj * Redistribution and use in source and binary forms, with or without 9208751Sraj * modification, are permitted provided that the following conditions 10208751Sraj * are met: 11208751Sraj * 1. Redistributions of source code must retain the above copyright 12208751Sraj * notice, this list of conditions and the following disclaimer. 13208751Sraj * 2. Redistributions in binary form must reproduce the above copyright 14208751Sraj * notice, this list of conditions and the following disclaimer in the 15208751Sraj * documentation and/or other materials provided with the distribution. 16208751Sraj * 4. Neither the name of the University nor the names of its contributors 17208751Sraj * may be used to endorse or promote products derived from this software 18208751Sraj * without specific prior written permission. 19208751Sraj * 20208751Sraj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21208751Sraj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22208751Sraj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23208751Sraj * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24208751Sraj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25208751Sraj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26208751Sraj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27208751Sraj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28208751Sraj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29208751Sraj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30208751Sraj * SUCH DAMAGE. 31208751Sraj */ 32208751Sraj 33208751Sraj#include <sys/cdefs.h> 34208751Sraj__FBSDID("$FreeBSD$"); 35208751Sraj 36208751Sraj#include <sys/libkern.h> 37208751Sraj#include <sys/param.h> 38208751Sraj 39208751Srajvoid * 40208751Srajmemchr(const void *s, int c, size_t n) 41208751Sraj{ 42208751Sraj if (n != 0) { 43208751Sraj const unsigned char *p = s; 44208751Sraj 45208751Sraj do { 46208751Sraj if (*p++ == (unsigned char)c) 47208751Sraj return ((void *)(uintptr_t)(p - 1)); 48208751Sraj } while (--n != 0); 49208751Sraj } 50208751Sraj return (NULL); 51208751Sraj} 52