]> pd.if.org Git - pdclib/blob - functions/string/strpbrk.c
Added #ifdef to allow regression against system lib.
[pdclib] / functions / string / strpbrk.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* strpbrk( 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 * strpbrk( const char * s1, const char * s2 )
16 {
17     const char * p1 = s1;
18     const char * p2;
19     while ( *p1 )
20     {
21         p2 = s2;
22         while ( *p2 )
23         {
24             if ( *p1 == *p2++ )
25             {
26                 return (char *) p1;
27             }
28         }
29         ++p1;
30     }
31     return NULL;
32 }
33
34 #endif
35
36 #ifdef TEST
37 #include <_PDCLIB_test.h>
38
39 int main()
40 {
41     BEGIN_TESTS;
42     TESTCASE( strpbrk( abcde, "x" ) == NULL );
43     TESTCASE( strpbrk( abcde, "xyz" ) == NULL );
44     TESTCASE( strpbrk( abcdx, "x" ) == &abcdx[4] );
45     TESTCASE( strpbrk( abcdx, "xyz" ) == &abcdx[4] );
46     TESTCASE( strpbrk( abcdx, "zyx" ) == &abcdx[4] );
47     TESTCASE( strpbrk( abcde, "a" ) == &abcde[0] );
48     TESTCASE( strpbrk( abcde, "abc" ) == &abcde[0] );
49     TESTCASE( strpbrk( abcde, "cba" ) == &abcde[0] );
50     return TEST_RESULTS;
51 }
52 #endif