]>
Commit | Line | Data |
---|---|---|
6599da04 JM |
1 | /* Simple implementation of strstr for systems without it. |
2 | This function is in the public domain. */ | |
3 | ||
4 | /* | |
5 | ||
aaa5f039 | 6 | @deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub}) |
6599da04 | 7 | |
aaa5f039 | 8 | This function searches for the substring @var{sub} in the string |
e922f978 | 9 | @var{string}, not including the terminating null characters. A pointer |
7f8fa05d | 10 | to the first occurrence of @var{sub} is returned, or @code{NULL} if the |
aaa5f039 DD |
11 | substring is absent. If @var{sub} points to a string with zero |
12 | length, the function returns @var{string}. | |
6599da04 | 13 | |
aaa5f039 | 14 | @end deftypefn |
6599da04 | 15 | |
6599da04 JM |
16 | |
17 | */ | |
18 | ||
f9a9ac80 KG |
19 | #include <stddef.h> |
20 | ||
16b00dc6 | 21 | extern int memcmp (const void *, const void *, size_t); |
f9a9ac80 KG |
22 | extern size_t strlen (const char *); |
23 | ||
6599da04 | 24 | char * |
f9a9ac80 | 25 | strstr (const char *s1, const char *s2) |
6599da04 | 26 | { |
f9a9ac80 | 27 | const size_t len = strlen (s2); |
16b00dc6 | 28 | while (*s1) |
6599da04 | 29 | { |
16b00dc6 SK |
30 | if (!memcmp (s1, s2, len)) |
31 | return (char *)s1; | |
32 | ++s1; | |
6599da04 JM |
33 | } |
34 | return (0); | |
35 | } |