blob: ab9f53986c0194cb90d3bbb6c26398a71eebcbd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include "stddef.h" // for NULL
#include <string.h> // for memcmp, size_t, memmem
void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
{
const unsigned char *p1 = haystack;
const unsigned char *p2 = needle;
while (haystacklen >= needlelen) {
if (!memcmp(p1, p2, needlelen))
return (void *)p1;
p1++;
haystacklen--;
}
return NULL;
}
|