Commit ea7f9737 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

ntdll: Add support to NtWriteFile for special offset -1.

parent d71bf64e
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment