4 * Copyright 1998 Alexandre Julliard
14 /***********************************************************************
15 * CreateSemaphore32A (KERNEL32.174)
17 HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
19 struct create_semaphore_request *req = get_req_buffer();
21 /* Check parameters */
23 if ((max <= 0) || (initial < 0) || (initial > max))
25 SetLastError( ERROR_INVALID_PARAMETER );
29 req->initial = (unsigned int)initial;
30 req->max = (unsigned int)max;
31 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
32 lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
34 server_call( REQ_CREATE_SEMAPHORE );
35 if (req->handle == -1) return 0;
40 /***********************************************************************
41 * CreateSemaphore32W (KERNEL32.175)
43 HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
44 LONG max, LPCWSTR name )
46 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
47 HANDLE ret = CreateSemaphoreA( sa, initial, max, nameA );
48 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
53 /***********************************************************************
54 * OpenSemaphore32A (KERNEL32.545)
56 HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
58 struct open_semaphore_request *req = get_req_buffer();
61 req->inherit = inherit;
62 lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
63 server_call( REQ_OPEN_SEMAPHORE );
64 if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
69 /***********************************************************************
70 * OpenSemaphore32W (KERNEL32.546)
72 HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
74 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
75 HANDLE ret = OpenSemaphoreA( access, inherit, nameA );
76 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
81 /***********************************************************************
82 * ReleaseSemaphore (KERNEL32.583)
84 BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
86 struct release_semaphore_request *req = get_req_buffer();
90 SetLastError( ERROR_INVALID_PARAMETER );
94 req->count = (unsigned int)count;
95 if (server_call( REQ_RELEASE_SEMAPHORE )) return FALSE;
96 if (previous) *previous = req->prev_count;