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