* tiny
[mascara-docs.git] / compilers / bcc / linux86-0.16.17 / libc / string / strstr.c
blobaafcaf967d889b7b325f04d27f818c48002894d8
1 /* 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 */
6 #include <string.h>
8 #if 1
9 /* We've now got a nice fast strchr and memcmp use them */
11 char *
12 strstr(s1, s2)
13 char *s1; char *s2;
15 register int l = strlen(s2);
16 register char * p = s1;
18 if( l==0 ) return p;
20 while (p = strchr(p, *s2))
22 if( memcmp(p, s2, l) == 0 )
23 return p;
24 p++;
26 return (char *) 0;
29 #else
30 /* This is a nice simple self contained strstr,
31 now go and work out why the GNU one is faster :-) */
33 char *strstr(str1, str2)
34 char *str1, *str2;
36 register char *Sptr, *Tptr;
37 int len = strlen(str1) -strlen(str2) + 1;
39 if (*str2)
40 for (; len > 0; len--, str1++){
41 if (*str1 != *str2)
42 continue;
44 for (Sptr = str1, Tptr = str2; *Tptr != '\0'; Sptr++, Tptr++)
45 if (*Sptr != *Tptr)
46 break;
48 if (*Tptr == '\0')
49 return (char*) str1;
52 return (char*)0;
54 #endif