xref: /freebsd/lib/libc/string/memmem.3 (revision 535af610)
1.\" Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\" 3. The name of the author may not be used to endorse or promote
12.\"    products derived from this software without specific prior written
13.\"    permission.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.\" $FreeBSD$
28.\"
29.Dd June 29, 2023
30.Dt MEMMEM 3
31.Os
32.Sh NAME
33.Nm memmem
34.Nd "locate a byte substring in a byte string"
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In string.h
39.Ft "void *"
40.Fo memmem
41.Fa "const void *big" "size_t big_len"
42.Fa "const void *little" "size_t little_len"
43.Fc
44.Sh DESCRIPTION
45The
46.Fn memmem
47function
48locates the first occurrence of the byte string
49.Fa little
50in the byte string
51.Fa big .
52.Sh RETURN VALUES
53If
54.Fa little_len
55is zero
56.Fa big
57is returned (that is, an empty little is deemed to match at the beginning of
58big);
59if
60.Fa little
61occurs nowhere in
62.Fa big ,
63.Dv NULL
64is returned;
65otherwise a pointer to the first character of the first occurrence of
66.Fa little
67is returned.
68.Sh SEE ALSO
69.Xr memchr 3 ,
70.Xr strchr 3 ,
71.Xr strstr 3
72.Sh CONFORMING TO
73.Fn memmem
74started as a GNU extension but is now available in at least
75the GNU, musl, bionic, OpenBSD, NetBSD, macOS, and illumos C runtime libraries.
76.Sh HISTORY
77The
78.Fn memmem
79function first appeared in
80.Fx 6.0 .
81It was replaced with an optimized O(n) implementation from the musl libc
82project in
83.Fx 12.0 .
84.An Pascal Gloor Aq Mt pascal.gloor@spale.com
85provided this man page along with the previous implementation.
86.Sh BUGS
87This function was broken in Linux libc up to and including version 5.0.9
88and in GNU libc prior to version 2.1.
89Prior to
90.Fx 11.0
91.Nm
92returned
93.Dv NULL
94when
95.Fa little_len
96equals 0.
97