Debian Codegraph @

upstream/debian-unstable/man3/memmem.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH memmem 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 memmem \- locate a substring
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
16 .B #include <string.h>
17 .P
18 .BR "void *memmem(" "size_t hsize, size_t nsize;"
19 .BI " const void " haystack [ hsize "], size_t " hsize ,
20 .BI " const void " needle [ nsize "], size_t " nsize );
21 .fi
22 .SH DESCRIPTION
23 The
24 .BR memmem ()
25 function finds the start of the first occurrence
26 of the substring
27 .I needle
28 of size
29 .I nsize
30 in the memory
31 area
32 .I haystack
33 of size
34 .IR hsize .
35 .SH RETURN VALUE
36 The
37 .BR memmem ()
38 function returns a pointer to the beginning of the
39 substring, or NULL if the substring is not found.
40 .SH ATTRIBUTES
41 For an explanation of the terms used in this section, see
42 .BR attributes (7).
43 .TS
44 allbox;
45 lbx lb lb
46 l l l.
47 Interface Attribute Value
48 T{
49 .na
50 .nh
51 .BR memmem ()
52 T} Thread safety MT-Safe
53 .TE
54 .SH STANDARDS
55 None.
56 .SH HISTORY
57 musl libc 0.9.7;
58 FreeBSD 6.0, OpenBSD 5.4, NetBSD, Illumos.
59 .SH BUGS
60 .\" This function was broken in Linux libraries up to and including libc 5.0.9;
61 .\" there the
62 .\" .IR needle
63 .\" and
64 .\" .I haystack
65 .\" arguments were interchanged,
66 .\" and a pointer to the end of the first occurrence of
67 .\" .I needle
68 .\" was returned.
69 .\"
70 .\" Both old and new libc's have the bug that if
71 .\" .I needle
72 .\" is empty,
73 .\" .I haystack\-1
74 .\" (instead of
75 .\" .IR haystack )
76 .\" is returned.
77 In glibc 2.0, if
78 .I needle
79 is empty,
80 .BR memmem ()
81 returns a pointer to the last byte of
82 .IR haystack .
83 This is fixed in glibc 2.1.
84 .SH SEE ALSO
85 .BR bstring (3),
86 .BR strstr (3)