malloc.3: ffix
[man-pages.git] / man3 / strchr.3
blob4bd0be8ecaab6f98bba057774de6131f73b89b53
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Mon Apr 12 12:51:24 1993, David Metcalfe
30 .\" 2006-05-19, Justin Pryzby <pryzbyj@justinpryzby.com>
31 .\"     Document strchrnul(3).
32 .\"
33 .TH STRCHR 3  2021-03-22 "GNU" "Linux Programmer's Manual"
34 .SH NAME
35 strchr, strrchr, strchrnul \- locate character in string
36 .SH SYNOPSIS
37 .nf
38 .B #include <string.h>
39 .PP
40 .BI "char *strchr(const char *" s ", int " c );
41 .BI "char *strrchr(const char *" s ", int " c );
42 .PP
43 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
44 .B #include <string.h>
45 .PP
46 .BI "char *strchrnul(const char *" s ", int " c );
47 .fi
48 .SH DESCRIPTION
49 The
50 .BR strchr ()
51 function returns a pointer to the first occurrence
52 of the character
53 .I c
54 in the string
55 .IR s .
56 .PP
57 The
58 .BR strrchr ()
59 function returns a pointer to the last occurrence
60 of the character
61 .I c
62 in the string
63 .IR s .
64 .PP
65 The
66 .BR strchrnul ()
67 function is like
68 .BR strchr ()
69 except that if
70 .I c
71 is not found in
72 .IR s ,
73 then it returns a pointer to the null byte
74 at the end of
75 .IR s ,
76 rather than NULL.
77 .PP
78 Here "character" means "byte"; these functions do not work with
79 wide or multibyte characters.
80 .SH RETURN VALUE
81 The
82 .BR strchr ()
83 and
84 .BR strrchr ()
85 functions return a pointer to
86 the matched character or NULL if the character is not found.
87 The terminating null byte is considered part of the string,
88 so that if
89 .I c
90 is specified as \(aq\e0\(aq,
91 these functions return a pointer to the terminator.
92 .PP
93 The
94 .BR strchrnul ()
95 function returns a pointer to the matched character,
96 or a pointer to the null byte at the end of
97 .I s
98 (i.e.,
99 .IR "s+strlen(s)" )
100 if the character is not found.
101 .SH VERSIONS
102 .BR strchrnul ()
103 first appeared in glibc in version 2.1.1.
104 .SH ATTRIBUTES
105 For an explanation of the terms used in this section, see
106 .BR attributes (7).
107 .ad l
110 allbox;
111 lbx lb lb
112 l l l.
113 Interface       Attribute       Value
115 .BR strchr (),
116 .BR strrchr (),
117 .BR strchrnul ()
118 T}      Thread safety   MT-Safe
122 .sp 1
123 .SH CONFORMING TO
124 .BR strchr (),
125 .BR strrchr ():
126 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
128 .BR strchrnul ()
129 is a GNU extension.
130 .SH SEE ALSO
131 .BR index (3),
132 .BR memchr (3),
133 .BR rindex (3),
134 .BR string (3),
135 .BR strlen (3),
136 .BR strpbrk (3),
137 .BR strsep (3),
138 .BR strspn (3),
139 .BR strstr (3),
140 .BR strtok (3),
141 .BR wcschr (3),
142 .BR wcsrchr (3)