xref: /freebsd/lib/libc/string/strchr.c (revision 8a16b7a18f5d0b031f09832fd7752fba717e2a97)
146632c18SEd Schouten /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
446632c18SEd Schouten  * Copyright (c) 1990, 1993
546632c18SEd Schouten  *	The Regents of the University of California.  All rights reserved.
646632c18SEd Schouten  *
746632c18SEd Schouten  * Redistribution and use in source and binary forms, with or without
846632c18SEd Schouten  * modification, are permitted provided that the following conditions
946632c18SEd Schouten  * are met:
1046632c18SEd Schouten  * 1. Redistributions of source code must retain the above copyright
1146632c18SEd Schouten  *    notice, this list of conditions and the following disclaimer.
1246632c18SEd Schouten  * 2. Redistributions in binary form must reproduce the above copyright
1346632c18SEd Schouten  *    notice, this list of conditions and the following disclaimer in the
1446632c18SEd Schouten  *    documentation and/or other materials provided with the distribution.
153fb3b97cSEd Maste  * 3. Neither the name of the University nor the names of its contributors
1646632c18SEd Schouten  *    may be used to endorse or promote products derived from this software
1746632c18SEd Schouten  *    without specific prior written permission.
1846632c18SEd Schouten  *
1946632c18SEd Schouten  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2046632c18SEd Schouten  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2146632c18SEd Schouten  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2246632c18SEd Schouten  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2346632c18SEd Schouten  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2446632c18SEd Schouten  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2546632c18SEd Schouten  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2646632c18SEd Schouten  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2746632c18SEd Schouten  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2846632c18SEd Schouten  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2946632c18SEd Schouten  * SUCH DAMAGE.
3046632c18SEd Schouten  */
3146632c18SEd Schouten 
3246632c18SEd Schouten #if defined(LIBC_SCCS) && !defined(lint)
3346632c18SEd Schouten static char sccsid[] = "@(#)index.c	8.1 (Berkeley) 6/4/93";
3446632c18SEd Schouten #endif /* LIBC_SCCS and not lint */
35333fc21eSDavid E. O'Brien #include <sys/cdefs.h>
36333fc21eSDavid E. O'Brien __FBSDID("$FreeBSD$");
37333fc21eSDavid E. O'Brien 
3846632c18SEd Schouten #include <stddef.h>
3946632c18SEd Schouten #include <string.h>
4046632c18SEd Schouten 
4146632c18SEd Schouten char *
4246632c18SEd Schouten strchr(const char *p, int ch)
4346632c18SEd Schouten {
4446632c18SEd Schouten 	char c;
4546632c18SEd Schouten 
4646632c18SEd Schouten 	c = ch;
4746632c18SEd Schouten 	for (;; ++p) {
4846632c18SEd Schouten 		if (*p == c)
4946632c18SEd Schouten 			return ((char *)p);
5046632c18SEd Schouten 		if (*p == '\0')
5146632c18SEd Schouten 			return (NULL);
5246632c18SEd Schouten 	}
5346632c18SEd Schouten 	/* NOTREACHED */
5446632c18SEd Schouten }
5546632c18SEd Schouten 
5619c262feSEd Schouten __weak_reference(strchr, index);
57