Author: ion
Date: Sat Jul 23 10:05:02 2011
New Revision: 52795
URL: 
http://svn.reactos.org/svn/reactos?rev=52795&view=rev
Log:
[KERNEL32]: Apply macros to Semaphore APIs. Fix bugs #18/#19 (same as before).
Modified:
    trunk/reactos/dll/win32/kernel32/client/synch.c
Modified: trunk/reactos/dll/win32/kernel32/client/synch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] Sat Jul 23 10:05:02 2011
@@ -535,128 +535,12 @@
  */
 HANDLE
 WINAPI
-CreateSemaphoreExA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes  OPTIONAL,
-                   IN LONG lInitialCount,
-                   IN LONG lMaximumCount,
-                   IN LPCSTR lpName  OPTIONAL,
-                   IN DWORD dwFlags,
-                   IN DWORD dwDesiredAccess)
-{
-    NTSTATUS Status;
-    ANSI_STRING AnsiName;
-    PUNICODE_STRING UnicodeCache;
-    LPCWSTR UnicodeName = NULL;
-
-    /* Check for a name */
-    if (lpName)
-    {
-        /* Use TEB Cache */
-        UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;
-
-        /* Convert to unicode */
-        RtlInitAnsiString(&AnsiName, lpName);
-        Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
-        if (!NT_SUCCESS(Status))
-        {
-            /* Conversion failed */
-            SetLastErrorByStatus(Status);
-            return NULL;
-        }
-
-        /* Otherwise, save the buffer */
-        UnicodeName = (LPCWSTR)UnicodeCache->Buffer;
-    }
-
-    /* Call the Unicode API */
-    return CreateSemaphoreExW(lpSemaphoreAttributes,
-                              lInitialCount,
-                              lMaximumCount,
-                              UnicodeName,
-                              dwFlags,
-                              dwDesiredAccess);
-}
-
-/*
- * @implemented
- */
-HANDLE
-WINAPI
-CreateSemaphoreExW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes  OPTIONAL,
-                   IN LONG lInitialCount,
-                   IN LONG lMaximumCount,
-                   IN LPCWSTR lpName  OPTIONAL,
-                   IN DWORD dwFlags,
-                   IN DWORD dwDesiredAccess)
-{
-    NTSTATUS Status;
-    OBJECT_ATTRIBUTES LocalAttributes;
-    POBJECT_ATTRIBUTES ObjectAttributes;
-    HANDLE Handle;
-    UNICODE_STRING ObjectName;
-
-    /* Now check if we got a name */
-    if (lpName) RtlInitUnicodeString(&ObjectName, lpName);
-
-    if (dwFlags != 0)
-    {
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return NULL;
-    }
-
-    /* Now convert the object attributes */
-    ObjectAttributes = BasepConvertObjectAttributes(&LocalAttributes,
-                                                    lpSemaphoreAttributes,
-                                                    lpName ? &ObjectName : NULL);
-
-    /* Create the semaphore */
-   Status = NtCreateSemaphore(&Handle,
-                              (ACCESS_MASK)dwDesiredAccess,
-                              ObjectAttributes,
-                              lInitialCount,
-                              lMaximumCount);
-    if (NT_SUCCESS(Status))
-    {
-        /* Check if the object already existed */
-        if (Status == STATUS_OBJECT_NAME_EXISTS)
-        {
-            /* Set distinguished Win32 error code */
-            SetLastError(ERROR_ALREADY_EXISTS);
-        }
-        else
-        {
-            /* Otherwise, set success */
-            SetLastError(ERROR_SUCCESS);
-        }
-
-        /* Return the handle */
-        return Handle;
-    }
-    else
-    {
-        /* Convert the NT Status and fail */
-        SetLastErrorByStatus(Status);
-        return NULL;
-    }
-
-}
-
-
-/*
- * @implemented
- */
-HANDLE
-WINAPI
 CreateSemaphoreA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes  OPTIONAL,
                  IN LONG lInitialCount,
                  IN LONG lMaximumCount,
                  IN LPCSTR lpName  OPTIONAL)
 {
-    return CreateSemaphoreExA(lpSemaphoreAttributes,
-                              lInitialCount,
-                              lMaximumCount,
-                              lpName,
-                              0,
-                              SEMAPHORE_ALL_ACCESS);
+    ConvertWin32AnsiObjectApiToUnicodeApi(Semaphore, lpName, lpSemaphoreAttributes,
lInitialCount, lMaximumCount);
 }
 /*
@@ -669,12 +553,11 @@
                  IN LONG lMaximumCount,
                  IN LPCWSTR lpName  OPTIONAL)
 {
-    return CreateSemaphoreExW(lpSemaphoreAttributes,
-                              lInitialCount,
-                              lMaximumCount,
-                              lpName,
-                              0,
-                              SEMAPHORE_ALL_ACCESS);
+    CreateNtObjectFromWin32Api(Semaphore, Semaphore, SEMAPHORE,
+                               lpSemaphoreAttributes,
+                               lpName,
+                               lInitialCount,
+                               lMaximumCount);
 }
 /*
@@ -686,37 +569,7 @@
                IN BOOL bInheritHandle,
                IN LPCSTR lpName)
 {
-    NTSTATUS Status;
-    ANSI_STRING AnsiName;
-    PUNICODE_STRING UnicodeCache;
-
-    /* Check for a name */
-    if (lpName)
-    {
-        /* Use TEB Cache */
-        UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;
-
-        /* Convert to unicode */
-        RtlInitAnsiString(&AnsiName, lpName);
-        Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
-        if (!NT_SUCCESS(Status))
-        {
-            /* Conversion failed */
-            SetLastErrorByStatus(Status);
-            return NULL;
-        }
-    }
-    else
-    {
-        /* We need a name */
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return NULL;
-    }
-
-    /* Call the Unicode API */
-    return OpenSemaphoreW(dwDesiredAccess,
-                          bInheritHandle,
-                          (LPCWSTR)UnicodeCache->Buffer);
+    ConvertOpenWin32AnsiObjectApiToUnicodeApi(Semaphore, dwDesiredAccess, bInheritHandle,
lpName);
 }
 /*
@@ -728,38 +581,7 @@
                IN BOOL bInheritHandle,
                IN LPCWSTR lpName)
 {
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING ObjectName;
-    NTSTATUS Status;
-    HANDLE Handle;
-
-    /* Make sure we got a name */
-    if (!lpName)
-    {
-        /* Fail without one */
-        SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
-        return NULL;
-    }
-
-    /* Initialize the object name and attributes */
-    RtlInitUnicodeString(&ObjectName, lpName);
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &ObjectName,
-                               bInheritHandle ? OBJ_INHERIT : 0,
-                               hBaseDir,
-                               NULL);
-
-    /* Open the semaphore */
-    Status = NtOpenSemaphore(&Handle, dwDesiredAccess, &ObjectAttributes);
-    if (!NT_SUCCESS(Status))
-    {
-        /* Convert the status and fail */
-        SetLastErrorByStatus(Status);
-        return NULL;
-    }
-
-    /* Return the handle */
-    return Handle;
+    OpenNtObjectFromWin32Api(Semaphore, dwDesiredAccess, bInheritHandle, lpName);
 }
 /*