Fixed header inclusion order.
[reactos.git] / reactos / lib / kernel32 / synch / event.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/kernel32/synch/event.c
5 * PURPOSE: Local string functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 * Created 01/11/98
9 */
10
11 #include <ddk/ntddk.h>
12 #include <windows.h>
13 #include <wchar.h>
14
15
16 WINBOOL
17 STDCALL
18 SetEvent(
19 HANDLE hEvent
20 )
21 {
22 NTSTATUS errCode;
23 ULONG Count;
24 errCode = NtSetEvent(hEvent,&Count);
25 if ( !NT_SUCCESS(errCode) ) {
26 SetLastError(RtlNtStatusToDosError(errCode));
27 return FALSE;
28 }
29 return TRUE;
30 }
31
32 WINBOOL
33 STDCALL
34 ResetEvent(
35 HANDLE hEvent
36 )
37 {
38 NTSTATUS errCode;
39 ULONG Count;
40 errCode = NtResetEvent(hEvent, &Count);
41 if ( !NT_SUCCESS(errCode) ) {
42 SetLastError(RtlNtStatusToDosError(errCode));
43 return FALSE;
44 }
45 return TRUE;
46 }
47
48
49
50 HANDLE
51 STDCALL
52 CreateEventW(
53 LPSECURITY_ATTRIBUTES lpEventAttributes,
54 WINBOOL bManualReset,
55 WINBOOL bInitialState,
56 LPCWSTR lpName
57 )
58 {
59 NTSTATUS errCode;
60 HANDLE hEvent;
61 UNICODE_STRING EventNameString;
62 OBJECT_ATTRIBUTES ObjectAttributes;
63 ObjectAttributes.Attributes = 0;
64 if ( lpEventAttributes != NULL ) {
65 ObjectAttributes.SecurityDescriptor = lpEventAttributes->lpSecurityDescriptor;
66 if ( lpEventAttributes->bInheritHandle == TRUE )
67 ObjectAttributes.Attributes |= OBJ_INHERIT;
68
69 }
70
71
72 if(lpName != NULL) {
73 EventNameString.Buffer = (WCHAR *)lpName;
74 EventNameString.Length = lstrlenW(lpName)*sizeof(WCHAR);
75 EventNameString.MaximumLength = EventNameString.Length;
76 ObjectAttributes.ObjectName = &EventNameString;
77 }
78 else
79 ObjectAttributes.ObjectName = NULL;
80
81
82
83 errCode = NtCreateEvent(&hEvent,STANDARD_RIGHTS_ALL|EVENT_READ_ACCESS|EVENT_WRITE_ACCESS,&ObjectAttributes,bManualReset,bInitialState);
84 if(!NT_SUCCESS(errCode)) {
85 SetLastError(RtlNtStatusToDosError(errCode));
86 return NULL;
87 }
88
89
90 return hEvent;
91 }
92
93
94 HANDLE
95 STDCALL
96 OpenEventW(
97 DWORD dwDesiredAccess,
98 WINBOOL bInheritHandle,
99 LPCWSTR lpName
100 )
101 {
102 OBJECT_ATTRIBUTES ObjectAttributes;
103 UNICODE_STRING EventNameString;
104 NTSTATUS errCode;
105 HANDLE hEvent = NULL;
106
107 if(lpName == NULL) {
108 SetLastError(ERROR_INVALID_PARAMETER);
109 return NULL;
110 }
111
112 ObjectAttributes.Attributes = 0;
113 ObjectAttributes.SecurityDescriptor = NULL;
114 EventNameString.Buffer = (WCHAR *)lpName;
115 EventNameString.Length = lstrlenW(lpName)*sizeof(WCHAR);
116 EventNameString.MaximumLength = EventNameString.Length;
117 ObjectAttributes.ObjectName = &EventNameString;
118
119 if (bInheritHandle == TRUE )
120 ObjectAttributes.Attributes |= OBJ_INHERIT;
121
122
123 errCode = NtOpenEvent(hEvent,dwDesiredAccess,&ObjectAttributes);
124 if ( !NT_SUCCESS(errCode) ) {
125 SetLastError(RtlNtStatusToDosError(errCode));
126 return NULL;
127 }
128
129 return hEvent;
130 }
131
132
133 HANDLE
134 STDCALL
135 CreateEventA(
136 LPSECURITY_ATTRIBUTES lpEventAttributes,
137 WINBOOL bManualReset,
138 WINBOOL bInitialState,
139 LPCSTR lpName
140 )
141 {
142 int i;
143 WCHAR EventNameW[MAX_PATH];
144 i = 0;
145 while ((*lpName)!=0 && i < MAX_PATH)
146 {
147 EventNameW[i] = *lpName;
148 lpName++;
149 i++;
150 }
151 EventNameW[i] = 0;
152
153 return CreateEventW(lpEventAttributes,bManualReset,bInitialState,EventNameW);
154 }
155
156
157 HANDLE
158 STDCALL
159 OpenEventA(
160 DWORD dwDesiredAccess,
161 WINBOOL bInheritHandle,
162 LPCSTR lpName
163 )
164 {
165 ULONG i;
166 WCHAR EventNameW[MAX_PATH];
167
168
169
170 i = 0;
171 while ((*lpName)!=0 && i < MAX_PATH)
172 {
173 EventNameW[i] = *lpName;
174 lpName++;
175 i++;
176 }
177 EventNameW[i] = 0;
178
179
180 return OpenEventW(dwDesiredAccess,bInheritHandle,EventNameW);
181 }
182
183 WINBOOL
184 STDCALL
185 PulseEvent(
186 HANDLE hEvent
187 )
188 {
189 ULONG Count;
190 NTSTATUS errCode;
191 errCode = NtPulseEvent(hEvent,&Count);
192 if ( !NT_SUCCESS(errCode) ) {
193 SetLastError(RtlNtStatusToDosError(errCode));
194 return FALSE;
195 }
196 return TRUE;
197 }