xref: /reactos/sdk/lib/ucrt/string/wcsncmp.cpp (revision fe11f7a2)
1 //
2 // wcsncmp.cpp
3 //
4 //      Copyright (c) Microsoft Corporation.  All rights reserved.
5 //
6 // Defines wcsncmp(), which compares two wide character strings, determining
7 // their ordinal order.  The function tests at most 'count' characters.
8 //
9 // Note that the comparison is performed with unsigned elements (wchar_t is
10 // unsigned in this implementation), so the null character (0) is less than
11 // all other characters.
12 //
13 // Returns:
14 //  * a negative value if a  < b
15 //  * zero             if a == b
16 //  * a positive value if a  > b
17 //
18 #include <string.h>
19 
20 
21 
22 #ifdef _M_ARM
23     #pragma function(wcsncmp)
24 #endif
25 
26 
27 
28 extern "C" int __cdecl wcsncmp(
29     wchar_t const* a,
30     wchar_t const* b,
31     size_t         count
32     )
33 {
34     if (count == 0)
35         return 0;
36 
37     while (--count != 0 && *a && *a == *b)
38     {
39         ++a;
40         ++b;
41     }
42 
43     return static_cast<int>(*a - *b);
44 }
45