]> git.saurik.com Git - apple/libc.git/blob - string/strstr.3
Libc-498.1.7.tar.gz
[apple/libc.git] / string / strstr.3
1 .\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
2 .\" Copyright (c) 1990, 1991, 1993
3 .\" The Regents of the University of California. All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Chris Torek and the American National Standards Committee X3,
7 .\" on Information Processing Systems.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed by the University of
20 .\" California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\" may be used to endorse or promote products derived from this software
23 .\" without specific prior written permission.
24 .\"
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" SUCH DAMAGE.
36 .\"
37 .\" @(#)strstr.3 8.1 (Berkeley) 6/4/93
38 .\" $FreeBSD: src/lib/libc/string/strstr.3,v 1.12 2001/11/20 14:11:07 ru Exp $
39 .\"
40 .Dd October 11, 2001
41 .Dt STRSTR 3
42 .Os
43 .Sh NAME
44 .Nm strcasestr ,
45 .Nm strcasestr_l ,
46 .Nm strnstr ,
47 .Nm strstr
48 .Nd locate a substring in a string
49 .Sh LIBRARY
50 .Lb libc
51 .Sh SYNOPSIS
52 .In string.h
53 .Ft char *
54 .Fo strcasestr
55 .Fa "const char *s1"
56 .Fa "const char *s2"
57 .Fc
58 .Ft char *
59 .Fo strnstr
60 .Fa "const char *s1"
61 .Fa "const char *s2"
62 .Fa "size_t n"
63 .Fc
64 .Ft char *
65 .Fo strstr
66 .Fa "const char *s1"
67 .Fa "const char *s2"
68 .Fc
69 .In string.h
70 .In xlocale.h
71 .Ft char *
72 .Fo strcasestr_l
73 .Fa "const char *s1"
74 .Fa "const char *s2"
75 .Fa "locale_t loc"
76 .Fc
77 .Sh DESCRIPTION
78 The
79 .Fn strstr
80 function
81 locates the first occurrence of the null-terminated string
82 .Fa s2
83 in the null-terminated string
84 .Fa s1 .
85 .Pp
86 The
87 .Fn strcasestr
88 function is similar to
89 .Fn strstr ,
90 but ignores the case of both strings.
91 .Pp
92 The
93 .Fn strnstr
94 function
95 locates the first occurrence of the null-terminated string
96 .Fa s2
97 in the string
98 .Fa s1 ,
99 where not more than
100 .Fa n
101 characters are searched.
102 Characters that appear after a
103 .Ql \e0
104 character are not searched.
105 Since the
106 .Fn strnstr
107 function is a
108 .Fx
109 specific API, it should only be used when portability is not a concern.
110 .Pp
111 While the
112 .Fn strcasestr
113 function uses the current locale, the
114 .Fn strcasestr_l
115 function may be passed a locale directly. See
116 .Xr xlocale 3
117 for more information.
118 .Sh RETURN VALUES
119 If
120 .Fa s2
121 is an empty string,
122 .Fa s1
123 is returned;
124 if
125 .Fa s2
126 occurs nowhere in
127 .Fa s1 ,
128 .Dv NULL
129 is returned;
130 otherwise a pointer to the first character of the first occurrence of
131 .Fa s2
132 is returned.
133 .Sh EXAMPLES
134 The following sets the pointer
135 .Va ptr
136 to the
137 .Qq Li Bar Baz
138 portion of
139 .Va largestring :
140 .Bd -literal -offset indent
141 const char *largestring = "Foo Bar Baz";
142 const char *smallstring = "Bar";
143 char *ptr;
144
145 ptr = strstr(largestring, smallstring);
146 .Ed
147 .Pp
148 The following sets the pointer
149 .Va ptr
150 to
151 .Dv NULL ,
152 because only the first 4 characters of
153 .Va largestring
154 are searched:
155 .Bd -literal -offset indent
156 const char *largestring = "Foo Bar Baz";
157 const char *smallstring = "Bar";
158 char *ptr;
159
160 ptr = strnstr(largestring, smallstring, 4);
161 .Ed
162 .Sh SEE ALSO
163 .Xr memchr 3 ,
164 .Xr strchr 3 ,
165 .Xr strcspn 3 ,
166 .Xr strpbrk 3 ,
167 .Xr strrchr 3 ,
168 .Xr strsep 3 ,
169 .Xr strspn 3 ,
170 .Xr strtok 3 ,
171 .Xr xlocale 3
172 .Sh STANDARDS
173 The
174 .Fn strstr
175 function
176 conforms to
177 .St -isoC .