kernel32: Move ReadConsole and WriteConsole to kernelbase.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-10-13 16:27:55 +02:00 committed by Alexandre Julliard
parent 633b244b1a
commit 98dcd3a7ea
4 changed files with 93 additions and 94 deletions

View File

@ -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.@)
*/

View File

@ -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)

View File

@ -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.@)
*/

View File

@ -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)