diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c index 656e91c5d0b..2b46fe5589f 100644 --- a/dlls/kernel32/console.c +++ b/dlls/kernel32/console.c @@ -242,53 +242,6 @@ DWORD WINAPI GetConsoleTitleA(LPSTR title, DWORD size) } -/*********************************************************************** - * ReadConsoleA (KERNEL32.@) - */ -BOOL WINAPI ReadConsoleA( HANDLE handle, LPVOID buffer, DWORD length, DWORD *ret_count, void *reserved ) -{ - LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) ); - DWORD count = 0; - BOOL ret; - - if (!strW) - { - SetLastError( ERROR_NOT_ENOUGH_MEMORY ); - return FALSE; - } - if ((ret = ReadConsoleW( handle, strW, length, &count, NULL ))) - { - count = WideCharToMultiByte( GetConsoleCP(), 0, strW, count, buffer, length, NULL, NULL ); - if (ret_count) *ret_count = count; - } - HeapFree( GetProcessHeap(), 0, strW ); - return ret; -} - - -/*********************************************************************** - * ReadConsoleW (KERNEL32.@) - */ -BOOL WINAPI ReadConsoleW( HANDLE handle, void *buffer, DWORD length, DWORD *count, void *reserved ) -{ - BOOL ret; - - TRACE( "(%p,%p,%d,%p,%p)\n", handle, buffer, length, count, reserved ); - - if (length > INT_MAX) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - ret = DeviceIoControl( handle, IOCTL_CONDRV_READ_CONSOLE, NULL, 0, buffer, - length * sizeof(WCHAR), count, NULL ); - if (ret) *count /= sizeof(WCHAR); - else SetLastError( ERROR_INVALID_HANDLE ); - return ret; -} - - /*********************************************************************** * GetNumberOfConsoleMouseButtons (KERNEL32.@) */ @@ -300,45 +253,6 @@ BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons) } -/*********************************************************************** - * WriteConsoleA (KERNEL32.@) - */ -BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA( HANDLE handle, LPCVOID buffer, DWORD length, - DWORD *written, void *reserved ) -{ - UINT cp = GetConsoleOutputCP(); - LPWSTR strW; - DWORD lenW; - BOOL ret; - - if (written) *written = 0; - lenW = MultiByteToWideChar( cp, 0, buffer, length, NULL, 0 ); - if (!(strW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) return FALSE; - MultiByteToWideChar( cp, 0, buffer, length, strW, lenW ); - ret = WriteConsoleW( handle, strW, lenW, written, 0 ); - HeapFree( GetProcessHeap(), 0, strW ); - return ret; -} - - -/*********************************************************************** - * WriteConsoleW (KERNEL32.@) - */ -BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW( HANDLE handle, const void *buffer, DWORD length, - DWORD *written, void *reserved ) -{ - BOOL ret; - - TRACE( "(%p,%s,%d,%p,%p)\n", handle, debugstr_wn(buffer, length), length, written, reserved ); - - ret = DeviceIoControl( handle, IOCTL_CONDRV_WRITE_CONSOLE, (void *)buffer, - length * sizeof(WCHAR), NULL, 0, NULL, NULL ); - if (written) *written = ret ? length : 0; - if (!ret) SetLastError( ERROR_INVALID_HANDLE ); - return ret; -} - - /****************************************************************** * GetConsoleDisplayMode (KERNEL32.@) */ diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index f68989424d5..08a64955123 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -1193,7 +1193,7 @@ @ stdcall -import QueueUserWorkItem(ptr ptr long) @ stdcall -import RaiseException(long long long ptr) # @ stub RaiseFailFastException -@ stdcall ReadConsoleA(long ptr long ptr ptr) +@ stdcall -import ReadConsoleA(long ptr long ptr ptr) @ stdcall -import ReadConsoleInputA(long ptr long ptr) @ stub ReadConsoleInputExA @ stub ReadConsoleInputExW @@ -1203,7 +1203,7 @@ @ stdcall -import ReadConsoleOutputCharacterA(long ptr long long ptr) @ stdcall -import ReadConsoleOutputCharacterW(long ptr long long ptr) @ stdcall -import ReadConsoleOutputW(long ptr long long ptr) -@ stdcall ReadConsoleW(long ptr long ptr ptr) +@ stdcall -import ReadConsoleW(long ptr long ptr ptr) @ stdcall -import ReadDirectoryChangesW(long ptr long long long ptr ptr ptr) @ stdcall ReadFile(long ptr long ptr ptr) KERNEL32_ReadFile @ stdcall -import ReadFileEx(long ptr long ptr ptr) @@ -1619,7 +1619,7 @@ @ stdcall -import Wow64RevertWow64FsRedirection(ptr) @ stdcall Wow64SetThreadContext(long ptr) # @ stub Wow64SuspendThread -@ stdcall WriteConsoleA(long ptr long ptr ptr) +@ stdcall -import WriteConsoleA(long ptr long ptr ptr) @ stdcall -import WriteConsoleInputA(long ptr long ptr) @ stub WriteConsoleInputVDMA @ stub WriteConsoleInputVDMW @@ -1629,7 +1629,7 @@ @ stdcall -import WriteConsoleOutputCharacterA(long ptr long long ptr) @ stdcall -import WriteConsoleOutputCharacterW(long ptr long long ptr) @ stdcall -import WriteConsoleOutputW(long ptr long long ptr) -@ stdcall WriteConsoleW(long ptr long ptr ptr) +@ stdcall -import WriteConsoleW(long ptr long ptr ptr) @ stdcall WriteFile(long ptr long ptr ptr) KERNEL32_WriteFile @ stdcall -import WriteFileEx(long ptr long ptr ptr) @ stdcall -import WriteFileGather(long ptr long ptr ptr) diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c index 0fd832d3785..4f511b16379 100644 --- a/dlls/kernelbase/console.c +++ b/dlls/kernelbase/console.c @@ -7,6 +7,7 @@ * Copyright 1998 Marcus Meissner * Copyright 2001,2002,2004,2005,2010 Eric Pouech * Copyright 2001 Alexandre Julliard + * Copyright 2020 Jacek Caban for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1659,6 +1660,90 @@ BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputCharacterW( HANDLE handle, LPCWS } +/*********************************************************************** + * ReadConsoleA (kernelbase.@) + */ +BOOL WINAPI ReadConsoleA( HANDLE handle, void *buffer, DWORD length, DWORD *ret_count, void *reserved ) +{ + LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) ); + DWORD count = 0; + BOOL ret; + + if (!strW) + { + SetLastError( ERROR_NOT_ENOUGH_MEMORY ); + return FALSE; + } + if ((ret = ReadConsoleW( handle, strW, length, &count, NULL ))) + { + count = WideCharToMultiByte( GetConsoleCP(), 0, strW, count, buffer, length, NULL, NULL ); + if (ret_count) *ret_count = count; + } + HeapFree( GetProcessHeap(), 0, strW ); + return ret; +} + + +/*********************************************************************** + * ReadConsoleW (kernelbase.@) + */ +BOOL WINAPI ReadConsoleW( HANDLE handle, void *buffer, DWORD length, DWORD *count, void *reserved ) +{ + BOOL ret; + + TRACE( "(%p,%p,%d,%p,%p)\n", handle, buffer, length, count, reserved ); + + if (length > INT_MAX) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + ret = console_ioctl( handle, IOCTL_CONDRV_READ_CONSOLE, NULL, 0, buffer, + length * sizeof(WCHAR), count ); + if (ret) *count /= sizeof(WCHAR); + return ret; +} + + +/*********************************************************************** + * WriteConsoleA (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA( HANDLE handle, const void *buffer, DWORD length, + DWORD *written, void *reserved ) +{ + UINT cp = GetConsoleOutputCP(); + LPWSTR strW; + DWORD lenW; + BOOL ret; + + if (written) *written = 0; + lenW = MultiByteToWideChar( cp, 0, buffer, length, NULL, 0 ); + if (!(strW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) return FALSE; + MultiByteToWideChar( cp, 0, buffer, length, strW, lenW ); + ret = WriteConsoleW( handle, strW, lenW, written, 0 ); + HeapFree( GetProcessHeap(), 0, strW ); + return ret; +} + + +/*********************************************************************** + * WriteConsoleW (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW( HANDLE handle, const void *buffer, DWORD length, + DWORD *written, void *reserved ) +{ + BOOL ret; + + TRACE( "(%p,%s,%d,%p,%p)\n", handle, debugstr_wn(buffer, length), length, written, reserved ); + + ret = console_ioctl( handle, IOCTL_CONDRV_WRITE_CONSOLE, (void *)buffer, + length * sizeof(WCHAR), NULL, 0, NULL ); + if (written) *written = ret ? length : 0; + return ret; +} + + /*********************************************************************** * Beep (kernelbase.@) */ diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 1ba1c52b21a..e55194f2041 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -1237,7 +1237,7 @@ @ stdcall RaiseException(long long long ptr) # @ stub RaiseFailFastException @ stdcall ReOpenFile(ptr long long long) -@ stdcall ReadConsoleA(long ptr long ptr ptr) kernel32.ReadConsoleA +@ stdcall ReadConsoleA(long ptr long ptr ptr) @ stdcall ReadConsoleInputA(long ptr long ptr) @ stub ReadConsoleInputExA @ stub ReadConsoleInputExW @@ -1247,7 +1247,7 @@ @ stdcall ReadConsoleOutputCharacterA(long ptr long long ptr) @ stdcall ReadConsoleOutputCharacterW(long ptr long long ptr) @ stdcall ReadConsoleOutputW(long ptr long long ptr) -@ stdcall ReadConsoleW(long ptr long ptr ptr) kernel32.ReadConsoleW +@ stdcall ReadConsoleW(long ptr long ptr ptr) @ stdcall ReadDirectoryChangesW(long ptr long long long ptr ptr ptr) @ stdcall ReadFile(long ptr long ptr ptr) @ stdcall ReadFileEx(long ptr long ptr ptr) @@ -1721,7 +1721,7 @@ @ stdcall Wow64RevertWow64FsRedirection(ptr) # @ stub Wow64SetThreadDefaultGuestMachine # @ stub -arch=i386 Wow64Transition -@ stdcall WriteConsoleA(long ptr long ptr ptr) kernel32.WriteConsoleA +@ stdcall WriteConsoleA(long ptr long ptr ptr) @ stdcall WriteConsoleInputA(long ptr long ptr) @ stdcall WriteConsoleInputW(long ptr long ptr) @ stdcall WriteConsoleOutputA(long ptr long long ptr) @@ -1729,7 +1729,7 @@ @ stdcall WriteConsoleOutputCharacterA(long ptr long long ptr) @ stdcall WriteConsoleOutputCharacterW(long ptr long long ptr) @ stdcall WriteConsoleOutputW(long ptr long long ptr) -@ stdcall WriteConsoleW(long ptr long ptr ptr) kernel32.WriteConsoleW +@ stdcall WriteConsoleW(long ptr long ptr ptr) @ stdcall WriteFile(long ptr long ptr ptr) @ stdcall WriteFileEx(long ptr long ptr ptr) @ stdcall WriteFileGather(long ptr long ptr ptr)