Author: jmorlan
Date: Mon Aug 4 12:08:52 2008
New Revision: 35109
URL:
http://svn.reactos.org/svn/reactos?rev=35109&view=rev
Log:
- 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.
Modified:
trunk/reactos/dll/win32/kernel32/file/file.c
trunk/reactos/dll/win32/kernel32/file/rw.c
trunk/reactos/dll/win32/kernel32/include/kernel32.h
trunk/reactos/dll/win32/kernel32/misc/handle.c
trunk/reactos/dll/win32/kernel32/synch/wait.c
Modified: trunk/reactos/dll/win32/kernel32/file/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/file/fi…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/file/file.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/file/file.c [iso-8859-1] Mon Aug 4 12:08:52 2008
@@ -352,6 +352,8 @@
{
NTSTATUS errCode;
IO_STATUS_BLOCK IoStatusBlock;
+
+ hFile = TranslateStdHandle(hFile);
if (IsConsoleHandle(hFile))
{
@@ -561,20 +563,7 @@
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))
Modified: trunk/reactos/dll/win32/kernel32/file/rw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/file/rw…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/file/rw.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/file/rw.c [iso-8859-1] Mon Aug 4 12:08:52 2008
@@ -37,6 +37,8 @@
*lpNumberOfBytesWritten = 0;
}
+ hFile = TranslateStdHandle(hFile);
+
if (IsConsoleHandle(hFile))
{
return WriteConsoleA(hFile,
@@ -141,6 +143,8 @@
{
*lpNumberOfBytesRead = 0;
}
+
+ hFile = TranslateStdHandle(hFile);
if (IsConsoleHandle(hFile))
{
Modified: trunk/reactos/dll/win32/kernel32/include/kernel32.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Mon Aug 4 12:08:52
2008
@@ -72,6 +72,8 @@
DWORD dwShareMode);
PTEB GetTeb(VOID);
+
+HANDLE FASTCALL TranslateStdHandle(HANDLE hHandle);
PWCHAR FilenameA2W(LPCSTR NameA, BOOL alloc);
Modified: trunk/reactos/dll/win32/kernel32/misc/handle.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ha…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/handle.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/handle.c [iso-8859-1] Mon Aug 4 12:08:52 2008
@@ -26,6 +26,21 @@
/* 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 @@
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 @@
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 @@
* 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 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))
{
Modified: trunk/reactos/dll/win32/kernel32/synch/wait.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/synch/w…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/synch/wait.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/synch/wait.c [iso-8859-1] Mon Aug 4 12:08:52 2008
@@ -41,29 +41,7 @@
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 @@
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 @@
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)) &&