xref: /openbsd-src/share/man/man9/strnstr.9 (revision e86eac0aa26ae70ca99c10330901a05f18155e9a)
1*e86eac0aSjsg.\"	$OpenBSD: strnstr.9,v 1.1 2023/12/21 02:57:14 jsg Exp $
2*e86eac0aSjsg.\"
3*e86eac0aSjsg.\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
4*e86eac0aSjsg.\" Copyright (c) 1990, 1991, 1993
5*e86eac0aSjsg.\"	The Regents of the University of California.  All rights reserved.
6*e86eac0aSjsg.\"
7*e86eac0aSjsg.\" This code is derived from software contributed to Berkeley by
8*e86eac0aSjsg.\" Chris Torek and the American National Standards Committee X3,
9*e86eac0aSjsg.\" on Information Processing Systems.
10*e86eac0aSjsg.\"
11*e86eac0aSjsg.\" Redistribution and use in source and binary forms, with or without
12*e86eac0aSjsg.\" modification, are permitted provided that the following conditions
13*e86eac0aSjsg.\" are met:
14*e86eac0aSjsg.\" 1. Redistributions of source code must retain the above copyright
15*e86eac0aSjsg.\"    notice, this list of conditions and the following disclaimer.
16*e86eac0aSjsg.\" 2. Redistributions in binary form must reproduce the above copyright
17*e86eac0aSjsg.\"    notice, this list of conditions and the following disclaimer in the
18*e86eac0aSjsg.\"    documentation and/or other materials provided with the distribution.
19*e86eac0aSjsg.\" 3. Neither the name of the University nor the names of its contributors
20*e86eac0aSjsg.\"    may be used to endorse or promote products derived from this software
21*e86eac0aSjsg.\"    without specific prior written permission.
22*e86eac0aSjsg.\"
23*e86eac0aSjsg.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24*e86eac0aSjsg.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*e86eac0aSjsg.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26*e86eac0aSjsg.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27*e86eac0aSjsg.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28*e86eac0aSjsg.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29*e86eac0aSjsg.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30*e86eac0aSjsg.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31*e86eac0aSjsg.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32*e86eac0aSjsg.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*e86eac0aSjsg.\" SUCH DAMAGE.
34*e86eac0aSjsg.\"
35*e86eac0aSjsg.Dd $Mdocdate: December 21 2023 $
36*e86eac0aSjsg.Dt STRNSTR 9
37*e86eac0aSjsg.Os
38*e86eac0aSjsg.Sh NAME
39*e86eac0aSjsg.Nm strnstr
40*e86eac0aSjsg.Nd locate a substring in a string
41*e86eac0aSjsg.Sh SYNOPSIS
42*e86eac0aSjsg.In lib/libkern/libkern.h
43*e86eac0aSjsg.Ft char *
44*e86eac0aSjsg.Fn strnstr "const char *big" "const char *little" "size_t len"
45*e86eac0aSjsg.Sh DESCRIPTION
46*e86eac0aSjsgThe
47*e86eac0aSjsg.Fn strnstr
48*e86eac0aSjsgfunction
49*e86eac0aSjsglocates the first occurrence of the null-terminated string
50*e86eac0aSjsg.Fa little
51*e86eac0aSjsgin the string
52*e86eac0aSjsg.Fa big ,
53*e86eac0aSjsgwhere not more than
54*e86eac0aSjsg.Fa len
55*e86eac0aSjsgcharacters are searched.
56*e86eac0aSjsgCharacters that appear after a
57*e86eac0aSjsg.Ql \e0
58*e86eac0aSjsgcharacter are not searched.
59*e86eac0aSjsg.Sh RETURN VALUES
60*e86eac0aSjsgIf
61*e86eac0aSjsg.Fa little
62*e86eac0aSjsgis an empty string,
63*e86eac0aSjsg.Fa big
64*e86eac0aSjsgis returned;
65*e86eac0aSjsgif
66*e86eac0aSjsg.Fa little
67*e86eac0aSjsgoccurs nowhere in
68*e86eac0aSjsg.Fa big ,
69*e86eac0aSjsg.Dv NULL
70*e86eac0aSjsgis returned;
71*e86eac0aSjsgotherwise a pointer to the first character of the first occurrence of
72*e86eac0aSjsg.Fa little
73*e86eac0aSjsgis returned.
74*e86eac0aSjsg.Sh EXAMPLES
75*e86eac0aSjsgThe following sets the pointer
76*e86eac0aSjsg.Va ptr
77*e86eac0aSjsgto
78*e86eac0aSjsg.Dv NULL ,
79*e86eac0aSjsgbecause only the first 4 characters of
80*e86eac0aSjsg.Va largestring
81*e86eac0aSjsgare searched:
82*e86eac0aSjsg.Bd -literal -offset indent
83*e86eac0aSjsgconst char *largestring = "Foo Bar Baz";
84*e86eac0aSjsgconst char *smallstring = "Bar";
85*e86eac0aSjsgchar *ptr;
86*e86eac0aSjsg
87*e86eac0aSjsgptr = strnstr(largestring, smallstring, 4);
88*e86eac0aSjsg.Ed
89*e86eac0aSjsg.Sh SEE ALSO
90*e86eac0aSjsg.Xr memchr 9
91