From 70828ee0caf954b5dc63bfcd02bc9e18c6a681ff Mon Sep 17 00:00:00 2001 From: Fabrizio Bertocci Date: Mon, 21 Jun 2021 23:30:50 +0200 Subject: [PATCH] Exported method WideCharToMultiByte to convert Windows wchar_t strings to multibyte --- libc/nt/kernel32/WideCharToMultiByte.s | 12 +++++++++++- libc/nt/master.sh | 2 +- libc/nt/windows.h | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libc/nt/kernel32/WideCharToMultiByte.s b/libc/nt/kernel32/WideCharToMultiByte.s index 626013612..f35ebccaa 100644 --- a/libc/nt/kernel32/WideCharToMultiByte.s +++ b/libc/nt/kernel32/WideCharToMultiByte.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_WideCharToMultiByte,WideCharToMultiByte,0 +.imp kernel32,__imp_WideCharToMultiByte,WideCharToMultiByte,1553 + + .text.windows +WideCharToMultiByte: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_WideCharToMultiByte(%rip),%rax + jmp __sysv2nt8 + .endfn WideCharToMultiByte,globl + .previous diff --git a/libc/nt/master.sh b/libc/nt/master.sh index 8d6260545..1bd2a62ab 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -7093,7 +7093,7 @@ imp 'WerpNotifyLoadStringResource' WerpNotifyLoadStringResource KernelBase imp 'WerpNotifyLoadStringResourceWorker' WerpNotifyLoadStringResourceWorker kernel32 1540 imp 'WerpNotifyUseStringResource' WerpNotifyUseStringResource KernelBase 1809 imp 'WerpNotifyUseStringResourceWorker' WerpNotifyUseStringResourceWorker kernel32 1541 -imp 'WideCharToMultiByte' WideCharToMultiByte kernel32 0 # KernelBase +imp 'WideCharToMultiByte' WideCharToMultiByte kernel32 1553 8 imp 'WidenPath' WidenPath gdi32 1941 imp 'Win32DeleteFile' Win32DeleteFile shell32 164 imp 'WinExec' WinExec kernel32 1543 diff --git a/libc/nt/windows.h b/libc/nt/windows.h index 64926aebc..bb0b9e045 100644 --- a/libc/nt/windows.h +++ b/libc/nt/windows.h @@ -91,6 +91,17 @@ bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y, int32_t nReserved, int64_t hWnd, const struct NtRect *prcRect); +int WideCharToMultiByte(unsigned int CodePage, + uint32_t dwFlags, + uint16_t * lpWideCharStr, + int cchWideChar, + char * lpMultiByteStr, + int cbMultiByte, + uint16_t * lpDefaultChar, + int * lpUsedDefaultChar +); + + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_WINDOWS_H_ */