- Add some definitions to NDK - Prettify/document CreatePipe and correct some mistakes, use 120 second timeout like on NT and send FILE_PIPE flags instead of weird BOOLEAN values from hell. Modified: trunk/reactos/include/ndk/iotypes.h Modified: trunk/reactos/include/ndk/rtlfuncs.h Modified: trunk/reactos/lib/kernel32/file/pipe.c _____
Modified: trunk/reactos/include/ndk/iotypes.h --- trunk/reactos/include/ndk/iotypes.h 2005-11-08 20:50:04 UTC (rev 19064) +++ trunk/reactos/include/ndk/iotypes.h 2005-11-08 20:53:53 UTC (rev 19065) @@ -37,6 +37,7 @@
#define FILE_DOES_NOT_EXIST 0x00000005
/* Pipe Flags */ +#define FILE_PIPE_BYTE_STREAM_TYPE 0x00000000 #define FILE_PIPE_BYTE_STREAM_MODE 0x00000000 #define FILE_PIPE_MESSAGE_MODE 0x00000001 #define FILE_PIPE_QUEUE_OPERATION 0x00000000 _____
Modified: trunk/reactos/include/ndk/rtlfuncs.h --- trunk/reactos/include/ndk/rtlfuncs.h 2005-11-08 20:50:04 UTC (rev 19064) +++ trunk/reactos/include/ndk/rtlfuncs.h 2005-11-08 20:53:53 UTC (rev 19065) @@ -1184,6 +1184,15 @@
NTSYSAPI BOOLEAN NTAPI +RtlPrefixString( + PCANSI_STRING String1, + PCANSI_STRING String2, + BOOLEAN CaseInsensitive +); + +NTSYSAPI +BOOLEAN +NTAPI RtlPrefixUnicodeString( PCUNICODE_STRING String1, PCUNICODE_STRING String2, _____
Modified: trunk/reactos/lib/kernel32/file/pipe.c --- trunk/reactos/lib/kernel32/file/pipe.c 2005-11-08 20:50:04 UTC (rev 19064) +++ trunk/reactos/lib/kernel32/file/pipe.c 2005-11-08 20:53:53 UTC (rev 19065) @@ -17,95 +17,109 @@
/* GLOBALS ******************************************************************/
-ULONG ProcessPipeId = 0; +LONG ProcessPipeId = 0;
/* FUNCTIONS ****************************************************************/
/* * @implemented */ -BOOL STDCALL CreatePipe(PHANDLE hReadPipe, - PHANDLE hWritePipe, - LPSECURITY_ATTRIBUTES lpPipeAttributes, - DWORD nSize) +BOOL +STDCALL +CreatePipe(PHANDLE hReadPipe, + PHANDLE hWritePipe, + LPSECURITY_ATTRIBUTES lpPipeAttributes, + DWORD nSize) { - WCHAR Buffer[64]; - UNICODE_STRING PipeName; - OBJECT_ATTRIBUTES ObjectAttributes; - IO_STATUS_BLOCK StatusBlock; - LARGE_INTEGER DefaultTimeout; - NTSTATUS Status; - HANDLE ReadPipeHandle; - HANDLE WritePipeHandle; - ULONG PipeId; - ULONG Attributes; - PSECURITY_DESCRIPTOR SecurityDescriptor = NULL; + WCHAR Buffer[64]; + UNICODE_STRING PipeName; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK StatusBlock; + LARGE_INTEGER DefaultTimeout; + NTSTATUS Status; + HANDLE ReadPipeHandle; + HANDLE WritePipeHandle; + LONG PipeId; + ULONG Attributes; + PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
- DefaultTimeout.QuadPart = -300000000; /* 30 seconds */ + /* Set the timeout to 120 seconds */ + DefaultTimeout.QuadPart = -1200000000;
- PipeId = (ULONG)InterlockedIncrement((LONG*)&ProcessPipeId); - swprintf(Buffer, - L"\\.\PIPE\Win32Pipes.%08x.%08x", - NtCurrentTeb()->Cid.UniqueProcess, - PipeId); - RtlInitUnicodeString (&PipeName, - Buffer); + /* Use default buffer size if desired */ + if (!nSize) nSize = 0x1000;
- Attributes = OBJ_CASE_INSENSITIVE; - if (lpPipeAttributes) - { - SecurityDescriptor = lpPipeAttributes->lpSecurityDescriptor; - if (lpPipeAttributes->bInheritHandle) - Attributes |= OBJ_INHERIT; - } + /* Increase the Pipe ID */ + PipeId = InterlockedIncrement(&ProcessPipeId);
- /* use default buffer size if desired */ - if (nSize == 0) - nSize = 0x1000; + /* Create the pipe name */ + swprintf(Buffer, + L"\\.\PIPE\Win32Pipes.%08x.%08x", + NtCurrentTeb()->Cid.UniqueProcess, + PipeId); + RtlInitUnicodeString(&PipeName, Buffer);
- InitializeObjectAttributes(&ObjectAttributes, - &PipeName, - Attributes, - NULL, - SecurityDescriptor); + /* Always use case insensitive */ + Attributes = OBJ_CASE_INSENSITIVE;
- Status = NtCreateNamedPipeFile(&ReadPipeHandle, - FILE_GENERIC_READ |FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, - &ObjectAttributes, - &StatusBlock, - FILE_SHARE_WRITE, - FILE_CREATE, - FILE_SYNCHRONOUS_IO_NONALERT, - FALSE, - FALSE, - FALSE, - 1, - nSize, - nSize, - &DefaultTimeout); - if (!NT_SUCCESS(Status)) - { - SetLastErrorByStatus(Status); - return FALSE; - } + /* Check if we got attributes */ + if (lpPipeAttributes) + { + /* Use the attributes' SD instead */ + SecurityDescriptor = lpPipeAttributes->lpSecurityDescriptor;
- Status = NtOpenFile(&WritePipeHandle, - FILE_GENERIC_WRITE | SYNCHRONIZE, - &ObjectAttributes, - &StatusBlock, - FILE_SHARE_READ, - FILE_SYNCHRONOUS_IO_NONALERT); - if (!NT_SUCCESS(Status)) - { - NtClose(ReadPipeHandle); - SetLastErrorByStatus(Status); - return FALSE; - } + /* Set OBJ_INHERIT if requested */ + if (lpPipeAttributes->bInheritHandle) Attributes |= OBJ_INHERIT; + }
- *hReadPipe = ReadPipeHandle; - *hWritePipe = WritePipeHandle; + /* Initialize the attributes */ + InitializeObjectAttributes(&ObjectAttributes, + &PipeName, + Attributes, + NULL, + SecurityDescriptor);
- return TRUE; + /* Create the named pipe */ + Status = NtCreateNamedPipeFile(&ReadPipeHandle, + FILE_GENERIC_READ |FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, + &ObjectAttributes, + &StatusBlock, + FILE_SHARE_WRITE, + FILE_CREATE, + FILE_SYNCHRONOUS_IO_NONALERT, + FILE_PIPE_BYTE_STREAM_TYPE, + FILE_PIPE_BYTE_STREAM_MODE, + FILE_PIPE_BYTE_STREAM_MODE, + 1, + nSize, + nSize, + &DefaultTimeout); + if (!NT_SUCCESS(Status)) + { + /* Convert error and fail */ + SetLastErrorByStatus(Status); + return FALSE; + } + + /* Now try opening it for write access */ + Status = NtOpenFile(&WritePipeHandle, + FILE_GENERIC_WRITE | SYNCHRONIZE, + &ObjectAttributes, + &StatusBlock, + FILE_SHARE_READ, + FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE); + if (!NT_SUCCESS(Status)) + { + /* Convert error and fail */ + NtClose(ReadPipeHandle); + SetLastErrorByStatus(Status); + return FALSE; + } + + /* Return both handles */ + *hReadPipe = ReadPipeHandle; + *hWritePipe = WritePipeHandle; + return TRUE; }
/* EOF */