reactos/lib/kernel32/misc
diff -u -r1.16 -r1.17
--- handle.c 23 Jan 2004 21:16:03 -0000 1.16
+++ handle.c 3 Oct 2004 10:05:56 -0000 1.17
@@ -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 @@
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 (HandleInfo.Inherit)
- *lpdwFlags &= HANDLE_FLAG_INHERIT;
-
- if (HandleInfo.ProtectFromClose)
- *lpdwFlags &= HANDLE_FLAG_PROTECT_FROM_CLOSE;
-
- return TRUE;
+ if (NT_SUCCESS(Status))
+ {
+ Flags = 0;
+ if (HandleInfo.Inherit)
+ Flags |= HANDLE_FLAG_INHERIT;
+ if (HandleInfo.ProtectFromClose)
+ Flags |= HANDLE_FLAG_PROTECT_FROM_CLOSE;
+
+ *lpdwFlags = Flags;
+
+ return TRUE;
+ }
+ else
+ {
+ SetLastErrorByStatus (Status);
+ return FALSE;
+ }
}
@@ -69,42 +89,51 @@
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 @@
* 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 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 @@
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;
}