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