]> pd.if.org Git - pdclib/blob - functions/string/memcmp.c
Porting current working set from CVS.
[pdclib] / functions / string / memcmp.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* memcmp( const void *, const void *, size_t )
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 int memcmp( const void * s1, const void * s2, size_t n )
16 {
17     const unsigned char * p1 = (const unsigned char *) s1;
18     const unsigned char * p2 = (const unsigned char *) s2;
19     while ( n-- )
20     {
21         if ( *p1 != *p2 )
22         {
23             return *p1 - *p2;
24         }
25         ++p1;
26         ++p2;
27     }
28     return 0;
29 }
30
31 #endif
32
33 #ifdef TEST
34 #include <_PDCLIB_test.h>
35
36 int main( void )
37 {
38     char const xxxxx[] = "xxxxx";
39     TESTCASE( memcmp( abcde, abcdx, 5 ) < 0 );
40     TESTCASE( memcmp( abcde, abcdx, 4 ) == 0 );
41     TESTCASE( memcmp( abcde, xxxxx, 0 ) == 0 );
42     TESTCASE( memcmp( xxxxx, abcde, 1 ) > 0 );
43     return 0;
44 }
45 #endif