diff --git a/reactos/lib/kernel32/misc/handle.c b/reactos/lib/kernel32/misc/handle.c index 081229d49b2..29bf2639ca8 100644 --- a/reactos/lib/kernel32/misc/handle.c +++ b/reactos/lib/kernel32/misc/handle.c @@ -1,4 +1,4 @@ -/* $Id: handle.c,v 1.16 2004/01/23 21:16:03 ekohl Exp $ +/* $Id: handle.c,v 1.17 2004/10/03 10:05:56 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -36,28 +36,48 @@ 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->hStdInput; + break; + case STD_OUTPUT_HANDLE: + hObject = Ppb->hStdOutput; + break; + case STD_ERROR_HANDLE: + hObject = Ppb->hStdError; + break; + } Status = NtQueryObject (hObject, ObjectHandleInformation, &HandleInfo, sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION), &BytesWritten); - if (!NT_SUCCESS(Status)) - { - SetLastErrorByStatus (Status); - return FALSE; - } + if (NT_SUCCESS(Status)) + { + Flags = 0; + if (HandleInfo.Inherit) + Flags |= HANDLE_FLAG_INHERIT; + if (HandleInfo.ProtectFromClose) + Flags |= HANDLE_FLAG_PROTECT_FROM_CLOSE; - if (HandleInfo.Inherit) - *lpdwFlags &= HANDLE_FLAG_INHERIT; + *lpdwFlags = Flags; - if (HandleInfo.ProtectFromClose) - *lpdwFlags &= HANDLE_FLAG_PROTECT_FROM_CLOSE; - - return TRUE; + return TRUE; + } + else + { + SetLastErrorByStatus (Status); + return FALSE; + } } @@ -69,42 +89,51 @@ 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->hStdInput; + break; + case STD_OUTPUT_HANDLE: + hObject = Ppb->hStdOutput; + break; + case STD_ERROR_HANDLE: + hObject = Ppb->hStdError; + break; + } + Status = NtQueryObject (hObject, ObjectHandleInformation, &HandleInfo, sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION), &BytesWritten); - if (!NT_SUCCESS(Status)) + if (NT_SUCCESS(Status)) + { + HandleInfo.Inherit = ((dwFlags & HANDLE_FLAG_INHERIT) ? TRUE : FALSE); + HandleInfo.ProtectFromClose = ((dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE) ? TRUE : FALSE); + Status = NtSetInformationObject (hObject, + ObjectHandleInformation, + &HandleInfo, + sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION)); + if(!NT_SUCCESS(Status)) { SetLastErrorByStatus (Status); return FALSE; } - - if (dwMask & HANDLE_FLAG_INHERIT) - { - HandleInfo.Inherit = dwFlags & HANDLE_FLAG_INHERIT; - } - - if (dwMask & HANDLE_FLAG_PROTECT_FROM_CLOSE) - { - HandleInfo.ProtectFromClose = dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE; - } - - Status = NtSetInformationObject (hObject, - ObjectHandleInformation, - &HandleInfo, - sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION)); - if (!NT_SUCCESS(Status)) - { - SetLastErrorByStatus (Status); - return FALSE; - } - - return TRUE; + + return TRUE; + } + else + { + SetLastErrorByStatus (Status); + return FALSE; + } } @@ -120,17 +149,32 @@ BOOL STDCALL CloseHandle(HANDLE hObject) * If the function fails, the return value is zero */ { - NTSTATUS errCode; + PRTL_USER_PROCESS_PARAMETERS Ppb; + NTSTATUS Status; + + Ppb = NtCurrentPeb()->ProcessParameters; + switch ((ULONG)hObject) + { + case STD_INPUT_HANDLE: + hObject = Ppb->hStdInput; + break; + case STD_OUTPUT_HANDLE: + hObject = Ppb->hStdOutput; + break; + case STD_ERROR_HANDLE: + hObject = Ppb->hStdError; + break; + } if (IsConsoleHandle(hObject)) { return(CloseConsoleHandle(hObject)); } - errCode = NtClose(hObject); - if (!NT_SUCCESS(errCode)) + Status = NtClose(hObject); + if (!NT_SUCCESS(Status)) { - SetLastErrorByStatus (errCode); + SetLastErrorByStatus (Status); return FALSE; } @@ -149,8 +193,24 @@ BOOL STDCALL DuplicateHandle(HANDLE hSourceProcessHandle, BOOL bInheritHandle, DWORD dwOptions) { - NTSTATUS errCode; + PRTL_USER_PROCESS_PARAMETERS Ppb; DWORD SourceProcessId, TargetProcessId; + NTSTATUS Status; + + Ppb = NtCurrentPeb()->ProcessParameters; + switch ((ULONG)hSourceHandle) + { + case STD_INPUT_HANDLE: + hSourceHandle = Ppb->hStdInput; + break; + case STD_OUTPUT_HANDLE: + hSourceHandle = Ppb->hStdOutput; + break; + case STD_ERROR_HANDLE: + hSourceHandle = Ppb->hStdError; + break; + } + if (IsConsoleHandle(hSourceHandle)) { if (FALSE == InternalGetProcessId(hSourceProcessHandle, &SourceProcessId) || @@ -166,16 +226,16 @@ BOOL STDCALL DuplicateHandle(HANDLE hSourceProcessHandle, return *lpTargetHandle != INVALID_HANDLE_VALUE ? TRUE : FALSE; } - errCode = NtDuplicateObject(hSourceProcessHandle, - hSourceHandle, - hTargetProcessHandle, - lpTargetHandle, - dwDesiredAccess, - (BOOLEAN)bInheritHandle, - dwOptions); - if (!NT_SUCCESS(errCode)) + Status = NtDuplicateObject(hSourceProcessHandle, + hSourceHandle, + hTargetProcessHandle, + lpTargetHandle, + dwDesiredAccess, + (BOOLEAN)bInheritHandle, + dwOptions); + if (!NT_SUCCESS(Status)) { - SetLastErrorByStatus (errCode); + SetLastErrorByStatus (Status); return FALSE; }