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,
30 and a pointer to the end of the first occurrence of needle was
31 returned. Since libc 5.0.9 is still widely used, this is a dangerous
32 function to use.
33 Both old and new libc's have the bug that if needle is empty haystack-1
34 (instead of haystack) is returned. And glibc 2.0 makes it worse, and
35 returns a pointer to the last byte of `haystack'. This is fixed in
36 glibc 2.1.
37
39 strstr(3), feature_test_macros(7)
40
41
42
43GNU 1998-01-13 MEMMEM(3)