1MEMMEM(3) Linux Programmer's Manual MEMMEM(3)
2
3
4
6 memmem - locate a substring
7
9 #define _GNU_SOURCE
10 #include <string.h>
11
12 void *memmem(const void *haystack, size_t haystacklen,
13 const void *needle, size_t needlelen);
14
16 The memmem() function finds the start of the first occurrence of the
17 substring needle of length needlelen in the memory area haystack of
18 length haystacklen.
19
21 The memmem() function returns a pointer to the beginning of the sub‐
22 string, or NULL if the substring is not found.
23
25 This function is a GNU extension.
26
28 This function was broken in Linux libraries up to and including libc
29 5.0.9; there the needle and haystack arguments were interchanged, and a
30 pointer to the end of the first occurrence of needle was returned.
31
32 Both old and new libc's have the bug that if needle is empty,
33 haystack-1 (instead of haystack) is returned. And glibc 2.0 makes it
34 worse, returning a pointer to the last byte of haystack. This is fixed
35 in glibc 2.1.
36
38 strstr(3), feature_test_macros(7)
39
41 This page is part of release 3.22 of the Linux man-pages project. A
42 description of the project, and information about reporting bugs, can
43 be found at http://www.kernel.org/doc/man-pages/.
44
45
46
47GNU 2008-12-05 MEMMEM(3)