xref: /freebsd/lib/libc/string/strchr.c (revision 46632c18bda3890a493e0a3f43907c5c75bf93eb)
1*46632c18SEd Schouten /*-
2*46632c18SEd Schouten  * Copyright (c) 1990, 1993
3*46632c18SEd Schouten  *	The Regents of the University of California.  All rights reserved.
4*46632c18SEd Schouten  *
5*46632c18SEd Schouten  * Redistribution and use in source and binary forms, with or without
6*46632c18SEd Schouten  * modification, are permitted provided that the following conditions
7*46632c18SEd Schouten  * are met:
8*46632c18SEd Schouten  * 1. Redistributions of source code must retain the above copyright
9*46632c18SEd Schouten  *    notice, this list of conditions and the following disclaimer.
10*46632c18SEd Schouten  * 2. Redistributions in binary form must reproduce the above copyright
11*46632c18SEd Schouten  *    notice, this list of conditions and the following disclaimer in the
12*46632c18SEd Schouten  *    documentation and/or other materials provided with the distribution.
13*46632c18SEd Schouten  * 4. Neither the name of the University nor the names of its contributors
14*46632c18SEd Schouten  *    may be used to endorse or promote products derived from this software
15*46632c18SEd Schouten  *    without specific prior written permission.
16*46632c18SEd Schouten  *
17*46632c18SEd Schouten  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*46632c18SEd Schouten  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*46632c18SEd Schouten  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*46632c18SEd Schouten  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*46632c18SEd Schouten  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*46632c18SEd Schouten  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*46632c18SEd Schouten  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*46632c18SEd Schouten  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*46632c18SEd Schouten  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*46632c18SEd Schouten  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*46632c18SEd Schouten  * SUCH DAMAGE.
28*46632c18SEd Schouten  */
29*46632c18SEd Schouten 
30*46632c18SEd Schouten #if defined(LIBC_SCCS) && !defined(lint)
31*46632c18SEd Schouten static char sccsid[] = "@(#)index.c	8.1 (Berkeley) 6/4/93";
32*46632c18SEd Schouten #endif /* LIBC_SCCS and not lint */
33333fc21eSDavid E. O'Brien #include <sys/cdefs.h>
34333fc21eSDavid E. O'Brien __FBSDID("$FreeBSD$");
35333fc21eSDavid E. O'Brien 
36*46632c18SEd Schouten #include <stddef.h>
37*46632c18SEd Schouten #include <string.h>
38*46632c18SEd Schouten 
39*46632c18SEd Schouten char *
40*46632c18SEd Schouten strchr(const char *p, int ch)
41*46632c18SEd Schouten {
42*46632c18SEd Schouten 	char c;
43*46632c18SEd Schouten 
44*46632c18SEd Schouten 	c = ch;
45*46632c18SEd Schouten 	for (;; ++p) {
46*46632c18SEd Schouten 		if (*p == c)
47*46632c18SEd Schouten 			return ((char *)p);
48*46632c18SEd Schouten 		if (*p == '\0')
49*46632c18SEd Schouten 			return (NULL);
50*46632c18SEd Schouten 	}
51*46632c18SEd Schouten 	/* NOTREACHED */
52*46632c18SEd Schouten }
53*46632c18SEd Schouten 
54*46632c18SEd Schouten __strong_reference(strchr, index);
55