[1/5] ntdll: Add support to NtWriteFile for special offset -1. Take 3.
Dmitry Timoshkov
dmitry at baikal.ru
Mon Sep 9 20:45:08 CDT 2013
This version of the patch should fix the failures caused by wrong file offset.
---
dlls/ntdll/file.c | 13 ++++++++++---
dlls/ntdll/tests/file.c | 15 ---------------
2 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 9420df5..1040aab 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -961,16 +961,23 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
if (type == FD_TYPE_FILE)
{
+ off_t off;
+
if (!(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)) && !offset)
{
status = STATUS_INVALID_PARAMETER;
goto done;
}
- if (offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */)
+ off = offset ? offset->QuadPart : (off_t)-2 /* FILE_USE_FILE_POINTER_POSITION */;
+
+ if (off == (off_t)-1 /* FILE_WRITE_TO_END_OF_FILE */)
+ off = lseek( unix_handle, 0, SEEK_END );
+
+ if (off != (off_t)-2 /* FILE_USE_FILE_POINTER_POSITION */)
{
/* async I/O doesn't make sense on regular files */
- while ((result = pwrite( unix_handle, buffer, length, offset->QuadPart )) == -1)
+ while ((result = pwrite( unix_handle, buffer, length, off )) == -1)
{
if (errno != EINTR)
{
@@ -982,7 +989,7 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
if (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT))
/* update file pointer position */
- lseek( unix_handle, offset->QuadPart + result, SEEK_SET );
+ lseek( unix_handle, off + result, SEEK_SET );
total = result;
status = STATUS_SUCCESS;
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 86f8a77..0b2a764 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -1976,25 +1976,10 @@ static void test_read_write(void)
iob.Information = -1;
offset.QuadPart = (LONGLONG)-1 /* FILE_WRITE_TO_END_OF_FILE */;
status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents + 7, sizeof(contents) - 7, &offset, NULL);
-todo_wine
ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
-todo_wine
ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
-todo_wine
ok(iob.Information == sizeof(contents) - 7, "expected sizeof(contents)-7, got %lu\n", iob.Information);
- /* FIXME: Remove once Wine is fixed */
- if (status != STATUS_SUCCESS)
- {
- iob.Status = -1;
- iob.Information = -1;
- offset.QuadPart = 7;
- status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents + 7, sizeof(contents) - 7, &offset, NULL);
- ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
- ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
- ok(iob.Information == sizeof(contents) - 7, "expected sizeof(contents)-7, got %lu\n", iob.Information);
- }
-
off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
--
1.8.3.4
More information about the wine-patches
mailing list