winpr/crt: Fix endianness in string utils

All WCHAR strings are stored as little endian after commit f722dc5,
therefor WCHAR string utils have to be changed appropriately.
This commit is contained in:
Ondrej Holy 2016-06-08 11:42:27 +02:00
parent 1903537f09
commit bbcc0476c7
1 changed files with 25 additions and 6 deletions

View File

@ -87,13 +87,17 @@ int _strnicmp(const char* string1, const char* string2, size_t count)
int _wcscmp(const WCHAR* string1, const WCHAR* string2)
{
WCHAR value1, value2;
while (*string1 && (*string1 == *string2))
{
string1++;
string2++;
}
return *string1 - *string2;
Data_Read_UINT16(string1, value1);
Data_Read_UINT16(string2, value2);
return value1 - value2;
}
/* _wcslen -> wcslen */
@ -116,11 +120,13 @@ size_t _wcslen(const WCHAR* str)
WCHAR* _wcschr(const WCHAR* str, WCHAR c)
{
WCHAR* p = (WCHAR*) str;
WCHAR value;
while (*p && (*p != c))
Data_Write_UINT16(&value, c);
while (*p && (*p != value))
p++;
return ((*p == c) ? p : NULL);
return ((*p == value) ? p : NULL);
}
char* strtok_s(char* strToken, const char* strDelimit, char** context)
@ -131,20 +137,29 @@ char* strtok_s(char* strToken, const char* strDelimit, char** context)
WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context)
{
WCHAR* nextToken;
WCHAR value;
if (!strToken)
strToken = *context;
while (*strToken && _wcschr(strDelimit, *strToken))
Data_Read_UINT16(strToken, value);
while (*strToken && _wcschr(strDelimit, value))
{
strToken++;
Data_Read_UINT16(strToken, value);
}
if (!*strToken)
return NULL;
nextToken = strToken++;
while (*strToken && !(_wcschr(strDelimit, *strToken)))
Data_Read_UINT16(strToken, value);
while (*strToken && !(_wcschr(strDelimit, value)))
{
strToken++;
Data_Read_UINT16(strToken, value);
}
if (*strToken)
*strToken++ = 0;
@ -387,13 +402,17 @@ int lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
{
WCHAR value1, value2;
while (*lpString1 && (*lpString1 == *lpString2))
{
lpString1++;
lpString2++;
}
return *lpString1 - *lpString2;
Data_Read_UINT16(lpString1, value1);
Data_Read_UINT16(lpString2, value2);
return value1 - value2;
}
#endif