1 /* strstr( const char *, const char * )
2 
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6 
7 #include <string.h>
8 
9 #ifndef REGTEST
10 
strstr(const char * s1,const char * s2)11 char * strstr( const char * s1, const char * s2 )
12 {
13     const char * p1 = s1;
14     const char * p2;
15 
16     while ( *s1 )
17     {
18         p2 = s2;
19 
20         while ( *p2 && ( *p1 == *p2 ) )
21         {
22             ++p1;
23             ++p2;
24         }
25 
26         if ( ! *p2 )
27         {
28             return ( char * ) s1;
29         }
30 
31         ++s1;
32         p1 = s1;
33     }
34 
35     return NULL;
36 }
37 
38 #endif
39 
40 #ifdef TEST
41 
42 #include "_PDCLIB_test.h"
43 
main(void)44 int main( void )
45 {
46     char s[] = "abcabcabcdabcde";
47     TESTCASE( strstr( s, "x" ) == NULL );
48     TESTCASE( strstr( s, "xyz" ) == NULL );
49     TESTCASE( strstr( s, "a" ) == &s[0] );
50     TESTCASE( strstr( s, "abc" ) == &s[0] );
51     TESTCASE( strstr( s, "abcd" ) == &s[6] );
52     TESTCASE( strstr( s, "abcde" ) == &s[10] );
53     return TEST_RESULTS;
54 }
55 
56 #endif
57