Updated _wcschr and _wcsrchr to match MSDN spec

This commit is contained in:
Armin Novak 2022-04-27 18:55:47 +02:00 committed by akallabeth
parent 5482607b15
commit 2dc98adb62
2 changed files with 24 additions and 12 deletions

View File

@ -61,8 +61,8 @@ extern "C"
WINPR_API size_t _wcslen(const WCHAR* str);
WINPR_API size_t _wcsnlen(const WCHAR* str, size_t maxNumberOfElements);
WINPR_API const WCHAR* _wcschr(const WCHAR* str, WCHAR c);
WINPR_API const WCHAR* _wcsrchr(const WCHAR* str, WCHAR c);
WINPR_API WCHAR* _wcschr(const WCHAR* str, WCHAR c);
WINPR_API WCHAR* _wcsrchr(const WCHAR* str, WCHAR c);
WINPR_API char* strtok_s(char* strToken, const char* strDelimit, char** context);
WINPR_API WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context);

View File

@ -128,33 +128,45 @@ size_t _wcsnlen(const WCHAR* str, size_t max)
/* _wcschr -> wcschr */
const WCHAR* _wcschr(const WCHAR* str, WCHAR c)
WCHAR* _wcschr(const WCHAR* str, WCHAR value)
{
union
{
const WCHAR* cc;
WCHAR* c;
} cnv;
const WCHAR* p = (const WCHAR*)str;
WCHAR value;
Data_Write_UINT16(&value, c);
while (*p && (*p != value))
p++;
return ((*p == value) ? p : NULL);
cnv.cc = (*p == value) ? p : NULL;
return cnv.c;
}
/* _wcsrchr -> wcsrchr */
const WCHAR* _wcsrchr(const WCHAR* str, WCHAR c)
WCHAR* _wcsrchr(const WCHAR* str, WCHAR c)
{
const WCHAR* p;
WCHAR ch;
union
{
const WCHAR* cc;
WCHAR* c;
} cnv;
const WCHAR* p = NULL;
if (!str)
return NULL;
for (p = (const WCHAR*)0; (ch = *str); str++)
for (; *str != '\0'; str++)
{
const WCHAR ch = *str;
if (ch == c)
p = (const WCHAR*)str;
p = str;
}
return p;
cnv.cc = p;
return cnv.c;
}
char* strtok_s(char* strToken, const char* strDelimit, char** context)