OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [string/] [strstr.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/*
2
FUNCTION
3
        <<strstr>>---find string segment
4
 
5
INDEX
6
        strstr
7
 
8
ANSI_SYNOPSIS
9
        #include <string.h>
10
        char *strstr(const char *<[s1]>, const char *<[s2]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <string.h>
14
        char *strstr(<[s1]>, <[s2]>)
15
        char *<[s1]>;
16
        char *<[s2]>;
17
 
18
DESCRIPTION
19
        Locates the first occurence in the string pointed to by <[s1]> of
20
        the sequence of characters in the string pointed to by <[s2]>
21
        (excluding the terminating null  character).
22
 
23
RETURNS
24
        Returns a pointer to the located string segment, or a null
25
        pointer if the string <[s2]> is not found. If <[s2]> points to
26
        a string with zero length, the <[s1]> is returned.
27
 
28
PORTABILITY
29
<<strstr>> is ANSI C.
30
 
31
<<strstr>> requires no supporting OS subroutines.
32
 
33
QUICKREF
34
        strstr ansi pure
35
*/
36
 
37
#include <string.h>
38
 
39
char *
40
_DEFUN (strstr, (searchee, lookfor),
41
        _CONST char *searchee _AND
42
        _CONST char *lookfor)
43
{
44
  if (*searchee == 0)
45
    {
46
      if (*lookfor)
47
        return (char *) NULL;
48
      return (char *) searchee;
49
    }
50
 
51
  while (*searchee)
52
    {
53
      size_t i;
54
      i = 0;
55
 
56
      while (1)
57
        {
58
          if (lookfor[i] == 0)
59
            {
60
              return (char *) searchee;
61
            }
62
 
63
          if (lookfor[i] != searchee[i])
64
            {
65
              break;
66
            }
67
          i++;
68
        }
69
      searchee++;
70
    }
71
 
72
  return (char *) NULL;
73
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.