X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fwchar%2Fwcsncmp.c;fp=functions%2Fwchar%2Fwcsncmp.c;h=920d64719203e86ecc81f43b46c9946ea7c968f3;hb=507d3eccbf4c74e4694165f9e00ab79d894b4f66;hp=0000000000000000000000000000000000000000;hpb=0150bb9ffe66236b6a47c5800d8beef669d5c047;p=pdclib.old diff --git a/functions/wchar/wcsncmp.c b/functions/wchar/wcsncmp.c new file mode 100644 index 0000000..920d647 --- /dev/null +++ b/functions/wchar/wcsncmp.c @@ -0,0 +1,54 @@ +/* $Id$ */ + +/* wcsncmp( const wchar_t *, const wchar_t *, size_t ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +int wcsncmp( const wchar_t * s1, const wchar_t * s2, size_t n ) +{ + while ( *s1 && n && ( *s1 == *s2 ) ) + { + ++s1; + ++s2; + --n; + } + if ( ( n == 0 ) ) + { + return 0; + } + else + { + return ( *(wchar_t *)s1 - *(wchar_t *)s2 ); + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + wchar_t cmpabcde[] = L"abcde\0f"; + wchar_t cmpabcd_[] = L"abcde\xfc"; + wchar_t empty[] = L""; + wchar_t x[] = L"x"; + TESTCASE( wcsncmp( wabcde, cmpabcde, 5 ) == 0 ); + TESTCASE( wcsncmp( wabcde, cmpabcde, 10 ) == 0 ); + TESTCASE( wcsncmp( wabcde, wabcdx, 5 ) < 0 ); + TESTCASE( wcsncmp( wabcdx, wabcde, 5 ) > 0 ); + TESTCASE( wcsncmp( empty, wabcde, 5 ) < 0 ); + TESTCASE( wcsncmp( wabcde, empty, 5 ) > 0 ); + TESTCASE( wcsncmp( wabcde, wabcdx, 4 ) == 0 ); + TESTCASE( wcsncmp( wabcde, x, 0 ) == 0 ); + TESTCASE( wcsncmp( wabcde, x, 1 ) < 0 ); + TESTCASE( wcsncmp( wabcde, cmpabcd_, 10 ) < 0 ); + return TEST_RESULTS; +} +#endif