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. 1758f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 1858f0484fSRodney W. Grimes.\" must display the following acknowledgement: 1958f0484fSRodney W. Grimes.\" This product includes software developed by the University of 2058f0484fSRodney W. Grimes.\" California, Berkeley and its contributors. 2158f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 2258f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 2358f0484fSRodney W. Grimes.\" without specific prior written permission. 2458f0484fSRodney W. Grimes.\" 2558f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2658f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2758f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2858f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2958f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3058f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3158f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3258f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3358f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3458f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3558f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3658f0484fSRodney W. Grimes.\" 3758f0484fSRodney W. Grimes.\" @(#)strstr.3 8.1 (Berkeley) 6/4/93 387f3dea24SPeter Wemm.\" $FreeBSD$ 3958f0484fSRodney W. Grimes.\" 40a9227c40SMike Barcroft.Dd October 11, 2001 4158f0484fSRodney W. Grimes.Dt STRSTR 3 4258f0484fSRodney W. Grimes.Os 4358f0484fSRodney W. Grimes.Sh NAME 4489503316SAndrey A. Chernov.Nm strstr , strcasestr , strnstr 4558f0484fSRodney W. Grimes.Nd locate a substring in a string 4625bb73e0SAlexey Zelkin.Sh LIBRARY 4725bb73e0SAlexey Zelkin.Lb libc 4858f0484fSRodney W. Grimes.Sh SYNOPSIS 4932eef9aeSRuslan Ermilov.In string.h 5058f0484fSRodney W. Grimes.Ft char * 5158f0484fSRodney W. Grimes.Fn strstr "const char *big" "const char *little" 5241036d78SMike Barcroft.Ft char * 5389503316SAndrey A. Chernov.Fn strcasestr "const char *big" "const char *little" 5489503316SAndrey A. Chernov.Ft char * 5541036d78SMike Barcroft.Fn strnstr "const char *big" "const char *little" "size_t len" 5658f0484fSRodney W. Grimes.Sh DESCRIPTION 5758f0484fSRodney W. GrimesThe 5858f0484fSRodney W. Grimes.Fn strstr 5958f0484fSRodney W. Grimesfunction 6058f0484fSRodney W. Grimeslocates the first occurrence of the null-terminated string 6158f0484fSRodney W. Grimes.Fa little 6258f0484fSRodney W. Grimesin the null-terminated string 6358f0484fSRodney W. Grimes.Fa big . 6441036d78SMike Barcroft.Pp 6541036d78SMike BarcroftThe 6689503316SAndrey A. Chernov.Fn strcasestr 6789503316SAndrey A. Chernovfunction is similar to 68a9227c40SMike Barcroft.Fn strstr , 6989503316SAndrey A. Chernovbut ignores the case of both strings. 7089503316SAndrey A. Chernov.Pp 7189503316SAndrey A. ChernovThe 7241036d78SMike Barcroft.Fn strnstr 7341036d78SMike Barcroftfunction 7441036d78SMike Barcroftlocates the first occurrence of the null-terminated string 7541036d78SMike Barcroft.Fa little 7641036d78SMike Barcroftin the string 7741036d78SMike Barcroft.Fa big , 78a9227c40SMike Barcroftwhere not more than 79a9227c40SMike Barcroft.Fa len 80a9227c40SMike Barcroftcharacters are searched. 81a9227c40SMike BarcroftCharacters that appear after a 82a9227c40SMike Barcroft.Ql \e0 83a9227c40SMike Barcroftcharacter are not searched. 847ec7a350SMike BarcroftSince the 857ec7a350SMike Barcroft.Fn strnstr 867ec7a350SMike Barcroftfunction is a 877ec7a350SMike Barcroft.Fx 887ec7a350SMike Barcroftspecific API, it should only be used when portablility is not a concern. 8941036d78SMike Barcroft.Sh RETURN VALUES 9058f0484fSRodney W. GrimesIf 9158f0484fSRodney W. Grimes.Fa little 9241036d78SMike Barcroftis an empty string, 9341036d78SMike Barcroft.Fa big 9441036d78SMike Barcroftis returned; 9558f0484fSRodney W. Grimesif 9658f0484fSRodney W. Grimes.Fa little 9758f0484fSRodney W. Grimesoccurs nowhere in 9858f0484fSRodney W. Grimes.Fa big , 9941036d78SMike BarcroftNULL is returned; 10041036d78SMike Barcroftotherwise a pointer to the first character of the first occurrence of 10141036d78SMike Barcroft.Fa little 10241036d78SMike Barcroftis returned. 10341036d78SMike Barcroft.Sh EXAMPLES 10441036d78SMike BarcroftThe following sets the pointer 10541036d78SMike Barcroft.Va ptr 10641036d78SMike Barcroftto the 10741036d78SMike Barcroft.Dq Li Bar Baz 10841036d78SMike Barcroftportion of 10941036d78SMike Barcroft.Va largestring : 11041036d78SMike Barcroft.Bd -literal -offset indent 11141036d78SMike Barcroftconst char *largestring = "Foo Bar Baz"; 11241036d78SMike Barcroftconst char *smallstring = "Bar"; 11341036d78SMike Barcroftchar *ptr; 11441036d78SMike Barcroft 11541036d78SMike Barcroftptr = strstr(largestring, smallstring); 11641036d78SMike Barcroft.Ed 11741036d78SMike Barcroft.Pp 11841036d78SMike BarcroftThe following sets the pointer 11941036d78SMike Barcroft.Va ptr 12041036d78SMike Barcroftto NULL, because only the first 4 characters of 12141036d78SMike Barcroft.Va largestring 12241036d78SMike Barcroftare searched: 12341036d78SMike Barcroft.Bd -literal -offset indent 12441036d78SMike Barcroftconst char *largestring = "Foo Bar Baz"; 12541036d78SMike Barcroftconst char *smallstring = "Bar"; 12641036d78SMike Barcroftchar *ptr; 12741036d78SMike Barcroft 12841036d78SMike Barcroftptr = strnstr(largestring, smallstring, 4); 12941036d78SMike Barcroft.Ed 13058f0484fSRodney W. Grimes.Sh SEE ALSO 13158f0484fSRodney W. Grimes.Xr memchr 3 , 13258f0484fSRodney W. Grimes.Xr strchr 3 , 13358f0484fSRodney W. Grimes.Xr strcspn 3 , 13458f0484fSRodney W. Grimes.Xr strpbrk 3 , 13558f0484fSRodney W. Grimes.Xr strrchr 3 , 13658f0484fSRodney W. Grimes.Xr strsep 3 , 13758f0484fSRodney W. Grimes.Xr strspn 3 , 13858f0484fSRodney W. Grimes.Xr strtok 3 13958f0484fSRodney W. Grimes.Sh STANDARDS 14058f0484fSRodney W. GrimesThe 14158f0484fSRodney W. Grimes.Fn strstr 14258f0484fSRodney W. Grimesfunction 14358f0484fSRodney W. Grimesconforms to 144588a200cSRuslan Ermilov.St -isoC . 145