From ca4ae96f3367f381be9dbb655c4da168d54ebd43 Mon Sep 17 00:00:00 2001
From: Eric Pouech <eric.pouech@wanadoo.fr>
Date: Mon, 14 Nov 2005 15:11:11 +0000
Subject: [PATCH] NtReadFile: now returning correct status in NtReadFile for
 EOF conditions (on files) and broken pipe (on named pipes).

---
 dlls/kernel/tests/pipe.c |  2 +-
 dlls/ntdll/file.c        | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel/tests/pipe.c b/dlls/kernel/tests/pipe.c
index 86e6365b1c7..aaad8d6781a 100644
--- a/dlls/kernel/tests/pipe.c
+++ b/dlls/kernel/tests/pipe.c
@@ -757,7 +757,7 @@ static void test_CreatePipe(void)
     ok(ReadFile(piperead,readbuf,sizeof(readbuf),&read, NULL), "Read from broken pipe withe with pending data failed\n");
     ok(read == sizeof(PIPENAME), "Read from  anonymous pipe got %ld bytes instead of %d\n", read, sizeof(PIPENAME));
     /* But now we need to get informed that the pipe is closed */
-    todo_wine ok(ReadFile(piperead,readbuf,sizeof(readbuf),&read, NULL) == 0, "Broken pipe not detected\n");
+    ok(ReadFile(piperead,readbuf,sizeof(readbuf),&read, NULL) == 0, "Broken pipe not detected\n");
 }
 
 START_TEST(pipe)
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index cd73aeff52e..13105291591 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -589,8 +589,16 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
         else io_status->u.Status = FILE_GetNtStatus();
 	break;
     }
+    if (io_status->u.Status == STATUS_SUCCESS && io_status->Information == 0)
+    {
+        struct stat st;
+        if (fstat( unix_handle, &st ) != -1 && S_ISSOCK( st.st_mode ))
+            io_status->u.Status = STATUS_PIPE_BROKEN;
+        else
+            io_status->u.Status = STATUS_END_OF_FILE;
+    }
     wine_server_release_fd( hFile, unix_handle );
-    TRACE("= 0x%08lx\n", io_status->u.Status);
+    TRACE("= 0x%08lx (%lu)\n", io_status->u.Status, io_status->Information);
     return io_status->u.Status;
 }
 
-- 
GitLab