Commit 3fd47b46 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

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

parent c69f1955
......@@ -2756,6 +2756,8 @@ static int read_utf8(ioinfo *fdinfo, wchar_t *buf, unsigned int count)
return 0;
}else {
msvcrt_set_errno(GetLastError());
if (GetLastError() == ERROR_ACCESS_DENIED)
*_errno() = EBADF;
return -1;
}
}else if(!num_read) {
......@@ -2813,6 +2815,8 @@ static int read_utf8(ioinfo *fdinfo, wchar_t *buf, unsigned int count)
return 0;
}else {
msvcrt_set_errno(GetLastError());
if (GetLastError() == ERROR_ACCESS_DENIED)
*_errno() = EBADF;
if (readbuf != min_buf) free(readbuf);
return -1;
}
......@@ -3041,6 +3045,8 @@ static int read_i(int fd, ioinfo *fdinfo, void *buf, unsigned int count)
{
TRACE(":failed-last error (%ld)\n", GetLastError());
msvcrt_set_errno(GetLastError());
if (GetLastError() == ERROR_ACCESS_DENIED)
*_errno() = EBADF;
return -1;
}
}
......
......@@ -258,6 +258,13 @@ static void test_readmode( BOOL ascii_mode )
write (fd, &padbuffer[i], 1);
write (fd, nlbuffer, strlen(nlbuffer));
write (fd, outbuffer, sizeof (outbuffer));
errno = 0xdeadbeef;
_doserrno = 0xdeadbeef;
ok(read(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);
close (fd);
if (ascii_mode) {
......
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