Next: memmove, Previous: memcpy, Up: Strings

### 5.9 `memmem`—find memory segment

Synopsis

         #include <string.h>
         char *memmem(const void *s1, size_t l1, const void *s2,
             size_t l2);

Description

Locates the first occurrence in the memory region pointed to by s1 with length l1 of the sequence of bytes pointed to by s2 of length l2. If you already know the lengths of your haystack and needle, `memmem` can be much faster than `strstr`.

Returns
Returns a pointer to the located segment, or a null pointer if s2 is not found. If l2 is 0, s1 is returned.

Portability
`memmem` is a newlib extension.

`memmem` requires no supporting OS subroutines.