xref: /freebsd/lib/libc/string/memmem.3 (revision dfa0ac74c2fbc1cde3e8cdb1ab9fe5cbb90a9b16)
16050c8feSAndre Oppermann.\" Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
26050c8feSAndre Oppermann.\"
36050c8feSAndre Oppermann.\" Redistribution and use in source and binary forms, with or without
46050c8feSAndre Oppermann.\" modification, are permitted provided that the following conditions
56050c8feSAndre Oppermann.\" are met:
66050c8feSAndre Oppermann.\" 1. Redistributions of source code must retain the above copyright
76050c8feSAndre Oppermann.\"    notice, this list of conditions and the following disclaimer.
86050c8feSAndre Oppermann.\" 2. Redistributions in binary form must reproduce the above copyright
96050c8feSAndre Oppermann.\"    notice, this list of conditions and the following disclaimer in the
106050c8feSAndre Oppermann.\"    documentation and/or other materials provided with the distribution.
116050c8feSAndre Oppermann.\" 3. The name of the author may not be used to endorse or promote
126050c8feSAndre Oppermann.\"    products derived from this software without specific prior written
136050c8feSAndre Oppermann.\"    permission.
146050c8feSAndre Oppermann.\"
156050c8feSAndre Oppermann.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
166050c8feSAndre Oppermann.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
176050c8feSAndre Oppermann.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
186050c8feSAndre Oppermann.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
196050c8feSAndre Oppermann.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
206050c8feSAndre Oppermann.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
216050c8feSAndre Oppermann.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
226050c8feSAndre Oppermann.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
236050c8feSAndre Oppermann.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
246050c8feSAndre Oppermann.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
256050c8feSAndre Oppermann.\" SUCH DAMAGE.
266050c8feSAndre Oppermann.\"
2724ec316cSYuri Pankov.Dd June 29, 2023
286050c8feSAndre Oppermann.Dt MEMMEM 3
296050c8feSAndre Oppermann.Os
306050c8feSAndre Oppermann.Sh NAME
316050c8feSAndre Oppermann.Nm memmem
32ca513774SRuslan Ermilov.Nd "locate a byte substring in a byte string"
336050c8feSAndre Oppermann.Sh LIBRARY
346050c8feSAndre Oppermann.Lb libc
356050c8feSAndre Oppermann.Sh SYNOPSIS
366050c8feSAndre Oppermann.In string.h
37ca513774SRuslan Ermilov.Ft "void *"
38ca513774SRuslan Ermilov.Fo memmem
3936c71f6aSRuslan Ermilov.Fa "const void *big" "size_t big_len"
4036c71f6aSRuslan Ermilov.Fa "const void *little" "size_t little_len"
41ca513774SRuslan Ermilov.Fc
426050c8feSAndre Oppermann.Sh DESCRIPTION
436050c8feSAndre OppermannThe
446050c8feSAndre Oppermann.Fn memmem
456050c8feSAndre Oppermannfunction
466050c8feSAndre Oppermannlocates the first occurrence of the byte string
476050c8feSAndre Oppermann.Fa little
486050c8feSAndre Oppermannin the byte string
496050c8feSAndre Oppermann.Fa big .
506050c8feSAndre Oppermann.Sh RETURN VALUES
516050c8feSAndre OppermannIf
526050c8feSAndre Oppermann.Fa little_len
5316150352SEd Masteis zero
5416150352SEd Maste.Fa big
5516150352SEd Masteis returned (that is, an empty little is deemed to match at the beginning of
5616150352SEd Mastebig);
5716150352SEd Masteif
586050c8feSAndre Oppermann.Fa little
596050c8feSAndre Oppermannoccurs nowhere in
606050c8feSAndre Oppermann.Fa big ,
616050c8feSAndre Oppermann.Dv NULL
626050c8feSAndre Oppermannis returned;
636050c8feSAndre Oppermannotherwise a pointer to the first character of the first occurrence of
646050c8feSAndre Oppermann.Fa little
656050c8feSAndre Oppermannis returned.
666050c8feSAndre Oppermann.Sh SEE ALSO
676050c8feSAndre Oppermann.Xr memchr 3 ,
686050c8feSAndre Oppermann.Xr strchr 3 ,
696050c8feSAndre Oppermann.Xr strstr 3
70*dfa0ac74SEd Maste.Sh STANDARDS
716050c8feSAndre Oppermann.Fn memmem
72*dfa0ac74SEd Masteconforms to
73*dfa0ac74SEd Maste.St -p1003.1-2024 .
746050c8feSAndre Oppermann.Sh HISTORY
756050c8feSAndre OppermannThe
766050c8feSAndre Oppermann.Fn memmem
776050c8feSAndre Oppermannfunction first appeared in
786050c8feSAndre Oppermann.Fx 6.0 .
7988521634SEd MasteIt was replaced with an optimized O(n) implementation from the musl libc
8088521634SEd Masteproject in
8188521634SEd Maste.Fx 12.0 .
828fbf3d50SBaptiste Daroussin.An Pascal Gloor Aq Mt pascal.gloor@spale.com
8388521634SEd Masteprovided this man page along with the previous implementation.
846050c8feSAndre Oppermann.Sh BUGS
856050c8feSAndre OppermannThis function was broken in Linux libc up to and including version 5.0.9
866050c8feSAndre Oppermannand in GNU libc prior to version 2.1.
8716150352SEd MastePrior to
8816150352SEd Maste.Fx 11.0
8916150352SEd Maste.Nm
9016150352SEd Mastereturned
9116150352SEd Maste.Dv NULL
9216150352SEd Mastewhen
9316150352SEd Maste.Fa little_len
9416150352SEd Masteequals 0.
95