* ldlang.h (struct lang_input_statement_flags): New, extract from..
[deliverable/binutils-gdb.git] / libiberty / strstr.c
CommitLineData
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 8This function searches for the substring @var{sub} in the string
fa9f0e33 9@var{string}, not including the terminating null characters. A pointer
99b58139 10to the first occurrence of @var{sub} is returned, or @code{NULL} if the
39423523
DD
11substring is absent. If @var{sub} points to a string with zero
12length, the function returns @var{string}.
252b5132 13
39423523 14@end deftypefn
252b5132 15
252b5132
RH
16
17*/
18
19
20/* FIXME: The above description is ANSI compiliant. This routine has not
21 been validated to comply with it. -fnf */
22
aa55ccb1
DD
23#include <stddef.h>
24
25extern char *strchr (const char *, int);
26extern int strncmp (const void *, const void *, size_t);
27extern size_t strlen (const char *);
28
252b5132 29char *
aa55ccb1 30strstr (const char *s1, const char *s2)
252b5132 31{
aa55ccb1
DD
32 const char *p = s1;
33 const size_t len = strlen (s2);
252b5132
RH
34
35 for (; (p = strchr (p, *s2)) != 0; p++)
36 {
37 if (strncmp (p, s2, len) == 0)
aa55ccb1 38 return (char *)p;
252b5132
RH
39 }
40 return (0);
41}
This page took 0.48412 seconds and 4 git commands to generate.