hppa64: Fix fmt_f_default_field_width_3.f90 and fmt_g_default_field_width_3.f90
[official-gcc.git] / libiberty / strstr.c
blob49209e8229ffb44259877c446985fd73b4f58c31
1 /* Simple implementation of strstr for systems without it.
2 This function is in the public domain. */
4 /*
6 @deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
8 This function searches for the substring @var{sub} in the string
9 @var{string}, not including the terminating null characters. A pointer
10 to the first occurrence of @var{sub} is returned, or @code{NULL} if the
11 substring is absent. If @var{sub} points to a string with zero
12 length, the function returns @var{string}.
14 @end deftypefn
19 #include <stddef.h>
21 extern char *strchr (const char *, int);
22 extern int strncmp (const void *, const void *, size_t);
23 extern size_t strlen (const char *);
25 char *
26 strstr (const char *s1, const char *s2)
28 const char *p = s1;
29 const size_t len = strlen (s2);
31 if (!len)
32 return s1;
34 for (; (p = strchr (p, *s2)) != 0; p++)
36 if (strncmp (p, s2, len) == 0)
37 return (char *)p;
39 return (0);