From 9e66e97db8b96eaf7f512a369743733443775e98 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Mon, 11 Aug 2014 17:26:18 +0200 Subject: [PATCH] kernel32: Implement GetNamedPipeHandleState. Based on a patch by Adam Martinson. --- dlls/kernel32/sync.c | 59 +++++++++++++++++++++++++++++++++----- dlls/kernel32/tests/pipe.c | 4 --- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c index 821062460a9..21b24f2688a 100644 --- a/dlls/kernel32/sync.c +++ b/dlls/kernel32/sync.c @@ -1712,12 +1712,16 @@ BOOL WINAPI GetNamedPipeHandleStateA( LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout, LPSTR lpUsername, DWORD nUsernameMaxSize) { - FIXME("%p %p %p %p %p %p %d\n", - hNamedPipe, lpState, lpCurInstances, - lpMaxCollectionCount, lpCollectDataTimeout, - lpUsername, nUsernameMaxSize); + WARN("%p %p %p %p %p %p %d: semi-stub\n", + hNamedPipe, lpState, lpCurInstances, + lpMaxCollectionCount, lpCollectDataTimeout, + lpUsername, nUsernameMaxSize); - return FALSE; + if (lpUsername && nUsernameMaxSize) + *lpUsername = 0; + + return GetNamedPipeHandleStateW(hNamedPipe, lpState, lpCurInstances, + lpMaxCollectionCount, lpCollectDataTimeout, NULL, 0); } /*********************************************************************** @@ -1728,12 +1732,53 @@ BOOL WINAPI GetNamedPipeHandleStateW( LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout, LPWSTR lpUsername, DWORD nUsernameMaxSize) { - FIXME("%p %p %p %p %p %p %d\n", + IO_STATUS_BLOCK iosb; + NTSTATUS status; + + FIXME("%p %p %p %p %p %p %d: semi-stub\n", hNamedPipe, lpState, lpCurInstances, lpMaxCollectionCount, lpCollectDataTimeout, lpUsername, nUsernameMaxSize); - return FALSE; + if (lpMaxCollectionCount) + *lpMaxCollectionCount = 0; + + if (lpCollectDataTimeout) + *lpCollectDataTimeout = 0; + + if (lpUsername && nUsernameMaxSize) + *lpUsername = 0; + + if (lpState) + { + FILE_PIPE_INFORMATION fpi; + status = NtQueryInformationFile(hNamedPipe, &iosb, &fpi, sizeof(fpi), + FilePipeInformation); + if (status) + { + SetLastError( RtlNtStatusToDosError(status) ); + return FALSE; + } + + *lpState = (fpi.ReadMode ? PIPE_READMODE_MESSAGE : PIPE_READMODE_BYTE) | + (fpi.CompletionMode ? PIPE_NOWAIT : PIPE_WAIT); + } + + if (lpCurInstances) + { + FILE_PIPE_LOCAL_INFORMATION fpli; + status = NtQueryInformationFile(hNamedPipe, &iosb, &fpli, sizeof(fpli), + FilePipeLocalInformation); + if (status) + { + SetLastError( RtlNtStatusToDosError(status) ); + return FALSE; + } + + *lpCurInstances = fpli.CurrentInstances; + } + + return TRUE; } /*********************************************************************** diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c index f7c75313e48..20c2c61f57e 100644 --- a/dlls/kernel32/tests/pipe.c +++ b/dlls/kernel32/tests/pipe.c @@ -1662,11 +1662,9 @@ static void test_NamedPipeHandleState(void) /* lpSecurityAttrib */ NULL); ok(server != INVALID_HANDLE_VALUE, "cf failed\n"); ret = GetNamedPipeHandleStateA(server, NULL, NULL, NULL, NULL, NULL, 0); - todo_wine ok(ret, "GetNamedPipeHandleState failed: %d\n", GetLastError()); ret = GetNamedPipeHandleStateA(server, &state, &instances, NULL, NULL, NULL, 0); - todo_wine ok(ret, "GetNamedPipeHandleState failed: %d\n", GetLastError()); if (ret) { @@ -1719,11 +1717,9 @@ static void test_NamedPipeHandleState(void) /* lpSecurityAttrib */ NULL); ok(server != INVALID_HANDLE_VALUE, "cf failed\n"); ret = GetNamedPipeHandleStateA(server, NULL, NULL, NULL, NULL, NULL, 0); - todo_wine ok(ret, "GetNamedPipeHandleState failed: %d\n", GetLastError()); ret = GetNamedPipeHandleStateA(server, &state, &instances, NULL, NULL, NULL, 0); - todo_wine ok(ret, "GetNamedPipeHandleState failed: %d\n", GetLastError()); if (ret) {