xref: /freebsd/lib/libc/string/strchr.3 (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd February 13, 2013
33.Dt STRCHR 3
34.Os
35.Sh NAME
36.Nm strchr , strrchr , strchrnul
37.Nd locate character in string
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In string.h
42.Ft "char *"
43.Fn strchr "const char *s" "int c"
44.Ft "char *"
45.Fn strrchr "const char *s" "int c"
46.Ft "char *"
47.Fn strchrnul "const char *s" "int c"
48.Sh DESCRIPTION
49The
50.Fn strchr
51function locates the first occurrence of
52.Fa c
53(converted to a
54.Vt char )
55in the string pointed to by
56.Fa s .
57The terminating null character is considered part of the string;
58therefore if
59.Fa c
60is
61.Ql \e0 ,
62the functions locate the terminating
63.Ql \e0 .
64.Pp
65The
66.Fn strrchr
67function is identical to
68.Fn strchr
69except it locates the last occurrence of
70.Fa c .
71.Pp
72The
73.Fn strchrnul
74function is identical to
75.Fn strchr
76except that if
77.Fa c
78is not found in
79.Fa s
80a pointer to the terminating
81.Ql \e0
82is returned.
83.Sh RETURN VALUES
84The functions
85.Fn strchr
86and
87.Fn strrchr
88return a pointer to the located character, or
89.Dv NULL
90if the character does not appear in the string.
91.Pp
92.Fn strchrnul
93returns a pointer to the terminating
94.Ql \e0
95if the character does not appear in the string.
96.Sh SEE ALSO
97.Xr memchr 3 ,
98.Xr memmem 3 ,
99.Xr strcspn 3 ,
100.Xr strpbrk 3 ,
101.Xr strsep 3 ,
102.Xr strspn 3 ,
103.Xr strstr 3 ,
104.Xr strtok 3 ,
105.Xr wcschr 3
106.Sh STANDARDS
107The functions
108.Fn strchr
109and
110.Fn strrchr
111conform to
112.St -isoC .
113The function
114.Fn strchrnul
115is a
116.Tn GNU
117extension.
118.Sh HISTORY
119The
120.Fn strchrnul
121function first appeared in glibc 2.1.1 and was added in
122.Fx 10.0 .
123