~ubuntu-branches/ubuntu/utopic/binutils-arm64-cross/utopic

« back to all changes in this revision

Viewing changes to binutils-2.23.52.20130611/libiberty/strstr.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-06-20 17:38:09 UTC
  • Revision ID: package-import@ubuntu.com-20130620173809-app8lzgvymy5fg6c
Tags: 0.7
Build-depend on binutils-source (>= 2.23.52.20130620-1~).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Simple implementation of strstr for systems without it.
 
2
   This function is in the public domain.  */
 
3
 
 
4
/*
 
5
 
 
6
@deftypefn Supplemental char* strstr (const char *@var{string}, const char *@var{sub})
 
7
 
 
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}.
 
13
 
 
14
@end deftypefn
 
15
 
 
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
 
 
23
#include <stddef.h>
 
24
 
 
25
extern char *strchr (const char *, int);
 
26
extern int strncmp (const void *, const void *, size_t);
 
27
extern size_t strlen (const char *);
 
28
 
 
29
char *
 
30
strstr (const char *s1, const char *s2)
 
31
{
 
32
  const char *p = s1;
 
33
  const size_t len = strlen (s2);
 
34
 
 
35
  for (; (p = strchr (p, *s2)) != 0; p++)
 
36
    {
 
37
      if (strncmp (p, s2, len) == 0)
 
38
        return (char *)p;
 
39
    }
 
40
  return (0);
 
41
}