]> git.saurik.com Git - apple/libc.git/blame - string/strstr.3
Libc-498.1.7.tar.gz
[apple/libc.git] / string / strstr.3
CommitLineData
224c7076
A
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
78The
79.Fn strstr
80function
81locates the first occurrence of the null-terminated string
82.Fa s2
83in the null-terminated string
84.Fa s1 .
85.Pp
86The
87.Fn strcasestr
88function is similar to
89.Fn strstr ,
90but ignores the case of both strings.
91.Pp
92The
93.Fn strnstr
94function
95locates the first occurrence of the null-terminated string
96.Fa s2
97in the string
98.Fa s1 ,
99where not more than
100.Fa n
101characters are searched.
102Characters that appear after a
103.Ql \e0
104character are not searched.
105Since the
106.Fn strnstr
107function is a
108.Fx
109specific API, it should only be used when portability is not a concern.
110.Pp
111While the
112.Fn strcasestr
113function uses the current locale, the
114.Fn strcasestr_l
115function may be passed a locale directly. See
116.Xr xlocale 3
117for more information.
118.Sh RETURN VALUES
119If
120.Fa s2
121is an empty string,
122.Fa s1
123is returned;
124if
125.Fa s2
126occurs nowhere in
127.Fa s1 ,
128.Dv NULL
129is returned;
130otherwise a pointer to the first character of the first occurrence of
131.Fa s2
132is returned.
133.Sh EXAMPLES
134The following sets the pointer
135.Va ptr
136to the
137.Qq Li Bar Baz
138portion of
139.Va largestring :
140.Bd -literal -offset indent
141const char *largestring = "Foo Bar Baz";
142const char *smallstring = "Bar";
143char *ptr;
144
145ptr = strstr(largestring, smallstring);
146.Ed
147.Pp
148The following sets the pointer
149.Va ptr
150to
151.Dv NULL ,
152because only the first 4 characters of
153.Va largestring
154are searched:
155.Bd -literal -offset indent
156const char *largestring = "Foo Bar Baz";
157const char *smallstring = "Bar";
158char *ptr;
159
160ptr = 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
173The
174.Fn strstr
175function
176conforms to
177.St -isoC .