]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/memmem.3
memmem.3: Add list of known systems where this is available
[thirdparty/man-pages.git] / man3 / memmem.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" References consulted:
6.\" Linux libc source code
7.\" 386BSD man pages
8.\" Modified Sat Jul 24 18:50:48 1993 by Rik Faith (faith@cs.unc.edu)
2b0fa182 9.\" Interchanged 'needle' and 'haystack'; added history, aeb, 980113.
4c1c5274 10.TH memmem 3 (date) "Linux man-pages (unreleased)"
fea681da
MK
11.SH NAME
12memmem \- locate a substring
9ec042f6
AC
13.SH LIBRARY
14Standard C library
8fc3b2cf 15.RI ( libc ", " \-lc )
fea681da
MK
16.SH SYNOPSIS
17.nf
b80f966b 18.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
fea681da 19.B #include <string.h>
68e4db0a 20.PP
c64cd13e
AC
21.BI "void *memmem(const void " haystack [. haystacklen "], size_t " haystacklen ,
22.BI " const void " needle [. needlelen "], size_t " needlelen );
fea681da
MK
23.fi
24.SH DESCRIPTION
60a90ecd
MK
25The
26.BR memmem ()
27function finds the start of the first occurrence
c6fa0841 28of the substring
1ae6b2c7 29.I needle
c6fa0841
MK
30of length
31.I needlelen
32in the memory
33area
34.I haystack
35of length
36.IR haystacklen .
47297adb 37.SH RETURN VALUE
60a90ecd
MK
38The
39.BR memmem ()
40function returns a pointer to the beginning of the
fea681da 41substring, or NULL if the substring is not found.
34a07418 42.SH ATTRIBUTES
346143cd
PH
43For an explanation of the terms used in this section, see
44.BR attributes (7).
c466875e
MK
45.ad l
46.nh
346143cd
PH
47.TS
48allbox;
c466875e 49lbx lb lb
346143cd
PH
50l l l.
51Interface Attribute Value
52T{
34a07418 53.BR memmem ()
346143cd
PH
54T} Thread safety MT-Safe
55.TE
c466875e
MK
56.hy
57.ad
58.sp 1
3113c7f3 59.SH STANDARDS
1b238553 60This function is not specified in POSIX.1,
c39de556
AC
61but is present on a number of other systems,
62including:
63musl libc 0.9.7;
64FreeBSD 6.0, OpenBSD 5.4, NetBSD, and Illumos.
fea681da 65.SH BUGS
b5a620f8
MK
66.\" This function was broken in Linux libraries up to and including libc 5.0.9;
67.\" there the
68.\" .IR needle
69.\" and
70.\" .I haystack
71.\" arguments were interchanged,
72.\" and a pointer to the end of the first occurrence of
73.\" .I needle
74.\" was returned.
ef4f4031 75.\"
b5a620f8
MK
76.\" Both old and new libc's have the bug that if
77.\" .I needle
78.\" is empty,
79.\" .I haystack\-1
80.\" (instead of
81.\" .IR haystack )
82.\" is returned.
6e76df0d
MK
83In glibc 2.0, if
84.I needle
85is empty,
86.BR memmem ()
87returns a pointer to the last byte of
c6fa0841 88.IR haystack .
ca7b3c18 89This is fixed in glibc 2.1.
47297adb 90.SH SEE ALSO
879091c9 91.BR bstring (3),
0a4f8b7b 92.BR strstr (3)