]> pd.if.org Git - pdclib/blob - functions/string/strcmp.c
5202771a67d52f266000746cf63c7608cd9b7682
[pdclib] / functions / string / strcmp.c
1 /* $Id$ */
2
3 /* strcmp( const char *, const char * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <string.h>
10
11 #ifndef REGTEST
12
13 int strcmp( const char * s1, const char * s2 )
14 {
15     while ( ( *s1 ) && ( *s1 == *s2 ) )
16     {
17         ++s1;
18         ++s2;
19     }
20     return ( *(unsigned char *)s1 - *(unsigned char *)s2 );
21 }
22
23 #endif
24
25 #ifdef TEST
26 #include <_PDCLIB_test.h>
27
28 int main( void )
29 {
30     char cmpabcde[] = "abcde";
31     char cmpabcd_[] = "abcd\xfc";
32     char empty[] = "";
33     TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
34     TESTCASE( strcmp( abcde, abcdx ) < 0 );
35     TESTCASE( strcmp( abcdx, abcde ) > 0 );
36     TESTCASE( strcmp( empty, abcde ) < 0 );
37     TESTCASE( strcmp( abcde, empty ) > 0 );
38     TESTCASE( strcmp( abcde, cmpabcd_ ) < 0 );
39     return TEST_RESULTS;
40 }
41 #endif