Reactos
at master 40 lines 984 B view raw
1// 2// wcscmp.cpp 3// 4// Copyright (c) Microsoft Corporation. All rights reserved. 5// 6// Defines wcscmp(), which compares two wide character strings, determining 7// their ordinal order. 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// * -1 if a < b 15// * 0 if a == b 16// * 1 if a > b 17// 18#include <string.h> 19 20 21 22#if defined _M_X64 || defined _M_IX86 || defined _M_ARM || defined _M_ARM64 23 #pragma warning(disable: 4163) 24 #pragma function(wcscmp) 25#endif 26 27 28 29extern "C" int __cdecl wcscmp(wchar_t const* a, wchar_t const* b) 30{ 31 int result = 0; 32#pragma warning(suppress:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 33 while ((result = (int)(*a - *b)) == 0 && *b) 34 { 35 ++a; 36 ++b; 37 } 38 39 return ((-result) < 0) - (result < 0); // (if positive) - (if negative) generates branchless code 40}