dc43a11c3c2cf35d3204c42ebb71200d7f18c76b
[reactos.git] / reactos / lib / kernel32 / misc / handle.c
1 /* $Id: handle.c,v 1.5 2000/07/01 17:07:00 ea Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/handle.c
6 * PURPOSE: Object functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 /* INCLUDES ******************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <windows.h>
16
17 #define NDEBUG
18 #include <kernel32/kernel32.h>
19 #include <kernel32/error.h>
20
21 /* FUNCTIONS *****************************************************************/
22
23 WINBOOL WINAPI GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
24 {
25 OBJECT_DATA_INFORMATION HandleInfo;
26 ULONG BytesWritten;
27 NTSTATUS errCode;
28
29 errCode = NtQueryObject(hObject,
30 ObjectDataInformation,
31 &HandleInfo,
32 sizeof(OBJECT_DATA_INFORMATION),
33 &BytesWritten);
34 if (!NT_SUCCESS(errCode))
35 {
36 SetLastErrorByStatus (errCode);
37 return FALSE;
38 }
39 if ( HandleInfo.bInheritHandle )
40 *lpdwFlags &= HANDLE_FLAG_INHERIT;
41 if ( HandleInfo.bProtectFromClose )
42 *lpdwFlags &= HANDLE_FLAG_PROTECT_FROM_CLOSE;
43 return TRUE;
44 }
45
46
47 WINBOOL STDCALL SetHandleInformation(HANDLE hObject,
48 DWORD dwMask,
49 DWORD dwFlags)
50 {
51 OBJECT_DATA_INFORMATION HandleInfo;
52 NTSTATUS errCode;
53 ULONG BytesWritten;
54
55 errCode = NtQueryObject(hObject,
56 ObjectDataInformation,
57 &HandleInfo,
58 sizeof(OBJECT_DATA_INFORMATION),
59 &BytesWritten);
60 if (!NT_SUCCESS(errCode))
61 {
62 SetLastErrorByStatus (errCode);
63 return FALSE;
64 }
65 if (dwMask & HANDLE_FLAG_INHERIT)
66 {
67 HandleInfo.bInheritHandle = TRUE;
68 }
69 if (dwMask & HANDLE_FLAG_PROTECT_FROM_CLOSE)
70 {
71 HandleInfo.bProtectFromClose = TRUE;
72 }
73
74 errCode = NtSetInformationObject(hObject,
75 ObjectDataInformation,
76 &HandleInfo,
77 sizeof(OBJECT_DATA_INFORMATION));
78 if (!NT_SUCCESS(errCode))
79 {
80 SetLastErrorByStatus (errCode);
81 return FALSE;
82 }
83
84 return TRUE;
85 }
86
87
88 WINBOOL STDCALL CloseHandle(HANDLE hObject)
89 /*
90 * FUNCTION: Closes an open object handle
91 * PARAMETERS:
92 * hObject = Identifies an open object handle
93 * RETURNS: If the function succeeds, the return value is nonzero
94 * If the function fails, the return value is zero
95 */
96 {
97 NTSTATUS errCode;
98
99 if (IsConsoleHandle(hObject))
100 {
101 return(CloseConsoleHandle(hObject));
102 }
103
104 errCode = NtClose(hObject);
105 if (!NT_SUCCESS(errCode))
106 {
107 SetLastErrorByStatus (errCode);
108 return FALSE;
109 }
110
111 return TRUE;
112 }
113
114
115 WINBOOL STDCALL DuplicateHandle(HANDLE hSourceProcessHandle,
116 HANDLE hSourceHandle,
117 HANDLE hTargetProcessHandle,
118 LPHANDLE lpTargetHandle,
119 DWORD dwDesiredAccess,
120 BOOL bInheritHandle,
121 DWORD dwOptions)
122 {
123 NTSTATUS errCode;
124
125 errCode = NtDuplicateObject(hSourceProcessHandle,
126 hSourceHandle,
127 hTargetProcessHandle,
128 lpTargetHandle,
129 dwDesiredAccess,
130 (BOOLEAN)bInheritHandle,
131 dwOptions);
132 if (!NT_SUCCESS(errCode))
133 {
134 SetLastErrorByStatus (errCode);
135 return FALSE;
136 }
137
138 return TRUE;
139 }
140
141 UINT STDCALL SetHandleCount(UINT nCount)
142 {
143 return(nCount);
144 }
145
146
147 /* EOF */