xref: /freebsd/lib/libc/string/memmem.3 (revision bdb561843e865eaa5bbdc5394ed9d9c91136240c)
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.Dd June 21, 2026
28.Dt MEMMEM 3
29.Os
30.Sh NAME
31.Nm memmem
32.Nd "locate a byte subsequence in a byte sequence"
33.Sh LIBRARY
34.Lb libc
35.Sh SYNOPSIS
36.In string.h
37.Ft "QVoid *"
38.Fo memmem
39.Fa "QVoid *big" "size_t big_len"
40.Fa "const void *little" "size_t little_len"
41.Fc
42.Sh DESCRIPTION
43The
44.Fn memmem
45function
46locates the first occurrence of the byte sequence
47.Fa little
48in the byte sequence
49.Fa big .
50.Sh RETURN VALUES
51If
52.Fa little_len
53is zero
54.Fa big
55is returned (that is, an empty little is deemed to match at the beginning of
56big);
57if
58.Fa little
59occurs nowhere in
60.Fa big ,
61.Dv NULL
62is returned;
63otherwise a pointer to the first character of the first occurrence of
64.Fa little
65is returned.
66.Sh SEE ALSO
67.Xr memchr 3 ,
68.Xr strchr 3 ,
69.Xr strstr 3
70.Sh STANDARDS
71.Fn memmem
72conforms to
73.St -p1003.1-2024 .
74Like the qualifier-preserving functions in
75.St -isoC-2023 ,
76.Fx implements
77.Fn memmem
78as qualifier-preserving as well.
79.Sh HISTORY
80The
81.Fn memmem
82function first appeared in
83.Fx 6.0 .
84It was replaced with an optimized O(n) implementation from the musl libc
85project in
86.Fx 12.0 .
87.An Pascal Gloor Aq Mt pascal.gloor@spale.com
88provided this man page along with the previous implementation.
89.Sh BUGS
90This function was broken in Linux libc up to and including version 5.0.9
91and in GNU libc prior to version 2.1.
92Prior to
93.Fx 11.0
94.Nm
95returned
96.Dv NULL
97when
98.Fa little_len
99equals 0.
100