]> pd.if.org Git - pdclib/blob - functions/string/strcmp.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / string / strcmp.c
1 /* strcmp( 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
11 int strcmp( const char * s1, const char * s2 )
12 {
13     while ( ( *s1 ) && ( *s1 == *s2 ) )
14     {
15         ++s1;
16         ++s2;
17     }
18     return ( *(unsigned char *)s1 - *(unsigned char *)s2 );
19 }
20
21 #endif
22
23 #ifdef TEST
24 #include "_PDCLIB_test.h"
25
26 int main( void )
27 {
28     char cmpabcde[] = "abcde";
29     char cmpabcd_[] = "abcd\xfc";
30     char empty[] = "";
31     TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
32     TESTCASE( strcmp( abcde, abcdx ) < 0 );
33     TESTCASE( strcmp( abcdx, abcde ) > 0 );
34     TESTCASE( strcmp( empty, abcde ) < 0 );
35     TESTCASE( strcmp( abcde, empty ) > 0 );
36     TESTCASE( strcmp( abcde, cmpabcd_ ) < 0 );
37     return TEST_RESULTS;
38 }
39 #endif