Module: wine Branch: master Commit: ea7f9737bd855287d72e78e0f598387989eb7342 URL: http://source.winehq.org/git/wine.git/?a=commit;h=ea7f9737bd855287d72e78e0f5...
Author: Dmitry Timoshkov dmitry@baikal.ru Date: Tue Sep 10 20:20:03 2013 +0900
ntdll: Add support to NtWriteFile for special offset -1.
---
dlls/ntdll/file.c | 18 ++++++++++++++++-- dlls/ntdll/tests/file.c | 15 --------------- 2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index 9420df5..f7f80e6 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -969,8 +969,22 @@ NTSTATUS WINAPI NtWriteFile(HANDLE hFile, HANDLE hEvent,
if (offset && offset->QuadPart != (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */) { + off_t off = offset->QuadPart; + + if (offset->QuadPart == (LONGLONG)-1 /* FILE_WRITE_TO_END_OF_FILE */) + { + struct stat st; + + if (fstat( unix_handle, &st ) == -1) + { + status = FILE_GetNtStatus(); + goto done; + } + off = st.st_size; + } + /* 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 +996,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);