]> pd.if.org Git - pdclib/blob - functions/string/strchr.c
Added #ifdef to allow regression against system lib.
[pdclib] / functions / string / strchr.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* strchr( const char *, int )
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 * strchr( const char * s, int c )
16 {
17     do
18     {
19         if ( *s == (char) c )
20         {
21             return (char *) s;
22         }
23     } while ( *s++ );
24     return NULL;
25 }
26
27 #endif
28
29 #ifdef TEST
30 #include <_PDCLIB_test.h>
31
32 int main()
33 {
34     char abccd[] = "abccd";
35     BEGIN_TESTS;
36     TESTCASE( strchr( abccd, 'x' ) == NULL );
37     TESTCASE( strchr( abccd, 'a' ) == &abccd[0] );
38     TESTCASE( strchr( abccd, 'd' ) == &abccd[4] );
39     TESTCASE( strchr( abccd, '\0' ) == &abccd[5] );
40     TESTCASE( strchr( abccd, 'c' ) == &abccd[2] );
41     return TEST_RESULTS;
42 }
43 #endif