Revert 18883 and 18912, as they break named pipes
[reactos.git] / reactos / lib / kernel32 / file / pipe.c
index ee562e9..f5e65d5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pipe.c,v 1.6 2002/09/07 15:12:26 chorns Exp $
+/* $Id$
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
 
 /* INCLUDES *****************************************************************/
 
-#define NTOS_USER_MODE
-#include <ntos.h>
-#include <kernel32/error.h>
+#include <k32.h>
 
-#include <kernel32/kernel32.h>
+#define NDEBUG
+#include "../include/debug.h"
 
 /* GLOBALS ******************************************************************/
 
@@ -22,6 +21,9 @@ ULONG ProcessPipeId = 0;
 
 /* FUNCTIONS ****************************************************************/
 
+/*
+ * @implemented
+ */
 BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
                        PHANDLE hWritePipe,
                        LPSECURITY_ATTRIBUTES lpPipeAttributes,
@@ -35,35 +37,33 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
    NTSTATUS Status;
    HANDLE ReadPipeHandle;
    HANDLE WritePipeHandle;
+   ULONG PipeId;
+   ULONG Attributes;
    PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
 
    DefaultTimeout.QuadPart = 300000000; /* 30 seconds */
 
-   ProcessPipeId++;
+   PipeId = (ULONG)InterlockedIncrement((LONG*)&ProcessPipeId);
    swprintf(Buffer,
            L"\\Device\\NamedPipe\\Win32Pipes.%08x.%08x",
            NtCurrentTeb()->Cid.UniqueProcess,
-           ProcessPipeId);
+           PipeId);
    RtlInitUnicodeString (&PipeName,
                         Buffer);
 
+   Attributes = OBJ_CASE_INSENSITIVE;
    if (lpPipeAttributes)
      {
        SecurityDescriptor = lpPipeAttributes->lpSecurityDescriptor;
+       if (lpPipeAttributes->bInheritHandle)
+         Attributes |= OBJ_INHERIT;
      }
 
    InitializeObjectAttributes(&ObjectAttributes,
                              &PipeName,
-                             OBJ_CASE_INSENSITIVE,
+                             Attributes,
                              NULL,
                              SecurityDescriptor);
-   if (lpPipeAttributes)
-   {
-      if(lpPipeAttributes->bInheritHandle)
-         ObjectAttributes.Attributes |= OBJ_INHERIT;
-      if (lpPipeAttributes->lpSecurityDescriptor)
-        ObjectAttributes.SecurityDescriptor = lpPipeAttributes->lpSecurityDescriptor;
-   }
 
    Status = NtCreateNamedPipeFile(&ReadPipeHandle,
                                  FILE_GENERIC_READ,
@@ -89,7 +89,7 @@ BOOL STDCALL CreatePipe(PHANDLE hReadPipe,
                       FILE_GENERIC_WRITE,
                       &ObjectAttributes,
                       &StatusBlock,
-                      FILE_SHARE_READ | FILE_SHARE_WRITE,
+                      0,
                       FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
    if (!NT_SUCCESS(Status))
      {