mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-27 03:43:36 +00:00
* lib/kernel32/k32.h: New file. * lib/kernel32/makefile (TARGET_CFLAGS): Add -I./. (TARGET_PCH): Set to k32.h. * lib/kernel32/except/except.c: Use <k32.h>. * lib/kernel32/file/backup.c: Ditto. * lib/kernel32/file/cnotify.c: Ditto. * lib/kernel32/file/copy.c: Ditto. * lib/kernel32/file/create.c: Ditto. * lib/kernel32/file/curdir.c: Ditto. * lib/kernel32/file/delete.c: Ditto. * lib/kernel32/file/deviceio.c: Ditto. * lib/kernel32/file/dir.c: Ditto. * lib/kernel32/file/dosdev.c: Ditto. * lib/kernel32/file/file.c: Ditto. * lib/kernel32/file/find.c: Ditto. * lib/kernel32/file/iocompl.c: Ditto. * lib/kernel32/file/lfile.c: Ditto. * lib/kernel32/file/lock.c: Ditto. * lib/kernel32/file/mailslot.c: Ditto. * lib/kernel32/file/move.c: Ditto. * lib/kernel32/file/npipe.c: Ditto. * lib/kernel32/file/pipe.c: Ditto. * lib/kernel32/file/rw.c: Ditto. * lib/kernel32/file/tape.c: Ditto. * lib/kernel32/file/volume.c: Ditto. * lib/kernel32/mem/global.c: Ditto. * lib/kernel32/mem/heap.c: Ditto. * lib/kernel32/mem/isbad.c: Ditto. * lib/kernel32/mem/local.c: Ditto. * lib/kernel32/mem/procmem.c: Ditto. * lib/kernel32/mem/section.c: Ditto. * lib/kernel32/mem/virtual.c: Ditto. * lib/kernel32/misc/atom.c: Ditto. * lib/kernel32/misc/comm.c: Ditto. * lib/kernel32/misc/console.c: Ditto. * lib/kernel32/misc/debug.c: Ditto. * lib/kernel32/misc/dllmain.c: Ditto. * lib/kernel32/misc/env.c: Ditto. * lib/kernel32/misc/error.c: Ditto. * lib/kernel32/misc/handle.c: Ditto. * lib/kernel32/misc/ldr.c: Ditto. * lib/kernel32/misc/profile.c: Ditto. * lib/kernel32/misc/res.c: Ditto. * lib/kernel32/misc/stubs.c: Ditto. * lib/kernel32/misc/sysinfo.c: Ditto. * lib/kernel32/misc/time.c: Ditto. * lib/kernel32/process/cmdline.c: Ditto. * lib/kernel32/process/create.c: Ditto. * lib/kernel32/process/proc.c: Ditto. * lib/kernel32/process/session.c: Ditto. * lib/kernel32/string/lstring.c: Ditto. * lib/kernel32/synch/critical.c: Ditto. * lib/kernel32/synch/event.c: Ditto. * lib/kernel32/synch/intrlck.c: Ditto. * lib/kernel32/synch/mutex.c: Ditto. * lib/kernel32/synch/sem.c: Ditto. * lib/kernel32/synch/timer.c: Ditto. * lib/kernel32/synch/wait.c: Ditto. * lib/kernel32/thread/fiber.c: Ditto. * lib/kernel32/thread/thread.c: Ditto. * lib/kernel32/thread/tls.c: Ditto. svn path=/trunk/; revision=4009
213 lines
4.6 KiB
C
213 lines
4.6 KiB
C
/* $Id: sem.c,v 1.5 2003/01/15 21:24:36 chorns Exp $
|
|
*
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
* PROJECT: ReactOS system libraries
|
|
* FILE: lib/kernel32/synch/sem.c
|
|
* PURPOSE: Semaphore functions
|
|
* PROGRAMMER: Eric Kohl ([email protected])
|
|
* UPDATE HISTORY:
|
|
* Created 01/20/2001
|
|
*/
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
#include <k32.h>
|
|
|
|
#define NDEBUG
|
|
#include <kernel32/kernel32.h>
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
HANDLE STDCALL
|
|
CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
|
LONG lInitialCount,
|
|
LONG lMaximumCount,
|
|
LPCSTR lpName)
|
|
{
|
|
UNICODE_STRING NameU;
|
|
ANSI_STRING Name;
|
|
HANDLE Handle;
|
|
|
|
RtlInitAnsiString(&Name,
|
|
(LPSTR)lpName);
|
|
RtlAnsiStringToUnicodeString(&NameU,
|
|
&Name,
|
|
TRUE);
|
|
|
|
Handle = CreateSemaphoreW(lpSemaphoreAttributes,
|
|
lInitialCount,
|
|
lMaximumCount,
|
|
NameU.Buffer);
|
|
|
|
RtlFreeUnicodeString (&NameU);
|
|
|
|
return Handle;
|
|
}
|
|
|
|
|
|
HANDLE STDCALL
|
|
CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
|
LONG lInitialCount,
|
|
LONG lMaximumCount,
|
|
LPCWSTR lpName)
|
|
{
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
NTSTATUS Status;
|
|
UNICODE_STRING NameString;
|
|
HANDLE SemaphoreHandle;
|
|
|
|
if (lpName)
|
|
{
|
|
NameString.Length = lstrlenW(lpName)*sizeof(WCHAR);
|
|
}
|
|
else
|
|
{
|
|
NameString.Length = 0;
|
|
}
|
|
|
|
NameString.Buffer = (WCHAR *)lpName;
|
|
NameString.MaximumLength = NameString.Length;
|
|
|
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
ObjectAttributes.RootDirectory = hBaseDir;
|
|
ObjectAttributes.ObjectName = &NameString;
|
|
ObjectAttributes.Attributes = 0;
|
|
ObjectAttributes.SecurityDescriptor = NULL;
|
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
|
if (lpSemaphoreAttributes != NULL)
|
|
{
|
|
ObjectAttributes.SecurityDescriptor = lpSemaphoreAttributes->lpSecurityDescriptor;
|
|
if (lpSemaphoreAttributes->bInheritHandle == TRUE)
|
|
{
|
|
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
|
}
|
|
}
|
|
|
|
Status = NtCreateSemaphore(&SemaphoreHandle,
|
|
SEMAPHORE_ALL_ACCESS,
|
|
&ObjectAttributes,
|
|
lInitialCount,
|
|
lMaximumCount);
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
SetLastErrorByStatus(Status);
|
|
return NULL;
|
|
}
|
|
return SemaphoreHandle;
|
|
}
|
|
|
|
|
|
HANDLE STDCALL
|
|
OpenSemaphoreA(DWORD dwDesiredAccess,
|
|
WINBOOL bInheritHandle,
|
|
LPCSTR lpName)
|
|
{
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
UNICODE_STRING NameU;
|
|
ANSI_STRING Name;
|
|
HANDLE Handle;
|
|
NTSTATUS Status;
|
|
|
|
if (lpName == NULL)
|
|
{
|
|
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
|
|
return NULL;
|
|
}
|
|
|
|
RtlInitAnsiString(&Name,
|
|
(LPSTR)lpName);
|
|
RtlAnsiStringToUnicodeString(&NameU,
|
|
&Name,
|
|
TRUE);
|
|
|
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
ObjectAttributes.RootDirectory = hBaseDir;
|
|
ObjectAttributes.ObjectName = &NameU;
|
|
ObjectAttributes.Attributes = 0;
|
|
ObjectAttributes.SecurityDescriptor = NULL;
|
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
|
if (bInheritHandle == TRUE)
|
|
{
|
|
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
|
}
|
|
|
|
Status = NtOpenSemaphore(&Handle,
|
|
(ACCESS_MASK)dwDesiredAccess,
|
|
&ObjectAttributes);
|
|
|
|
RtlFreeUnicodeString(&NameU);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
SetLastErrorByStatus(Status);
|
|
return NULL;
|
|
}
|
|
|
|
return Handle;
|
|
}
|
|
|
|
|
|
HANDLE STDCALL
|
|
OpenSemaphoreW(DWORD dwDesiredAccess,
|
|
WINBOOL bInheritHandle,
|
|
LPCWSTR lpName)
|
|
{
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
UNICODE_STRING Name;
|
|
HANDLE Handle;
|
|
NTSTATUS Status;
|
|
|
|
if (lpName == NULL)
|
|
{
|
|
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
|
|
return NULL;
|
|
}
|
|
|
|
RtlInitUnicodeString(&Name,
|
|
(LPWSTR)lpName);
|
|
|
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
|
ObjectAttributes.RootDirectory = hBaseDir;
|
|
ObjectAttributes.ObjectName = &Name;
|
|
ObjectAttributes.Attributes = 0;
|
|
ObjectAttributes.SecurityDescriptor = NULL;
|
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
|
if (bInheritHandle == TRUE)
|
|
{
|
|
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
|
}
|
|
|
|
Status = NtOpenSemaphore(&Handle,
|
|
(ACCESS_MASK)dwDesiredAccess,
|
|
&ObjectAttributes);
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
SetLastErrorByStatus(Status);
|
|
return NULL;
|
|
}
|
|
|
|
return Handle;
|
|
}
|
|
|
|
|
|
WINBOOL STDCALL
|
|
ReleaseSemaphore(HANDLE hSemaphore,
|
|
LONG lReleaseCount,
|
|
LPLONG lpPreviousCount)
|
|
{
|
|
NTSTATUS Status;
|
|
|
|
Status = NtReleaseSemaphore(hSemaphore,
|
|
lReleaseCount,
|
|
lpPreviousCount);
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
SetLastErrorByStatus(Status);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/* EOF */
|