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