1 /* strncmp( const char *, const char *, size_t )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
11 int strncmp( const char * s1, const char * s2, size_t n )
13 while ( *s1 && n && ( *s1 == *s2 ) )
25 return ( *(unsigned char *)s1 - *(unsigned char *)s2 );
33 #include "_PDCLIB_test.h"
37 char cmpabcde[] = "abcde\0f";
38 char cmpabcd_[] = "abcde\xfc";
41 TESTCASE( strncmp( abcde, cmpabcde, 5 ) == 0 );
42 TESTCASE( strncmp( abcde, cmpabcde, 10 ) == 0 );
43 TESTCASE( strncmp( abcde, abcdx, 5 ) < 0 );
44 TESTCASE( strncmp( abcdx, abcde, 5 ) > 0 );
45 TESTCASE( strncmp( empty, abcde, 5 ) < 0 );
46 TESTCASE( strncmp( abcde, empty, 5 ) > 0 );
47 TESTCASE( strncmp( abcde, abcdx, 4 ) == 0 );
48 TESTCASE( strncmp( abcde, x, 0 ) == 0 );
49 TESTCASE( strncmp( abcde, x, 1 ) < 0 );
50 TESTCASE( strncmp( abcde, cmpabcd_, 10 ) < 0 );