blob: 0632cc28a0f4507d01312fa22a1dabd626ea5bd6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <sys/types.h>
#include <string.h>
char *strstr(const char *haystack, const char *needle) {
size_t nl=strlen(needle);
size_t hl=strlen(haystack);
int i;
if (!nl) goto found;
if (nl>hl) return 0;
for (i=hl-nl+1; i; --i) {
if (*haystack==*needle && !memcmp(haystack,needle,nl))
found:
return (char*)haystack;
++haystack;
}
return 0;
}
|