Use the share disposition to detect the direction of a pipe.
[reactos.git] / reactos / lib / kernel32 / file / npipe.c
index d464992..f926dc4 100644 (file)
 #define NDEBUG
 #include "../include/debug.h"
 
-/* FIXME - defined in ntifs.h */
-#if !defined(FILE_PIPE_BYTE_STREAM_TYPE) && !defined(FILE_PIPE_MESSAGE_TYPE)
-#define FILE_PIPE_BYTE_STREAM_TYPE      0x00000000
-#define FILE_PIPE_MESSAGE_TYPE          0x00000001
-#endif
-
 /* FUNCTIONS ****************************************************************/
 
 /*
@@ -85,11 +79,11 @@ CreateNamedPipeW(LPCWSTR lpName,
    ULONG ShareAccess, Attributes;
    LARGE_INTEGER DefaultTimeOut;
    PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
-   
+
    if (nMaxInstances == 0 || nMaxInstances > PIPE_UNLIMITED_INSTANCES)
    {
-       SetLastError(ERROR_INVALID_PARAMETER);
-       return INVALID_HANDLE_VALUE;
+      SetLastError(ERROR_INVALID_PARAMETER);
+      return INVALID_HANDLE_VALUE;
    }
 
    Result = RtlDosPathNameToNtPathName_U((LPWSTR)lpName,
@@ -124,35 +118,35 @@ CreateNamedPipeW(LPCWSTR lpName,
    CreateOptions = 0;
 
    if (dwOpenMode & FILE_FLAG_WRITE_THROUGH)
-       CreateOptions |= FILE_WRITE_THROUGH;
+      CreateOptions = CreateOptions | FILE_WRITE_THROUGH;
+
    if (!(dwOpenMode & FILE_FLAG_OVERLAPPED))
-       CreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
+      CreateOptions = CreateOptions | FILE_SYNCHRONOUS_IO_NONALERT;
 
-   if (dwOpenMode & PIPE_ACCESS_INBOUND)
+   if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
      {
-          ShareAccess |= FILE_SHARE_WRITE;
-          DesiredAccess |= GENERIC_READ;
+       ShareAccess |= FILE_SHARE_READ;
+       DesiredAccess |= GENERIC_WRITE;
      }
-   if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
+   if (dwOpenMode & PIPE_ACCESS_INBOUND)
      {
-          ShareAccess |= FILE_SHARE_READ;
-          DesiredAccess |= GENERIC_WRITE;
+       ShareAccess |= FILE_SHARE_WRITE;
+       DesiredAccess |= GENERIC_READ;
      }
-
    if (dwPipeMode & PIPE_TYPE_MESSAGE)
-       WriteModeMessage = FILE_PIPE_MESSAGE_TYPE;
+      WriteModeMessage = FILE_PIPE_MESSAGE_MODE;
    else
-       WriteModeMessage = FILE_PIPE_BYTE_STREAM_TYPE;
+      WriteModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
 
    if (dwPipeMode & PIPE_READMODE_MESSAGE)
-       ReadModeMessage = FILE_PIPE_MESSAGE_MODE;
+      ReadModeMessage = FILE_PIPE_MESSAGE_MODE;
    else
-       ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
+      ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
 
    if (dwPipeMode & PIPE_NOWAIT)
        NonBlocking = FILE_PIPE_COMPLETE_OPERATION;
    else
-       NonBlocking = FILE_PIPE_QUEUE_OPERATION;
+      NonBlocking = FILE_PIPE_QUEUE_OPERATION;
 
    DefaultTimeOut.QuadPart = nDefaultTimeOut * -10000LL;
 
@@ -345,7 +339,7 @@ ConnectNamedPipe(IN HANDLE hNamedPipe,
 /*
  * @implemented
  */
-BOOL 
+BOOL
 STDCALL
 SetNamedPipeHandleState(HANDLE hNamedPipe,
                         LPDWORD lpMode,
@@ -368,7 +362,7 @@ SetNamedPipeHandleState(HANDLE hNamedPipe,
         Settings.ReadMode = (*lpMode & PIPE_READMODE_MESSAGE) ?
                             FILE_PIPE_MESSAGE_MODE: FILE_PIPE_BYTE_STREAM_MODE;
 
-        /* Send the changes to the Driver */ 
+        /* Send the changes to the Driver */
         Status = NtSetInformationFile(hNamedPipe,
                                       &Iosb,
                                       &Settings,
@@ -380,7 +374,7 @@ SetNamedPipeHandleState(HANDLE hNamedPipe,
             return(FALSE);
         }
     }
-    
+
     /* Check if the Collection count or Timeout are being changed */
     if (lpMaxCollectionCount || lpCollectDataTimeout)
     {
@@ -402,9 +396,9 @@ SetNamedPipeHandleState(HANDLE hNamedPipe,
             }
         }
 
-        /* Now set the new settings */    
-        RemoteSettings.MaximumCollectionCount = (lpMaxCollectionCount) ? 
-                                                *lpMaxCollectionCount : 
+        /* Now set the new settings */
+        RemoteSettings.MaximumCollectionCount = (lpMaxCollectionCount) ?
+                                                *lpMaxCollectionCount :
                                                 RemoteSettings.MaximumCollectionCount;
         if (lpCollectDataTimeout)
         {