reshuffling of dlls
[reactos.git] / reactos / lib / kernel32 / synch / event.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/synch/event.c
6 * PURPOSE: Local string functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <k32.h>
15
16 #define NDEBUG
17 #include "../include/debug.h"
18
19
20 /* FUNCTIONS ****************************************************************/
21
22 /*
23 * @implemented
24 */
25 HANDLE STDCALL
26 CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
27 BOOL bManualReset,
28 BOOL bInitialState,
29 LPCSTR lpName)
30 {
31 UNICODE_STRING EventNameU;
32 ANSI_STRING EventName;
33 HANDLE EventHandle;
34
35 if (lpName)
36 {
37 RtlInitAnsiString(&EventName,
38 (LPSTR)lpName);
39 RtlAnsiStringToUnicodeString(&EventNameU,
40 &EventName,
41 TRUE);
42 }
43
44 EventHandle = CreateEventW(lpEventAttributes,
45 bManualReset,
46 bInitialState,
47 (lpName ? EventNameU.Buffer : NULL));
48
49 if (lpName)
50 {
51 RtlFreeUnicodeString(&EventNameU);
52 }
53
54 return EventHandle;
55 }
56
57
58 /*
59 * @implemented
60 */
61 HANDLE STDCALL
62 CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes,
63 BOOL bManualReset,
64 BOOL bInitialState,
65 LPCWSTR lpName)
66 {
67 NTSTATUS Status;
68 HANDLE hEvent;
69 UNICODE_STRING UnicodeName;
70 OBJECT_ATTRIBUTES ObjectAttributes;
71
72 if (lpName != NULL)
73 {
74 RtlInitUnicodeString(&UnicodeName, (LPWSTR)lpName);
75 }
76
77 InitializeObjectAttributes(&ObjectAttributes,
78 (lpName ? &UnicodeName : NULL),
79 0,
80 (lpName ? hBaseDir : NULL),
81 NULL);
82
83 if (lpEventAttributes != NULL)
84 {
85 ObjectAttributes.SecurityDescriptor = lpEventAttributes->lpSecurityDescriptor;
86 if (lpEventAttributes->bInheritHandle)
87 {
88 ObjectAttributes.Attributes |= OBJ_INHERIT;
89 }
90 }
91
92 Status = NtCreateEvent(&hEvent,
93 EVENT_ALL_ACCESS,
94 &ObjectAttributes,
95 (bManualReset ? NotificationEvent : SynchronizationEvent),
96 bInitialState);
97 DPRINT( "Called\n" );
98 if (!NT_SUCCESS(Status))
99 {
100 SetLastErrorByStatus(Status);
101 return NULL;
102 }
103
104 return hEvent;
105 }
106
107
108 /*
109 * @implemented
110 */
111 HANDLE STDCALL
112 OpenEventA(DWORD dwDesiredAccess,
113 BOOL bInheritHandle,
114 LPCSTR lpName)
115 {
116 UNICODE_STRING EventNameU;
117 ANSI_STRING EventName;
118 HANDLE EventHandle;
119
120 if (lpName == NULL)
121 {
122 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
123 return NULL;
124 }
125
126 RtlInitUnicodeString(&EventNameU,
127 NULL);
128
129 RtlInitAnsiString(&EventName,
130 (LPSTR)lpName);
131 RtlAnsiStringToUnicodeString(&EventNameU,
132 &EventName,
133 TRUE);
134
135 EventHandle = OpenEventW(dwDesiredAccess,
136 bInheritHandle,
137 EventNameU.Buffer);
138
139 RtlFreeUnicodeString(&EventNameU);
140
141 return EventHandle;
142 }
143
144
145 /*
146 * @implemented
147 */
148 HANDLE STDCALL
149 OpenEventW(DWORD dwDesiredAccess,
150 BOOL bInheritHandle,
151 LPCWSTR lpName)
152 {
153 OBJECT_ATTRIBUTES ObjectAttributes;
154 UNICODE_STRING EventNameString;
155 NTSTATUS Status;
156 HANDLE hEvent = NULL;
157
158 if (lpName == NULL)
159 {
160 SetLastError(ERROR_INVALID_PARAMETER);
161 return NULL;
162 }
163
164 RtlInitUnicodeString(&EventNameString, (LPWSTR)lpName);
165
166 InitializeObjectAttributes(&ObjectAttributes,
167 &EventNameString,
168 (bInheritHandle ? OBJ_INHERIT : 0),
169 hBaseDir,
170 NULL);
171
172 Status = NtOpenEvent(&hEvent,
173 dwDesiredAccess,
174 &ObjectAttributes);
175 if (!NT_SUCCESS(Status))
176 {
177 SetLastErrorByStatus(Status);
178 return NULL;
179 }
180
181 return hEvent;
182 }
183
184
185 /*
186 * @implemented
187 */
188 BOOL STDCALL
189 PulseEvent(HANDLE hEvent)
190 {
191 NTSTATUS Status;
192
193 Status = NtPulseEvent(hEvent, NULL);
194 if (!NT_SUCCESS(Status))
195 {
196 SetLastErrorByStatus (Status);
197 return FALSE;
198 }
199
200 return TRUE;
201 }
202
203
204 /*
205 * @implemented
206 */
207 BOOL STDCALL
208 ResetEvent(HANDLE hEvent)
209 {
210 NTSTATUS Status;
211
212 Status = NtClearEvent(hEvent);
213 if (!NT_SUCCESS(Status))
214 {
215 SetLastErrorByStatus(Status);
216 return FALSE;
217 }
218
219 return TRUE;
220 }
221
222
223 /*
224 * @implemented
225 */
226 BOOL STDCALL
227 SetEvent(HANDLE hEvent)
228 {
229 NTSTATUS Status;
230
231 Status = NtSetEvent(hEvent, NULL);
232 if (!NT_SUCCESS(Status))
233 {
234 SetLastErrorByStatus(Status);
235 return FALSE;
236 }
237
238 return TRUE;
239 }
240
241 /* EOF */