xref: /openbsd-src/lib/libc/string/strchr.c (revision 132394c01e18b19a7e7495ae67acb64f9c600cad)
1*132394c0Smartijn /*	$OpenBSD: strchr.c,v 1.4 2018/10/01 06:37:37 martijn Exp $ */
25b859c19Sderaadt /*-
35b859c19Sderaadt  * Copyright (c) 1990 The Regents of the University of California.
45b859c19Sderaadt  * All rights reserved.
55b859c19Sderaadt  *
65b859c19Sderaadt  * Redistribution and use in source and binary forms, with or without
75b859c19Sderaadt  * modification, are permitted provided that the following conditions
85b859c19Sderaadt  * are met:
95b859c19Sderaadt  * 1. Redistributions of source code must retain the above copyright
105b859c19Sderaadt  *    notice, this list of conditions and the following disclaimer.
115b859c19Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
125b859c19Sderaadt  *    notice, this list of conditions and the following disclaimer in the
135b859c19Sderaadt  *    documentation and/or other materials provided with the distribution.
145b859c19Sderaadt  * 3. Neither the name of the University nor the names of its contributors
155b859c19Sderaadt  *    may be used to endorse or promote products derived from this software
165b859c19Sderaadt  *    without specific prior written permission.
175b859c19Sderaadt  *
185b859c19Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
195b859c19Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
205b859c19Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
215b859c19Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
225b859c19Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
235b859c19Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
245b859c19Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
255b859c19Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
265b859c19Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
275b859c19Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
285b859c19Sderaadt  * SUCH DAMAGE.
295b859c19Sderaadt  */
305b859c19Sderaadt 
315b859c19Sderaadt #include <string.h>
325b859c19Sderaadt 
33cb39b413Smillert __weak_alias(index, strchr);
34cb39b413Smillert 
355b859c19Sderaadt char *
strchr(const char * p,int ch)365b859c19Sderaadt strchr(const char *p, int ch)
375b859c19Sderaadt {
385b859c19Sderaadt 	for (;; ++p) {
39*132394c0Smartijn 		if (*p == (char) ch)
405b859c19Sderaadt 			return((char *)p);
415b859c19Sderaadt 		if (!*p)
425b859c19Sderaadt 			return((char *)NULL);
435b859c19Sderaadt 	}
445b859c19Sderaadt 	/* NOTREACHED */
455b859c19Sderaadt }
469b9d2a55Sguenther DEF_STRONG(strchr);
47