]> pd.if.org Git - pdclib.old/blobdiff - functions/wchar/wmemcmp.c
PDCLIB-2: Pure wide character functions
[pdclib.old] / functions / wchar / wmemcmp.c
diff --git a/functions/wchar/wmemcmp.c b/functions/wchar/wmemcmp.c
new file mode 100644 (file)
index 0000000..2d58914
--- /dev/null
@@ -0,0 +1,39 @@
+/* wmemcmp( const wchar_t *, const wchar_t *, size_t )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wchar.h>\r
+\r
+#ifndef REGTEST\r
+\r
+int wmemcmp( const wchar_t * p1, const wchar_t * p2, size_t n )\r
+{\r
+    while ( n-- )\r
+    {\r
+        if ( *p1 != *p2 )\r
+        {\r
+            return *p1 - *p2;\r
+        }\r
+        ++p1;\r
+        ++p2;\r
+    }\r
+    return 0;\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    wchar_t const xxxxx[] = L"xxxxx";\r
+    TESTCASE( wmemcmp( wabcde, wabcdx, 5 ) < 0 );\r
+    TESTCASE( wmemcmp( wabcde, wabcdx, 4 ) == 0 );\r
+    TESTCASE( wmemcmp( wabcde, xxxxx,  0 ) == 0 );\r
+    TESTCASE( wmemcmp( xxxxx,  wabcde, 1 ) > 0 );\r
+    return 0;\r
+}\r
+#endif\r