[1/2] ntdll: NtReadFile should not fail for 0-length reads at EOF.
Dmitry Timoshkov
dmitry at baikal.ru
Wed Oct 30 00:24:25 CDT 2013
This patch should fix the regression reported in the bug 34812.
---
dlls/ntdll/file.c | 16 ++++++++--------
dlls/ntdll/tests/file.c | 16 ----------------
2 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 8c8f4cf..e91b2fe 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -636,7 +636,7 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
lseek( unix_handle, offset->QuadPart + result, SEEK_SET );
total = result;
- status = total ? STATUS_SUCCESS : STATUS_END_OF_FILE;
+ status = (total || !length) ? STATUS_SUCCESS : STATUS_END_OF_FILE;
goto done;
}
}
@@ -656,21 +656,21 @@ NTSTATUS WINAPI NtReadFile(HANDLE hFile, HANDLE hEvent,
total += result;
if (!result || total == length)
{
- if (total)
- {
- status = STATUS_SUCCESS;
- goto done;
- }
switch (type)
{
case FD_TYPE_FILE:
case FD_TYPE_CHAR:
- status = STATUS_END_OF_FILE;
+ status = (total || !length) ? STATUS_SUCCESS : STATUS_END_OF_FILE;
goto done;
case FD_TYPE_SERIAL:
+ if (total)
+ {
+ status = STATUS_SUCCESS;
+ goto done;
+ }
break;
default:
- status = STATUS_PIPE_BROKEN;
+ status = total ? STATUS_SUCCESS : STATUS_PIPE_BROKEN;
goto done;
}
}
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index d9e85fd..f857777 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -2168,12 +2168,9 @@ todo_wine
bytes = -1;
SetLastError(0xdeadbeef);
ret = ReadFile(hfile, buf, 0, &bytes, &ovl);
-todo_wine
ok(ret, "ReadFile error %d\n", GetLastError());
-todo_wine
ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
ok(bytes == 0, "bytes %u\n", bytes);
-todo_wine
ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
@@ -2189,11 +2186,8 @@ todo_wine
U(iob).Status = -1;
iob.Information = -1;
status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, NULL, NULL);
-todo_wine
ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
-todo_wine
ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
-todo_wine
ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
U(iob).Status = -1;
@@ -2210,11 +2204,8 @@ todo_wine
iob.Information = -1;
offset.QuadPart = sizeof(contents);
status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, &offset, NULL);
-todo_wine
ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
-todo_wine
ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
-todo_wine
ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
U(iob).Status = -1;
@@ -2231,11 +2222,8 @@ todo_wine
iob.Information = -1;
offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, &offset, NULL);
-todo_wine
ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
-todo_wine
ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
-todo_wine
ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
for (i = -20; i < 0; i++)
@@ -2351,7 +2339,6 @@ todo_wine
/* ReadFile return value depends on Windows version and testing it is not practical */
ReadFile(hfile, buf, 0, &bytes, &ovl);
ok(bytes == 0, "bytes %u\n", bytes);
-todo_wine
ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
@@ -2547,11 +2534,8 @@ todo_wine
}
else
{
-todo_wine
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", status);
-todo_wine
ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
-todo_wine
ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
}
--
1.8.4.1
More information about the wine-patches
mailing list