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