Skip to content

Commit 5cbb2c9

Browse files
committed
[LIBCNTPR] Implement multibyte NT version of toupper
Windows ntdll and ntoskrnl export a multibyte capable version of toupper (not tolower though!) The internal version is kept as it is, because the multibyte version requires unicode tables to be set up and doesn't support IRQL > APC_LEVEL. Why though would toupper (but not tolower) support raw, undecoded multibyte characters, you might ask. Well I don't know, but someone at MS must have decided that this is a good idea, and winetests show this is how it behaves.
1 parent 3669658 commit 5cbb2c9

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

dll/ntdll/def/ntdll.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@
18881888
@ varargs swprintf(ptr wstr)
18891889
@ cdecl -arch=i386,x86_64 tan(double)
18901890
@ cdecl tolower(long)
1891-
@ cdecl toupper(long)
1891+
@ cdecl toupper(long) toupper_nt_mb
18921892
@ cdecl towlower(long)
18931893
@ cdecl towupper(long)
18941894
@ stdcall vDbgPrintEx(long long str ptr)

ntoskrnl/ntoskrnl.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@
16231623
@ cdecl strstr()
16241624
@ cdecl swprintf()
16251625
@ cdecl tolower()
1626-
@ cdecl toupper()
1626+
@ cdecl toupper() toupper_nt_mb
16271627
@ cdecl towlower()
16281628
@ cdecl towupper()
16291629
@ stdcall vDbgPrintEx(long long str ptr)

sdk/lib/crt/string/string.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ list(APPEND CRT_STRING_ASM_SOURCE
113113
list(APPEND LIBCNTPR_STRING_SOURCE
114114
string/mbstowcs_nt.c
115115
string/tolower_nt.c
116+
string/toupper_nt_mb.c
116117
string/towupper_nt.c
117118
string/wcstombs_nt.c
118119
)

sdk/lib/crt/string/toupper_nt_mb.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* PROJECT: ReactOS NT CRT library
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Multibyte capable version of toupper
5+
* COPYRIGHT: Copyright 2025 Timo Kreuzer <[email protected]>
6+
*/
7+
8+
#define WIN32_NO_STATUS
9+
#include <windef.h>
10+
#include <ndk/rtlfuncs.h>
11+
12+
_Check_return_
13+
int
14+
__cdecl
15+
toupper_nt_mb(_In_ int _C)
16+
{
17+
PUCHAR ptr;
18+
WCHAR wc, wcUpper;
19+
CHAR chrUpper[2];
20+
ULONG mbSize;
21+
22+
ptr = (PUCHAR)&_C;
23+
wc = RtlAnsiCharToUnicodeChar(&ptr);
24+
wcUpper = RtlUpcaseUnicodeChar(wc);
25+
RtlUnicodeToMultiByteN(chrUpper, 2, &mbSize, &wcUpper, sizeof(WCHAR));
26+
27+
if (mbSize == 2)
28+
return (UCHAR)chrUpper[1] + ((UCHAR)chrUpper[0] << 8);
29+
else if (mbSize == 1)
30+
return (UCHAR)chrUpper[0];
31+
else
32+
return (WCHAR)_C;
33+
}

0 commit comments

Comments
 (0)