Increased buffers for DateToStr() because localized
[AROS-Contrib.git] / regina / regutil / regsem.c
blob28472fe6a1447261280073e26d5b96c3f5816ec0
1 /* NT semaphore functions for regutil
3 * The contents of this file are subject to the Mozilla Public License
4 * Version 1.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 * http://www.mozilla.org/MPL/
8 * Software distributed under the License is distributed on an "AS IS"
9 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10 * License for the specific language governing rights and limitations
11 * under the License.
13 * The Original Code is regutil.
15 * The Initial Developer of the Original Code is Patrick TJ McPhee.
16 * Portions created by Patrick McPhee are Copyright © 1998, 2001
17 * Patrick TJ McPhee. All Rights Reserved.
19 * Contributors:
21 * $Header: /opt/cvs/Regina/regutil/regsem.c,v 1.1 2009/10/07 07:51:59 mark Exp $
23 #include "regutil.h"
24 #include <windows.h>
26 /* ******************************************************************** */
27 /* **************************** Semaphores **************************** */
28 /* ******************************************************************** */
29 static const char notimp[] = "not implemented";
30 #define what() memcpy(result->strptr, notimp, sizeof(notimp)-1), result->strlength = sizeof(notimp)-1
32 /* syscloseeventsem(handle) */
33 rxfunc(syscloseeventsem)
35 HANDLE semid;
37 checkparam(1,1);
39 if (argv[0].strlength != sizeof(semid))
40 return BADGENERAL;
42 memcpy(&semid, argv[0].strptr, sizeof(semid));
44 CloseHandle(semid);
45 result->strlength = sprintf(result->strptr, "%d", GetLastError());
47 return 0;
50 /* sysclosemutexsem(handle) */
51 rxfunc(sysclosemutexsem)
53 return syscloseeventsem(fname, argc, argv, pSomething, result);
56 /* syscreateeventsem([name],[manual_reset]) */
57 rxfunc(syscreateeventsem)
59 char *name, *manual;
60 HANDLE event;
61 BOOL bManual = FALSE;
63 checkparam(0,2);
65 if (argc > 0 && argv[0].strlength) {
66 rxstrdup(name, argv[0]);
68 else
69 name = NULL;
71 if (argc > 1 && argv[1].strlength)
72 rxstrdup(manual, argv[1]);
73 else
74 manual = NULL;
76 /* docs suggest the fact that this argument exists means the semaphore
77 * should be manual-reset */
78 if (manual && !stricmp(manual, "yes"))
79 bManual = TRUE;
80 else
81 bManual = FALSE;
83 event = CreateEvent(NULL, bManual, FALSE, name);
85 if (event) {
86 result->strlength = sizeof(event);
87 memcpy(result->strptr, &event, sizeof(event));
90 else {
91 result->strlength = 0;
94 return 0;
97 /* syscreatemutexsem([name]) */
98 rxfunc(syscreatemutexsem)
100 HANDLE mutex;
101 char * name;
103 if (argc > 0 && argv[0].strlength) {
104 rxstrdup(name, argv[0]);
106 else
107 name = NULL;
109 mutex = CreateMutex(NULL, FALSE, name);
111 if (mutex) {
112 result->strlength = sizeof(mutex);
113 memcpy(result->strptr, &mutex, sizeof(mutex));
115 else {
116 result->strlength = 0;
119 return 0;
123 /* sysopeneventsem(name) */
124 rxfunc(sysopeneventsem)
126 HANDLE event;
127 char * name;
129 checkparam(1,1);
131 rxstrdup(name, argv[0]);
133 event = OpenEvent(EVENT_ALL_ACCESS, FALSE, name);
135 if (event) {
136 result->strlength = sizeof(event);
137 memcpy(result->strptr, &event, sizeof(event));
139 else {
140 result_zero();
143 return 0;
147 /* sysopenmutexsem(name) */
148 rxfunc(sysopenmutexsem)
150 HANDLE mutex;
151 char * name;
153 checkparam(1,1);
155 rxstrdup(name, argv[0]);
157 mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name);
159 if (mutex) {
160 result->strlength = sizeof(mutex);
161 memcpy(result->strptr, &mutex, sizeof(mutex));
163 else {
164 result_zero();
167 return 0;
170 /* sysposteventsem(handle) */
171 rxfunc(sysposteventsem)
173 HANDLE event;
175 checkparam(1,1);
177 memcpy(&event, argv[0].strptr, sizeof(event));
179 SetEvent(event);
181 result->strlength = sprintf(result->strptr, "%d", GetLastError());
183 return 0;
186 /* syspulseeventsem(handle) */
187 rxfunc(syspulseeventsem)
189 HANDLE event;
191 checkparam(1,1);
193 memcpy(&event, argv[0].strptr, sizeof(event));
195 PulseEvent(event);
197 result->strlength = sprintf(result->strptr, "%d", GetLastError());
199 return 0;
203 /* sysreleasemutexsem(handle) */
204 rxfunc(sysreleasemutexsem)
206 HANDLE mutex;
208 checkparam(1,1);
210 memcpy(&mutex, argv[0].strptr, sizeof(mutex));
212 ReleaseMutex(mutex);
214 result->strlength = sprintf(result->strptr, "%d", GetLastError());
216 return 0;
219 /* sysrequestmutexsem(handle, [timeout]) */
220 rxfunc(sysrequestmutexsem)
222 HANDLE mutex;
223 char * timeout;
224 DWORD mtimeout;
225 int rc;
227 checkparam(1,2);
229 memcpy(&mutex, argv[0].strptr, sizeof(mutex));
231 if (argc > 1) {
232 rxstrdup(timeout, argv[1]);
233 mtimeout = atoi(timeout);
235 else {
236 mtimeout = INFINITE;
239 rc = WaitForSingleObject(mutex, mtimeout);
241 result->strlength = sprintf(result->strptr, "%d", rc);
243 return 0;
246 /* sysreseteventsem(handle) */
247 rxfunc(sysreseteventsem)
249 HANDLE event;
251 checkparam(1,1);
253 memcpy(&event, argv[0].strptr, sizeof(event));
255 ResetEvent(event);
257 result->strlength = sprintf(result->strptr, "%d", GetLastError());
259 return 0;
262 /* syswaiteventsem(handle, [timeout]) */
263 rxfunc(syswaiteventsem)
265 HANDLE event;
266 int rc, mtimeout;
267 char * timeout;
269 checkparam(1,2);
271 memcpy(&event, argv[0].strptr, sizeof(event));
273 if (argc > 1) {
274 rxstrdup(timeout, argv[1]);
275 mtimeout = atoi(timeout);
277 else {
278 mtimeout = INFINITE;
281 rc = WaitForSingleObject(event, mtimeout);
283 result->strlength = sprintf(result->strptr, "%d", rc);
285 return 0;