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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [string/] [strstr.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
2
 * This file is part of the Linux-8086 C library and is distributed
3
 * under the GNU Library General Public License.
4
 */
5
 
6
#include <string.h>
7
 
8
#if 1
9
/* We've now got a nice fast strchr and memcmp use them */
10
 
11
char *
12
strstr(s1, s2)
13
char *s1; char *s2;
14
{
15
   register int l = strlen(s2);
16
   register char * p = s1;
17
 
18
   if( l==0 ) return p;
19
 
20
   while (p = strchr(p, *s2))
21
   {
22
      if( memcmp(p, s2, l) == 0 )
23
         return p;
24
      p++;
25
   }
26
   return (char *) 0;
27
}
28
 
29
#else
30
/* This is a nice simple self contained strstr,
31
   now go and work out why the GNU one is faster :-) */
32
 
33
char *strstr(str1, str2)
34
char *str1, *str2;
35
{
36
    register char *Sptr, *Tptr;
37
    int len = strlen(str1) -strlen(str2) + 1;
38
 
39
    if (*str2)
40
        for (; len > 0;  len--, str1++){
41
            if (*str1 != *str2)
42
                continue;
43
 
44
            for (Sptr = str1, Tptr = str2; *Tptr != '\0'; Sptr++, Tptr++)
45
                if (*Sptr != *Tptr)
46
                    break;
47
 
48
            if (*Tptr == '\0')
49
                return (char*) str1;
50
        }
51
 
52
    return (char*)0;
53
}
54
#endif

powered by: WebSVN 2.1.0

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