mirror of
https://github.com/reactos/reactos.git
synced 2024-09-10 04:42:00 +00:00
- Add a function in kernel32 for translating STD_*_HANDLE constants to actual handles, for those APIs which accept either. Replace code in 8 APIs that already did this translation.
- Call it in WriteFile, ReadFile, and FlushFileBuffers, which previously did not. svn path=/trunk/; revision=35109
This commit is contained in:
parent
99961c6297
commit
f143cab0bb
|
@ -353,6 +353,8 @@ FlushFileBuffers(HANDLE hFile)
|
|||
NTSTATUS errCode;
|
||||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
|
||||
hFile = TranslateStdHandle(hFile);
|
||||
|
||||
if (IsConsoleHandle(hFile))
|
||||
{
|
||||
return FALSE;
|
||||
|
@ -561,20 +563,7 @@ GetFileType(HANDLE hFile)
|
|||
NTSTATUS Status;
|
||||
|
||||
/* Get real handle */
|
||||
switch ((ULONG)hFile)
|
||||
{
|
||||
case STD_INPUT_HANDLE:
|
||||
hFile = NtCurrentPeb()->ProcessParameters->StandardInput;
|
||||
break;
|
||||
|
||||
case STD_OUTPUT_HANDLE:
|
||||
hFile = NtCurrentPeb()->ProcessParameters->StandardOutput;
|
||||
break;
|
||||
|
||||
case STD_ERROR_HANDLE:
|
||||
hFile = NtCurrentPeb()->ProcessParameters->StandardError;
|
||||
break;
|
||||
}
|
||||
hFile = TranslateStdHandle(hFile);
|
||||
|
||||
/* Check for console handle */
|
||||
if (IsConsoleHandle(hFile))
|
||||
|
|
|
@ -37,6 +37,8 @@ WriteFile(IN HANDLE hFile,
|
|||
*lpNumberOfBytesWritten = 0;
|
||||
}
|
||||
|
||||
hFile = TranslateStdHandle(hFile);
|
||||
|
||||
if (IsConsoleHandle(hFile))
|
||||
{
|
||||
return WriteConsoleA(hFile,
|
||||
|
@ -142,6 +144,8 @@ ReadFile(IN HANDLE hFile,
|
|||
*lpNumberOfBytesRead = 0;
|
||||
}
|
||||
|
||||
hFile = TranslateStdHandle(hFile);
|
||||
|
||||
if (IsConsoleHandle(hFile))
|
||||
{
|
||||
return ReadConsoleA(hFile,
|
||||
|
|
|
@ -73,6 +73,8 @@ HANDLE STDCALL OpenConsoleW (LPCWSTR wsName,
|
|||
|
||||
PTEB GetTeb(VOID);
|
||||
|
||||
HANDLE FASTCALL TranslateStdHandle(HANDLE hHandle);
|
||||
|
||||
PWCHAR FilenameA2W(LPCSTR NameA, BOOL alloc);
|
||||
|
||||
DWORD FilenameW2A_FitOrFail(LPSTR DestA, INT destLen, LPCWSTR SourceW, INT sourceLen);
|
||||
|
|
|
@ -26,6 +26,21 @@ DuplicateConsoleHandle (HANDLE hConsole,
|
|||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
HANDLE FASTCALL
|
||||
TranslateStdHandle(HANDLE hHandle)
|
||||
{
|
||||
PRTL_USER_PROCESS_PARAMETERS Ppb = NtCurrentPeb()->ProcessParameters;
|
||||
|
||||
switch ((ULONG)hHandle)
|
||||
{
|
||||
case STD_INPUT_HANDLE: return Ppb->StandardInput;
|
||||
case STD_OUTPUT_HANDLE: return Ppb->StandardOutput;
|
||||
case STD_ERROR_HANDLE: return Ppb->StandardError;
|
||||
}
|
||||
|
||||
return hHandle;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
|
@ -33,25 +48,12 @@ BOOL WINAPI
|
|||
GetHandleInformation (HANDLE hObject,
|
||||
LPDWORD lpdwFlags)
|
||||
{
|
||||
PRTL_USER_PROCESS_PARAMETERS Ppb;
|
||||
OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo;
|
||||
ULONG BytesWritten;
|
||||
NTSTATUS Status;
|
||||
DWORD Flags;
|
||||
|
||||
Ppb = NtCurrentPeb()->ProcessParameters;
|
||||
switch ((ULONG)hObject)
|
||||
{
|
||||
case STD_INPUT_HANDLE:
|
||||
hObject = Ppb->StandardInput;
|
||||
break;
|
||||
case STD_OUTPUT_HANDLE:
|
||||
hObject = Ppb->StandardOutput;
|
||||
break;
|
||||
case STD_ERROR_HANDLE:
|
||||
hObject = Ppb->StandardError;
|
||||
break;
|
||||
}
|
||||
hObject = TranslateStdHandle(hObject);
|
||||
|
||||
Status = NtQueryObject (hObject,
|
||||
ObjectHandleFlagInformation,
|
||||
|
@ -86,24 +88,11 @@ SetHandleInformation (HANDLE hObject,
|
|||
DWORD dwMask,
|
||||
DWORD dwFlags)
|
||||
{
|
||||
PRTL_USER_PROCESS_PARAMETERS Ppb;
|
||||
OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo;
|
||||
ULONG BytesWritten;
|
||||
NTSTATUS Status;
|
||||
|
||||
Ppb = NtCurrentPeb()->ProcessParameters;
|
||||
switch ((ULONG)hObject)
|
||||
{
|
||||
case STD_INPUT_HANDLE:
|
||||
hObject = Ppb->StandardInput;
|
||||
break;
|
||||
case STD_OUTPUT_HANDLE:
|
||||
hObject = Ppb->StandardOutput;
|
||||
break;
|
||||
case STD_ERROR_HANDLE:
|
||||
hObject = Ppb->StandardError;
|
||||
break;
|
||||
}
|
||||
hObject = TranslateStdHandle(hObject);
|
||||
|
||||
Status = NtQueryObject (hObject,
|
||||
ObjectHandleFlagInformation,
|
||||
|
@ -149,22 +138,9 @@ BOOL STDCALL CloseHandle(HANDLE hObject)
|
|||
* If the function fails, the return value is zero
|
||||
*/
|
||||
{
|
||||
PRTL_USER_PROCESS_PARAMETERS Ppb;
|
||||
NTSTATUS Status;
|
||||
|
||||
Ppb = NtCurrentPeb()->ProcessParameters;
|
||||
switch ((ULONG)hObject)
|
||||
{
|
||||
case STD_INPUT_HANDLE:
|
||||
hObject = Ppb->StandardInput;
|
||||
break;
|
||||
case STD_OUTPUT_HANDLE:
|
||||
hObject = Ppb->StandardOutput;
|
||||
break;
|
||||
case STD_ERROR_HANDLE:
|
||||
hObject = Ppb->StandardError;
|
||||
break;
|
||||
}
|
||||
hObject = TranslateStdHandle(hObject);
|
||||
|
||||
if (IsConsoleHandle(hObject))
|
||||
{
|
||||
|
@ -193,23 +169,10 @@ BOOL STDCALL DuplicateHandle(HANDLE hSourceProcessHandle,
|
|||
BOOL bInheritHandle,
|
||||
DWORD dwOptions)
|
||||
{
|
||||
PRTL_USER_PROCESS_PARAMETERS Ppb;
|
||||
DWORD SourceProcessId, TargetProcessId;
|
||||
NTSTATUS Status;
|
||||
|
||||
Ppb = NtCurrentPeb()->ProcessParameters;
|
||||
switch ((ULONG)hSourceHandle)
|
||||
{
|
||||
case STD_INPUT_HANDLE:
|
||||
hSourceHandle = Ppb->StandardInput;
|
||||
break;
|
||||
case STD_OUTPUT_HANDLE:
|
||||
hSourceHandle = Ppb->StandardOutput;
|
||||
break;
|
||||
case STD_ERROR_HANDLE:
|
||||
hSourceHandle = Ppb->StandardError;
|
||||
break;
|
||||
}
|
||||
hSourceHandle = TranslateStdHandle(hSourceHandle);
|
||||
|
||||
if (IsConsoleHandle(hSourceHandle))
|
||||
{
|
||||
|
|
|
@ -41,29 +41,7 @@ WaitForSingleObjectEx(IN HANDLE hHandle,
|
|||
NTSTATUS Status;
|
||||
|
||||
/* Get real handle */
|
||||
switch ((ULONG)hHandle)
|
||||
{
|
||||
/* Input handle */
|
||||
case STD_INPUT_HANDLE:
|
||||
|
||||
/* Read it from the PEB */
|
||||
hHandle = NtCurrentPeb()->ProcessParameters->StandardInput;
|
||||
break;
|
||||
|
||||
/* Output handle */
|
||||
case STD_OUTPUT_HANDLE:
|
||||
|
||||
/* Read it from the PEB */
|
||||
hHandle = NtCurrentPeb()->ProcessParameters->StandardOutput;
|
||||
break;
|
||||
|
||||
/* Error handle */
|
||||
case STD_ERROR_HANDLE:
|
||||
|
||||
/* Read it from the PEB */
|
||||
hHandle = NtCurrentPeb()->ProcessParameters->StandardError;
|
||||
break;
|
||||
}
|
||||
hHandle = TranslateStdHandle(hHandle);
|
||||
|
||||
/* Check for console handle */
|
||||
if ((IsConsoleHandle(hHandle)) && (VerifyConsoleIoHandle(hHandle)))
|
||||
|
@ -163,26 +141,7 @@ WaitForMultipleObjectsEx(IN DWORD nCount,
|
|||
for (i = 0; i < nCount; i++)
|
||||
{
|
||||
/* Check what kind of handle this is */
|
||||
switch ((ULONG)HandleBuffer[i])
|
||||
{
|
||||
/* Input handle */
|
||||
case STD_INPUT_HANDLE:
|
||||
HandleBuffer[i] = NtCurrentPeb()->
|
||||
ProcessParameters->StandardInput;
|
||||
break;
|
||||
|
||||
/* Output handle */
|
||||
case STD_OUTPUT_HANDLE:
|
||||
HandleBuffer[i] = NtCurrentPeb()->
|
||||
ProcessParameters->StandardOutput;
|
||||
break;
|
||||
|
||||
/* Error handle */
|
||||
case STD_ERROR_HANDLE:
|
||||
HandleBuffer[i] = NtCurrentPeb()->
|
||||
ProcessParameters->StandardError;
|
||||
break;
|
||||
}
|
||||
HandleBuffer[i] = TranslateStdHandle(HandleBuffer[i]);
|
||||
|
||||
/* Check for console handle */
|
||||
if ((IsConsoleHandle(HandleBuffer[i])) &&
|
||||
|
@ -249,32 +208,7 @@ SignalObjectAndWait(IN HANDLE hObjectToSignal,
|
|||
NTSTATUS Status;
|
||||
|
||||
/* Get real handle */
|
||||
switch ((ULONG)hObjectToWaitOn)
|
||||
{
|
||||
/* Input handle */
|
||||
case STD_INPUT_HANDLE:
|
||||
|
||||
/* Read it from the PEB */
|
||||
hObjectToWaitOn = NtCurrentPeb()->
|
||||
ProcessParameters->StandardInput;
|
||||
break;
|
||||
|
||||
/* Output handle */
|
||||
case STD_OUTPUT_HANDLE:
|
||||
|
||||
/* Read it from the PEB */
|
||||
hObjectToWaitOn = NtCurrentPeb()->
|
||||
ProcessParameters->StandardOutput;
|
||||
break;
|
||||
|
||||
/* Error handle */
|
||||
case STD_ERROR_HANDLE:
|
||||
|
||||
/* Read it from the PEB */
|
||||
hObjectToWaitOn = NtCurrentPeb()->
|
||||
ProcessParameters->StandardError;
|
||||
break;
|
||||
}
|
||||
hObjectToWaitOn = TranslateStdHandle(hObjectToWaitOn);
|
||||
|
||||
/* Check for console handle */
|
||||
if ((IsConsoleHandle(hObjectToWaitOn)) &&
|
||||
|
|
Loading…
Reference in a new issue