xref: /freebsd/lib/libc/string/strstr.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
141036d78SMike Barcroft.\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
258f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993
358f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
458f0484fSRodney W. Grimes.\"
558f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
658f0484fSRodney W. Grimes.\" Chris Torek and the American National Standards Committee X3,
758f0484fSRodney W. Grimes.\" on Information Processing Systems.
858f0484fSRodney W. Grimes.\"
958f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
1058f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
1158f0484fSRodney W. Grimes.\" are met:
1258f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1358f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1458f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1558f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1658f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
173fb3b97cSEd Maste.\" 3. Neither the name of the University nor the names of its contributors
1858f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1958f0484fSRodney W. Grimes.\"    without specific prior written permission.
2058f0484fSRodney W. Grimes.\"
2158f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2258f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2358f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2458f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2558f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2658f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2758f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2858f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2958f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3058f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3158f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3258f0484fSRodney W. Grimes.\"
33a9227c40SMike Barcroft.Dd October 11, 2001
3458f0484fSRodney W. Grimes.Dt STRSTR 3
3558f0484fSRodney W. Grimes.Os
3658f0484fSRodney W. Grimes.Sh NAME
3789503316SAndrey A. Chernov.Nm strstr , strcasestr , strnstr
3858f0484fSRodney W. Grimes.Nd locate a substring in a string
3925bb73e0SAlexey Zelkin.Sh LIBRARY
4025bb73e0SAlexey Zelkin.Lb libc
4158f0484fSRodney W. Grimes.Sh SYNOPSIS
4232eef9aeSRuslan Ermilov.In string.h
4358f0484fSRodney W. Grimes.Ft char *
4458f0484fSRodney W. Grimes.Fn strstr "const char *big" "const char *little"
4541036d78SMike Barcroft.Ft char *
4689503316SAndrey A. Chernov.Fn strcasestr "const char *big" "const char *little"
4789503316SAndrey A. Chernov.Ft char *
4841036d78SMike Barcroft.Fn strnstr "const char *big" "const char *little" "size_t len"
49db356f03SIsabell Long.In string.h
50db356f03SIsabell Long.In xlocale.h
51db356f03SIsabell Long.Ft char *
52db356f03SIsabell Long.Fn strcasestr_l "const char *big" "const char *little" "locale_t loc"
5358f0484fSRodney W. Grimes.Sh DESCRIPTION
5458f0484fSRodney W. GrimesThe
5558f0484fSRodney W. Grimes.Fn strstr
5658f0484fSRodney W. Grimesfunction
5758f0484fSRodney W. Grimeslocates the first occurrence of the null-terminated string
5858f0484fSRodney W. Grimes.Fa little
5958f0484fSRodney W. Grimesin the null-terminated string
6058f0484fSRodney W. Grimes.Fa big .
6141036d78SMike Barcroft.Pp
6241036d78SMike BarcroftThe
6389503316SAndrey A. Chernov.Fn strcasestr
6489503316SAndrey A. Chernovfunction is similar to
65a9227c40SMike Barcroft.Fn strstr ,
6689503316SAndrey A. Chernovbut ignores the case of both strings.
6789503316SAndrey A. Chernov.Pp
6889503316SAndrey A. ChernovThe
69db356f03SIsabell Long.Fn strcasestr_l
70db356f03SIsabell Longfunction does the same as
71db356f03SIsabell Long.Fn strcasestr
72db356f03SIsabell Longbut takes an explicit locale rather than using the current locale.
73db356f03SIsabell Long.Pp
74db356f03SIsabell LongThe
7541036d78SMike Barcroft.Fn strnstr
7641036d78SMike Barcroftfunction
7741036d78SMike Barcroftlocates the first occurrence of the null-terminated string
7841036d78SMike Barcroft.Fa little
7941036d78SMike Barcroftin the string
8041036d78SMike Barcroft.Fa big ,
81a9227c40SMike Barcroftwhere not more than
82a9227c40SMike Barcroft.Fa len
83a9227c40SMike Barcroftcharacters are searched.
84a9227c40SMike BarcroftCharacters that appear after a
85a9227c40SMike Barcroft.Ql \e0
86a9227c40SMike Barcroftcharacter are not searched.
877ec7a350SMike BarcroftSince the
887ec7a350SMike Barcroft.Fn strnstr
897ec7a350SMike Barcroftfunction is a
907ec7a350SMike Barcroft.Fx
911ddfc2e3SRuslan Ermilovspecific API, it should only be used when portability is not a concern.
9241036d78SMike Barcroft.Sh RETURN VALUES
9358f0484fSRodney W. GrimesIf
9458f0484fSRodney W. Grimes.Fa little
9541036d78SMike Barcroftis an empty string,
9641036d78SMike Barcroft.Fa big
9741036d78SMike Barcroftis returned;
9858f0484fSRodney W. Grimesif
9958f0484fSRodney W. Grimes.Fa little
10058f0484fSRodney W. Grimesoccurs nowhere in
10158f0484fSRodney W. Grimes.Fa big ,
1021ddfc2e3SRuslan Ermilov.Dv NULL
1031ddfc2e3SRuslan Ermilovis returned;
10441036d78SMike Barcroftotherwise a pointer to the first character of the first occurrence of
10541036d78SMike Barcroft.Fa little
10641036d78SMike Barcroftis returned.
10741036d78SMike Barcroft.Sh EXAMPLES
10841036d78SMike BarcroftThe following sets the pointer
10941036d78SMike Barcroft.Va ptr
11041036d78SMike Barcroftto the
1111ddfc2e3SRuslan Ermilov.Qq Li Bar Baz
11241036d78SMike Barcroftportion of
11341036d78SMike Barcroft.Va largestring :
11441036d78SMike Barcroft.Bd -literal -offset indent
11541036d78SMike Barcroftconst char *largestring = "Foo Bar Baz";
11641036d78SMike Barcroftconst char *smallstring = "Bar";
11741036d78SMike Barcroftchar *ptr;
11841036d78SMike Barcroft
11941036d78SMike Barcroftptr = strstr(largestring, smallstring);
12041036d78SMike Barcroft.Ed
12141036d78SMike Barcroft.Pp
12241036d78SMike BarcroftThe following sets the pointer
12341036d78SMike Barcroft.Va ptr
1241ddfc2e3SRuslan Ermilovto
1251ddfc2e3SRuslan Ermilov.Dv NULL ,
1261ddfc2e3SRuslan Ermilovbecause only the first 4 characters of
12741036d78SMike Barcroft.Va largestring
12841036d78SMike Barcroftare searched:
12941036d78SMike Barcroft.Bd -literal -offset indent
13041036d78SMike Barcroftconst char *largestring = "Foo Bar Baz";
13141036d78SMike Barcroftconst char *smallstring = "Bar";
13241036d78SMike Barcroftchar *ptr;
13341036d78SMike Barcroft
13441036d78SMike Barcroftptr = strnstr(largestring, smallstring, 4);
13541036d78SMike Barcroft.Ed
13658f0484fSRodney W. Grimes.Sh SEE ALSO
13758f0484fSRodney W. Grimes.Xr memchr 3 ,
1386050c8feSAndre Oppermann.Xr memmem 3 ,
13958f0484fSRodney W. Grimes.Xr strchr 3 ,
14058f0484fSRodney W. Grimes.Xr strcspn 3 ,
14158f0484fSRodney W. Grimes.Xr strpbrk 3 ,
14258f0484fSRodney W. Grimes.Xr strrchr 3 ,
14358f0484fSRodney W. Grimes.Xr strsep 3 ,
14458f0484fSRodney W. Grimes.Xr strspn 3 ,
1455174a6a2SEdward Tomasz Napierala.Xr strtok 3 ,
1465174a6a2SEdward Tomasz Napierala.Xr wcsstr 3
14758f0484fSRodney W. Grimes.Sh STANDARDS
14858f0484fSRodney W. GrimesThe
14958f0484fSRodney W. Grimes.Fn strstr
15058f0484fSRodney W. Grimesfunction
15158f0484fSRodney W. Grimesconforms to
152588a200cSRuslan Ermilov.St -isoC .
153*4d004cccSDavid E. O'Brien.Sh HISTORY
154*4d004cccSDavid E. O'BrienThe
155*4d004cccSDavid E. O'Brien.Fn strnstr
156*4d004cccSDavid E. O'Brienfunction was introduced by
157*4d004cccSDavid E. O'Brien.Fx 4.5
158*4d004cccSDavid E. O'Brienand is non-standard.
159