Author: ekohl
Date: Mon Jul 9 00:09:22 2007
New Revision: 27514
URL:
http://svn.reactos.org/svn/reactos?rev=27514&view=rev
Log:
- Fix indentation.
- Replace tabs by spaces.
- Replace STDCALL by WINAPI.
- Replace Alex' unreadable single-line statements by readable ones.
- No code changes.
Modified:
trunk/reactos/dll/win32/kernel32/file/npipe.c
Modified: trunk/reactos/dll/win32/kernel32/file/npipe.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/file/np…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/file/npipe.c (original)
+++ trunk/reactos/dll/win32/kernel32/file/npipe.c Mon Jul 9 00:09:22 2007
@@ -48,6 +48,7 @@
nDefaultTimeOut,
lpSecurityAttributes);
}
+
/*
* @implemented
@@ -87,7 +88,8 @@
}
/* Convert to NT syntax */
- if (nMaxInstances == PIPE_UNLIMITED_INSTANCES) nMaxInstances = -1;
+ if (nMaxInstances == PIPE_UNLIMITED_INSTANCES)
+ nMaxInstances = -1;
/* Convert the name */
Result = RtlDosPathNameToNtPathName_U(lpName,
@@ -97,8 +99,8 @@
if (!Result)
{
/* Conversion failed */
- SetLastError(ERROR_PATH_NOT_FOUND);
- return(INVALID_HANDLE_VALUE);
+ SetLastError(ERROR_PATH_NOT_FOUND);
+ return INVALID_HANDLE_VALUE;
}
DPRINT("Pipe name: %wZ\n", &NamedPipeName);
@@ -112,7 +114,8 @@
SecurityDescriptor = lpSecurityAttributes->lpSecurityDescriptor;
/* And check if this is pipe's handle will beinheritable */
- if(lpSecurityAttributes->bInheritHandle) Attributes |= OBJ_INHERIT;
+ if (lpSecurityAttributes->bInheritHandle)
+ Attributes |= OBJ_INHERIT;
}
/* Now we can initialize the object attributes */
@@ -132,6 +135,7 @@
{
CreateOptions |= FILE_WRITE_THROUGH;
}
+
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED))
{
CreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
@@ -143,6 +147,7 @@
ShareAccess |= FILE_SHARE_READ;
DesiredAccess |= GENERIC_WRITE;
}
+
if (dwOpenMode & PIPE_ACCESS_INBOUND)
{
ShareAccess |= FILE_SHARE_WRITE;
@@ -232,6 +237,7 @@
return PipeHandle;
}
+
/*
* @implemented
*/
@@ -255,6 +261,7 @@
/* Return result */
return r;
}
+
/*
* When NPFS will work properly, use this code instead. It is compatible with
@@ -342,8 +349,8 @@
{
/* The name is invalid */
DPRINT1("Invalid name!\n");
- SetLastErrorByStatus(STATUS_OBJECT_PATH_SYNTAX_BAD);
- return FALSE;
+ SetLastErrorByStatus(STATUS_OBJECT_PATH_SYNTAX_BAD);
+ return FALSE;
}
/* FIXME: Open \DosDevices\Unc\Server\Pipe\Name */
@@ -387,7 +394,7 @@
SetLastErrorByStatus(Status);
RtlFreeUnicodeString(&NamedPipeName);
RtlFreeHeap(RtlGetProcessHeap(), 0, WaitPipeInfo);
- return(FALSE);
+ return FALSE;
}
/* Check what timeout we got */
@@ -454,78 +461,79 @@
/*
* @implemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
WaitNamedPipeW(LPCWSTR lpNamedPipeName,
- DWORD nTimeOut)
-{
- UNICODE_STRING NamedPipeName;
- BOOL r;
- NTSTATUS Status;
- OBJECT_ATTRIBUTES ObjectAttributes;
- FILE_PIPE_WAIT_FOR_BUFFER WaitPipe;
- HANDLE FileHandle;
- IO_STATUS_BLOCK Iosb;
-
- r = RtlDosPathNameToNtPathName_U(lpNamedPipeName,
- &NamedPipeName,
- NULL,
- NULL);
- if (!r)
- {
- return(FALSE);
- }
-
- InitializeObjectAttributes(&ObjectAttributes,
- &NamedPipeName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
- Status = NtOpenFile(&FileHandle,
- FILE_READ_ATTRIBUTES | SYNCHRONIZE,
- &ObjectAttributes,
- &Iosb,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- FILE_SYNCHRONOUS_IO_NONALERT);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return(FALSE);
- }
-
- WaitPipe.Timeout.QuadPart = nTimeOut * -10000LL;
-
- Status = NtFsControlFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- FSCTL_PIPE_WAIT,
- &WaitPipe,
- sizeof(WaitPipe),
- NULL,
- 0);
- NtClose(FileHandle);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return(FALSE);
- }
-
- return(TRUE);
+ DWORD nTimeOut)
+{
+ UNICODE_STRING NamedPipeName;
+ NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ FILE_PIPE_WAIT_FOR_BUFFER WaitPipe;
+ HANDLE FileHandle;
+ IO_STATUS_BLOCK Iosb;
+
+ if (RtlDosPathNameToNtPathName_U(lpNamedPipeName,
+ &NamedPipeName,
+ NULL,
+ NULL) == FALSE)
+ {
+ return FALSE;
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &NamedPipeName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+ Status = NtOpenFile(&FileHandle,
+ FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+ &ObjectAttributes,
+ &Iosb,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ WaitPipe.Timeout.QuadPart = nTimeOut * -10000LL;
+
+ Status = NtFsControlFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &Iosb,
+ FSCTL_PIPE_WAIT,
+ &WaitPipe,
+ sizeof(WaitPipe),
+ NULL,
+ 0);
+ NtClose(FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ return TRUE;
}
#endif
-/*
- * @implemented
- */
-BOOL STDCALL
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
ConnectNamedPipe(IN HANDLE hNamedPipe,
IN LPOVERLAPPED lpOverlapped)
{
- NTSTATUS Status;
-
- if (lpOverlapped != NULL)
- {
+ NTSTATUS Status;
+
+ if (lpOverlapped != NULL)
+ {
PVOID ApcContext;
lpOverlapped->Internal = STATUS_PENDING;
@@ -544,13 +552,13 @@
/* return FALSE in case of failure and pending operations! */
if (!NT_SUCCESS(Status) || Status == STATUS_PENDING)
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
- }
- else
- {
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+ }
+ else
+ {
IO_STATUS_BLOCK Iosb;
Status = NtFsControlFile(hNamedPipe,
@@ -566,31 +574,32 @@
/* wait in case operation is pending */
if (Status == STATUS_PENDING)
- {
+ {
Status = NtWaitForSingleObject(hNamedPipe,
FALSE,
NULL);
if (NT_SUCCESS(Status))
- {
- Status = Iosb.Status;
- }
- }
+ {
+ Status = Iosb.Status;
+ }
+ }
if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
- }
-
- return TRUE;
-}
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
/*
* @implemented
*/
BOOL
-STDCALL
+WINAPI
SetNamedPipeHandleState(HANDLE hNamedPipe,
LPDWORD lpMode,
LPDWORD lpMaxCollectionCount,
@@ -621,7 +630,7 @@
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
- return(FALSE);
+ return FALSE;
}
}
@@ -638,11 +647,10 @@
&RemoteSettings,
sizeof(FILE_PIPE_REMOTE_INFORMATION),
FilePipeRemoteInformation);
-
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
- return(FALSE);
+ return FALSE;
}
}
@@ -653,9 +661,8 @@
if (lpCollectDataTimeout)
{
/* Convert it to Quad */
- RemoteSettings.CollectDataTime.QuadPart = -(LONGLONG)
- UInt32x32To64(10000,
-
*lpCollectDataTimeout);
+ RemoteSettings.CollectDataTime.QuadPart =
+ -(LONGLONG)UInt32x32To64(10000, *lpCollectDataTimeout);
}
/* Tell the driver to change them */
@@ -664,17 +671,16 @@
&RemoteSettings,
sizeof(FILE_PIPE_REMOTE_INFORMATION),
FilePipeRemoteInformation);
-
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
- return(FALSE);
- }
- }
-
- /* All done */
+ return FALSE;
+ }
+ }
+
return TRUE;
}
+
/*
* @implemented
@@ -706,6 +712,7 @@
nTimeOut);
}
+
/*
* @implemented
*/
@@ -736,10 +743,12 @@
NULL);
/* Success, break out */
- if (hPipe != INVALID_HANDLE_VALUE) break;
+ if (hPipe != INVALID_HANDLE_VALUE)
+ break;
/* Already tried twice, give up */
- if (bRetry == FALSE) return FALSE;
+ if (bRetry == FALSE)
+ return FALSE;
/* Wait on it */
WaitNamedPipeW(lpNamedPipeName, nTimeOut);
@@ -766,16 +775,18 @@
nOutBufferSize,
lpBytesRead,
NULL);
-
- /* Close the handle and return */
+
+ /* Close the handle */
CloseHandle(hPipe);
+
return bError;
}
-/*
- * @implemented
- */
-BOOL
+
+/*
+ * @implemented
+ */
+BOOL
WINAPI
DisconnectNamedPipe(HANDLE hNamedPipe)
{
@@ -797,7 +808,8 @@
{
/* Wait on NPFS to finish and get updated status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
- if (NT_SUCCESS(Status)) Status = Iosb.Status;
+ if (NT_SUCCESS(Status))
+ Status = Iosb.Status;
}
/* Check for error */
@@ -806,209 +818,213 @@
/* Fail */
SetLastErrorByStatus(Status);
return FALSE;
- }
-
+ }
+
return TRUE;
}
+
/*
* @unimplemented
*/
-BOOL STDCALL
+BOOL
+WINAPI
GetNamedPipeHandleStateW(HANDLE hNamedPipe,
- LPDWORD lpState,
- LPDWORD lpCurInstances,
- LPDWORD lpMaxCollectionCount,
- LPDWORD lpCollectDataTimeout,
- LPWSTR lpUserName,
- DWORD nMaxUserNameSize)
-{
- IO_STATUS_BLOCK StatusBlock;
- NTSTATUS Status;
-
- if (lpState != NULL)
- {
- FILE_PIPE_INFORMATION PipeInfo;
+ LPDWORD lpState,
+ LPDWORD lpCurInstances,
+ LPDWORD lpMaxCollectionCount,
+ LPDWORD lpCollectDataTimeout,
+ LPWSTR lpUserName,
+ DWORD nMaxUserNameSize)
+{
+ IO_STATUS_BLOCK StatusBlock;
+ NTSTATUS Status;
+
+ if (lpState != NULL)
+ {
+ FILE_PIPE_INFORMATION PipeInfo;
+
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &PipeInfo,
+ sizeof(FILE_PIPE_INFORMATION),
+ FilePipeInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ *lpState = ((PipeInfo.CompletionMode != FILE_PIPE_QUEUE_OPERATION) ? PIPE_NOWAIT
: PIPE_WAIT);
+ *lpState |= ((PipeInfo.ReadMode != FILE_PIPE_BYTE_STREAM_MODE) ?
PIPE_READMODE_MESSAGE : PIPE_READMODE_BYTE);
+ }
+
+ if(lpCurInstances != NULL)
+ {
+ FILE_PIPE_LOCAL_INFORMATION LocalInfo;
+
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &LocalInfo,
+ sizeof(FILE_PIPE_LOCAL_INFORMATION),
+ FilePipeLocalInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ *lpCurInstances = min(LocalInfo.CurrentInstances, PIPE_UNLIMITED_INSTANCES);
+ }
+
+ if (lpMaxCollectionCount != NULL || lpCollectDataTimeout != NULL)
+ {
+ FILE_PIPE_REMOTE_INFORMATION RemoteInfo;
+
+ Status = NtQueryInformationFile(hNamedPipe,
+ &StatusBlock,
+ &RemoteInfo,
+ sizeof(FILE_PIPE_REMOTE_INFORMATION),
+ FilePipeRemoteInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ if (lpMaxCollectionCount != NULL)
+ {
+ *lpMaxCollectionCount = RemoteInfo.MaximumCollectionCount;
+ }
+
+ if(lpCollectDataTimeout != NULL)
+ {
+ /* FIXME */
+ *lpCollectDataTimeout = 0;
+ }
+ }
+
+ if (lpUserName != NULL)
+ {
+ /* FIXME - open the thread token, call ImpersonateNamedPipeClient() and
+ retreive the user name with GetUserName(), revert the impersonation
+ and finally restore the thread token */
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+GetNamedPipeHandleStateA(HANDLE hNamedPipe,
+ LPDWORD lpState,
+ LPDWORD lpCurInstances,
+ LPDWORD lpMaxCollectionCount,
+ LPDWORD lpCollectDataTimeout,
+ LPSTR lpUserName,
+ DWORD nMaxUserNameSize)
+{
+ UNICODE_STRING UserNameW = {0};
+ ANSI_STRING UserNameA;
+ BOOL Ret;
+
+ if(lpUserName != NULL)
+ {
+ UserNameW.MaximumLength = (USHORT)nMaxUserNameSize * sizeof(WCHAR);
+ UserNameW.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
UserNameW.MaximumLength);
+ if (UserNameW.Buffer == NULL)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
+
+ UserNameA.Buffer = lpUserName;
+ UserNameA.Length = 0;
+ UserNameA.MaximumLength = (USHORT)nMaxUserNameSize;
+ }
+
+ Ret = GetNamedPipeHandleStateW(hNamedPipe,
+ lpState,
+ lpCurInstances,
+ lpMaxCollectionCount,
+ lpCollectDataTimeout,
+ UserNameW.Buffer,
+ nMaxUserNameSize);
+ if (Ret && lpUserName != NULL)
+ {
+ NTSTATUS Status;
+
+ RtlInitUnicodeString(&UserNameW, UserNameW.Buffer);
+ Status = RtlUnicodeStringToAnsiString(&UserNameA, &UserNameW, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ Ret = FALSE;
+ }
+ }
+
+ if (UserNameW.Buffer != NULL)
+ {
+ RtlFreeHeap(RtlGetProcessHeap(), 0, UserNameW.Buffer);
+ }
+
+ return Ret;
+}
+
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+GetNamedPipeInfo(HANDLE hNamedPipe,
+ LPDWORD lpFlags,
+ LPDWORD lpOutBufferSize,
+ LPDWORD lpInBufferSize,
+ LPDWORD lpMaxInstances)
+{
+ FILE_PIPE_LOCAL_INFORMATION PipeLocalInformation;
+ IO_STATUS_BLOCK StatusBlock;
+ NTSTATUS Status;
Status = NtQueryInformationFile(hNamedPipe,
&StatusBlock,
- &PipeInfo,
- sizeof(FILE_PIPE_INFORMATION),
- FilePipeInformation);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
-
- *lpState = ((PipeInfo.CompletionMode != FILE_PIPE_QUEUE_OPERATION) ? PIPE_NOWAIT :
PIPE_WAIT);
- *lpState |= ((PipeInfo.ReadMode != FILE_PIPE_BYTE_STREAM_MODE) ?
PIPE_READMODE_MESSAGE : PIPE_READMODE_BYTE);
- }
-
- if(lpCurInstances != NULL)
- {
- FILE_PIPE_LOCAL_INFORMATION LocalInfo;
-
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &LocalInfo,
+ &PipeLocalInformation,
sizeof(FILE_PIPE_LOCAL_INFORMATION),
FilePipeLocalInformation);
- if(!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
-
- *lpCurInstances = min(LocalInfo.CurrentInstances, PIPE_UNLIMITED_INSTANCES);
- }
-
- if(lpMaxCollectionCount != NULL || lpCollectDataTimeout != NULL)
- {
- FILE_PIPE_REMOTE_INFORMATION RemoteInfo;
-
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &RemoteInfo,
- sizeof(FILE_PIPE_REMOTE_INFORMATION),
- FilePipeRemoteInformation);
- if(!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
-
- if(lpMaxCollectionCount != NULL)
- {
- *lpMaxCollectionCount = RemoteInfo.MaximumCollectionCount;
- }
-
- if(lpCollectDataTimeout != NULL)
- {
- /* FIXME */
- *lpCollectDataTimeout = 0;
- }
- }
-
- if(lpUserName != NULL)
- {
- /* FIXME - open the thread token, call ImpersonateNamedPipeClient() and
- retreive the user name with GetUserName(), revert the impersonation
- and finally restore the thread token */
- }
-
- return TRUE;
-}
-
-
-/*
- * @implemented
- */
-BOOL STDCALL
-GetNamedPipeHandleStateA(HANDLE hNamedPipe,
- LPDWORD lpState,
- LPDWORD lpCurInstances,
- LPDWORD lpMaxCollectionCount,
- LPDWORD lpCollectDataTimeout,
- LPSTR lpUserName,
- DWORD nMaxUserNameSize)
-{
- UNICODE_STRING UserNameW = {0};
- ANSI_STRING UserNameA;
- BOOL Ret;
-
- if(lpUserName != NULL)
- {
- UserNameW.MaximumLength = (USHORT)nMaxUserNameSize * sizeof(WCHAR);
- UserNameW.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, UserNameW.MaximumLength);
- if (UserNameW.Buffer == NULL)
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
- }
-
- UserNameA.Buffer = lpUserName;
- UserNameA.Length = 0;
- UserNameA.MaximumLength = (USHORT)nMaxUserNameSize;
- }
-
- Ret = GetNamedPipeHandleStateW(hNamedPipe,
- lpState,
- lpCurInstances,
- lpMaxCollectionCount,
- lpCollectDataTimeout,
- UserNameW.Buffer,
- nMaxUserNameSize);
-
- if(Ret && lpUserName != NULL)
- {
- NTSTATUS Status;
-
- RtlInitUnicodeString(&UserNameW, UserNameW.Buffer);
- Status = RtlUnicodeStringToAnsiString(&UserNameA, &UserNameW, FALSE);
- if(!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- Ret = FALSE;
- }
- }
-
- if(UserNameW.Buffer != NULL)
- {
- RtlFreeHeap(RtlGetProcessHeap(), 0, UserNameW.Buffer);
- }
-
- return Ret;
-}
-
-
-/*
- * @implemented
- */
-BOOL STDCALL
-GetNamedPipeInfo(HANDLE hNamedPipe,
- LPDWORD lpFlags,
- LPDWORD lpOutBufferSize,
- LPDWORD lpInBufferSize,
- LPDWORD lpMaxInstances)
-{
- FILE_PIPE_LOCAL_INFORMATION PipeLocalInformation;
- IO_STATUS_BLOCK StatusBlock;
- NTSTATUS Status;
-
- Status = NtQueryInformationFile(hNamedPipe,
- &StatusBlock,
- &PipeLocalInformation,
- sizeof(FILE_PIPE_LOCAL_INFORMATION),
- FilePipeLocalInformation);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return(FALSE);
- }
-
- if (lpFlags != NULL)
- {
- *lpFlags = (PipeLocalInformation.NamedPipeEnd == FILE_PIPE_SERVER_END) ?
PIPE_SERVER_END : PIPE_CLIENT_END;
- *lpFlags |= (PipeLocalInformation.NamedPipeType == 1) ? PIPE_TYPE_MESSAGE :
PIPE_TYPE_BYTE;
- }
-
- if (lpOutBufferSize != NULL)
- *lpOutBufferSize = PipeLocalInformation.OutboundQuota;
-
- if (lpInBufferSize != NULL)
- *lpInBufferSize = PipeLocalInformation.InboundQuota;
-
- if (lpMaxInstances != NULL)
- {
- if (PipeLocalInformation.MaximumInstances >= 255)
- *lpMaxInstances = PIPE_UNLIMITED_INSTANCES;
- else
- *lpMaxInstances = PipeLocalInformation.MaximumInstances;
- }
-
- return(TRUE);
-}
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ if (lpFlags != NULL)
+ {
+ *lpFlags = (PipeLocalInformation.NamedPipeEnd == FILE_PIPE_SERVER_END) ?
PIPE_SERVER_END : PIPE_CLIENT_END;
+ *lpFlags |= (PipeLocalInformation.NamedPipeType == 1) ? PIPE_TYPE_MESSAGE :
PIPE_TYPE_BYTE;
+ }
+
+ if (lpOutBufferSize != NULL)
+ *lpOutBufferSize = PipeLocalInformation.OutboundQuota;
+
+ if (lpInBufferSize != NULL)
+ *lpInBufferSize = PipeLocalInformation.InboundQuota;
+
+ if (lpMaxInstances != NULL)
+ {
+ if (PipeLocalInformation.MaximumInstances >= 255)
+ *lpMaxInstances = PIPE_UNLIMITED_INSTANCES;
+ else
+ *lpMaxInstances = PipeLocalInformation.MaximumInstances;
+ }
+
+ return TRUE;
+}
+
/*
* @implemented
@@ -1025,6 +1041,7 @@
PFILE_PIPE_PEEK_BUFFER Buffer;
IO_STATUS_BLOCK Iosb;
ULONG BufferSize;
+ ULONG BytesRead;
NTSTATUS Status;
/* Calculate the buffer space that we'll need and allocate it */
@@ -1051,11 +1068,13 @@
{
/* Wait for npfs to be done, and update the status */
Status = NtWaitForSingleObject(hNamedPipe, FALSE, NULL);
- if (NT_SUCCESS(Status)) Status = Iosb.Status;
+ if (NT_SUCCESS(Status))
+ Status = Iosb.Status;
}
/* Overflow is success for us */
- if (Status == STATUS_BUFFER_OVERFLOW) Status = STATUS_SUCCESS;
+ if (Status == STATUS_BUFFER_OVERFLOW)
+ Status = STATUS_SUCCESS;
/* If we failed */
if (!NT_SUCCESS(Status))
@@ -1067,23 +1086,25 @@
}
/* Check if caller requested bytes available */
- if (lpTotalBytesAvail) *lpTotalBytesAvail = Buffer->ReadDataAvailable;
+ if (lpTotalBytesAvail)
+ *lpTotalBytesAvail = Buffer->ReadDataAvailable;
+
+ /* Calculate the bytes returned, minus our structure overhead */
+ BytesRead = (ULONG)(Iosb.Information -
+ FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]))
/* Check if caller requested bytes read */
if (lpBytesRead)
{
- /* Calculate the bytes returned, minus our structure overhead */
- *lpBytesRead = (ULONG)(Iosb.Information -
- FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
+ /* Return the bytes read */
+ *lpBytesRead = BytesRead;
}
/* Check if caller requested bytes left */
if (lpBytesLeftThisMessage)
{
/* Calculate total minus what we returned and our structure overhead */
- *lpBytesLeftThisMessage = Buffer->MessageLength -
- (ULONG)(Iosb.Information -
- FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
+ *lpBytesLeftThisMessage = Buffer->MessageLength - BytesRead;
}
/* Check if the caller wanted to see the actual data */
@@ -1092,19 +1113,21 @@
/* Give him what he wants */
RtlCopyMemory(lpBuffer,
Buffer->Data,
- Iosb.Information -
- FIELD_OFFSET(FILE_PIPE_PEEK_BUFFER, Data[0]));
- }
-
- /* Free the buffer and return success */
+ BytesRead);
+ }
+
+ /* Free the buffer */
RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
+
return TRUE;
}
-/*
- * @implemented
- */
-BOOL STDCALL
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
TransactNamedPipe(IN HANDLE hNamedPipe,
IN LPVOID lpInBuffer,
IN DWORD nInBufferSize,
@@ -1113,15 +1136,15 @@
OUT LPDWORD lpBytesRead OPTIONAL,
IN LPOVERLAPPED lpOverlapped OPTIONAL)
{
- NTSTATUS Status;
-
- if (lpBytesRead != NULL)
- {
+ NTSTATUS Status;
+
+ if (lpBytesRead != NULL)
+ {
*lpBytesRead = 0;
- }
-
- if (lpOverlapped != NULL)
- {
+ }
+
+ if (lpOverlapped != NULL)
+ {
PVOID ApcContext;
ApcContext = (((ULONG_PTR)lpOverlapped->hEvent & 0x1) ? NULL :
lpOverlapped);
@@ -1137,21 +1160,19 @@
nInBufferSize,
lpOutBuffer,
nOutBufferSize);
-
- /* return FALSE in case of failure and pending operations! */
if (!NT_SUCCESS(Status) || Status == STATUS_PENDING)
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
if (lpBytesRead != NULL)
- {
- *lpBytesRead = lpOverlapped->InternalHigh;
- }
- }
- else
- {
+ {
+ *lpBytesRead = lpOverlapped->InternalHigh;
+ }
+ }
+ else
+ {
#if 0 /* We don't implement FSCTL_PIPE_TRANSCEIVE yet */
IO_STATUS_BLOCK Iosb;
@@ -1165,59 +1186,58 @@
nInBufferSize,
lpOutBuffer,
nOutBufferSize);
-
- /* wait in case operation is pending */
if (Status == STATUS_PENDING)
- {
- Status = NtWaitForSingleObject(hNamedPipe,
- FALSE,
- NULL);
- if (NT_SUCCESS(Status))
- {
- Status = Iosb.Status;
- }
- }
+ {
+ Status = NtWaitForSingleObject(hNamedPipe,
+ FALSE,
+ NULL);
+ if (NT_SUCCESS(Status))
+ Status = Iosb.Status;
+ }
if (NT_SUCCESS(Status))
- {
- /* lpNumberOfBytesRead must not be NULL here, in fact Win doesn't
- check that case either and crashes (only after the operation
- completed) */
- *lpBytesRead = Iosb.Information;
- }
+ {
+ /* lpNumberOfBytesRead must not be NULL here, in fact Win doesn't
+ check that case either and crashes (only after the operation
+ completed) */
+ *lpBytesRead = Iosb.Information;
+ }
else
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
#else /* Workaround while FSCTL_PIPE_TRANSCEIVE not available */
DWORD nActualBytes;
while (0 != nInBufferSize &&
WriteFile(hNamedPipe, lpInBuffer, nInBufferSize, &nActualBytes,
NULL))
- {
+ {
lpInBuffer = (LPVOID)((char *) lpInBuffer + nActualBytes);
nInBufferSize -= nActualBytes;
- }
+ }
+
if (0 != nInBufferSize)
- {
+ {
/* Must have dropped out of the while 'cause WriteFile failed */
return FALSE;
- }
- if (! ReadFile(hNamedPipe, lpOutBuffer, nOutBufferSize, &nActualBytes,
- NULL))
- {
+ }
+
+ if (!ReadFile(hNamedPipe, lpOutBuffer, nOutBufferSize, &nActualBytes,
+ NULL))
+ {
return FALSE;
- }
+ }
+
if (NULL != lpBytesRead)
- {
+ {
*lpBytesRead = nActualBytes;
- }
+ }
#endif
- }
-
- return TRUE;
+ }
+
+ return TRUE;
}
/* EOF */