Commit 7f5f904c authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fix errno set on write to read-only file.

parent 3fd47b46
......@@ -3590,6 +3590,8 @@ int CDECL _write(int fd, const void* buf, unsigned int count)
TRACE("WriteFile (fd %d, hand %p) failed-last error (%ld)\n", fd,
hand, GetLastError());
msvcrt_set_errno(GetLastError());
if (GetLastError() == ERROR_ACCESS_DENIED)
*_errno() = EBADF;
num_written = -1;
}
......@@ -3718,6 +3720,8 @@ int CDECL _write(int fd, const void* buf, unsigned int count)
TRACE("WriteFile/WriteConsoleW (fd %d, hand %p) failed-last error (%ld)\n", fd,
hand, GetLastError());
msvcrt_set_errno(GetLastError());
if (GetLastError() == ERROR_ACCESS_DENIED)
*_errno() = EBADF;
release_ioinfo(info);
return -1;
}
......
......@@ -312,6 +312,12 @@ static void test_readmode( BOOL ascii_mode )
ok(lstrlenA(buffer) == 2+ao,"line 2 fgets got size %d should be %d in %s\n",
lstrlenA(buffer), 2+ao, IOMODE);
errno = 0xdeadbeef;
_doserrno = 0xdeadbeef;
ok(write(fd, buffer, 1) == -1, "read succeeded on write-only file\n");
ok(errno == EBADF, "errno = %d\n", errno);
ok(_doserrno == ERROR_ACCESS_DENIED, "doserrno = %ld\n", _doserrno);
/* test fread across buffer boundary */
rewind(file);
ok(ftell(file) == 0,"Did not start at beginning of file in %s\n", IOMODE);
......
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