4 * Copyright 1998 Alexandre Julliard
13 /***********************************************************************
14 * CreateSemaphore32A (KERNEL32.174)
16 HANDLE WINAPI
CreateSemaphoreA( SECURITY_ATTRIBUTES
*sa
, LONG initial
, LONG max
, LPCSTR name
)
18 struct create_semaphore_request
*req
= get_req_buffer();
20 /* Check parameters */
22 if ((max
<= 0) || (initial
< 0) || (initial
> max
))
24 SetLastError( ERROR_INVALID_PARAMETER
);
28 req
->initial
= (unsigned int)initial
;
29 req
->max
= (unsigned int)max
;
30 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
31 server_strcpyAtoW( req
->name
, name
);
33 server_call( REQ_CREATE_SEMAPHORE
);
34 if (req
->handle
== -1) return 0;
39 /***********************************************************************
40 * CreateSemaphore32W (KERNEL32.175)
42 HANDLE WINAPI
CreateSemaphoreW( SECURITY_ATTRIBUTES
*sa
, LONG initial
,
43 LONG max
, LPCWSTR name
)
45 struct create_semaphore_request
*req
= get_req_buffer();
47 /* Check parameters */
49 if ((max
<= 0) || (initial
< 0) || (initial
> max
))
51 SetLastError( ERROR_INVALID_PARAMETER
);
55 req
->initial
= (unsigned int)initial
;
56 req
->max
= (unsigned int)max
;
57 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
58 server_strcpyW( req
->name
, name
);
60 server_call( REQ_CREATE_SEMAPHORE
);
61 if (req
->handle
== -1) return 0;
66 /***********************************************************************
67 * OpenSemaphore32A (KERNEL32.545)
69 HANDLE WINAPI
OpenSemaphoreA( DWORD access
, BOOL inherit
, LPCSTR name
)
71 struct open_semaphore_request
*req
= get_req_buffer();
74 req
->inherit
= inherit
;
75 server_strcpyAtoW( req
->name
, name
);
76 server_call( REQ_OPEN_SEMAPHORE
);
77 if (req
->handle
== -1) return 0; /* must return 0 on failure, not -1 */
82 /***********************************************************************
83 * OpenSemaphore32W (KERNEL32.546)
85 HANDLE WINAPI
OpenSemaphoreW( DWORD access
, BOOL inherit
, LPCWSTR name
)
87 struct open_semaphore_request
*req
= get_req_buffer();
90 req
->inherit
= inherit
;
91 server_strcpyW( req
->name
, name
);
92 server_call( REQ_OPEN_SEMAPHORE
);
93 if (req
->handle
== -1) return 0; /* must return 0 on failure, not -1 */
98 /***********************************************************************
99 * ReleaseSemaphore (KERNEL32.583)
101 BOOL WINAPI
ReleaseSemaphore( HANDLE handle
, LONG count
, LONG
*previous
)
104 struct release_semaphore_request
*req
= get_req_buffer();
108 SetLastError( ERROR_INVALID_PARAMETER
);
111 req
->handle
= handle
;
112 req
->count
= (unsigned int)count
;
113 if (!server_call( REQ_RELEASE_SEMAPHORE
))
115 if (previous
) *previous
= req
->prev_count
;