MEMMEM(3) Library Functions Manual MEMMEM(3)

memmemfind a byte subsequence in a byte sequence


#include <string.h>

void *memmem(const void *haystack, size_t haystacklen,
       const void *needle, size_t needlelen);

The memmem () function shall locate the first occurrence of byte sequence needle of length needlelen in byte sequence haystack of length haystacklen.

Upon successful completion, memmem () shall return a pointer to the the first byte of the located byte sequence in haystack, or a null pointer if the byte sequence is not found.

If needlelen is zero, the function shall return haystack.

If haystacklen is less than needlelen, the function shall return a null pointer.

No errors are defined.

None.

None.

This function is similar to strstr(3), except that NUL bytes may be included in either needle or haystack.

None.

memchr(3), strstr(3)

XBD <string.h>

First released in Issue 8.

June 14, 2024 posix.fail