https://bugs.winehq.org/show_bug.cgi?id=53677
--- Comment #8 from Piotr Caban piotr.caban@gmail.com --- (In reply to Fabian Maurer from comment #7)
Huh, is the file being opened read only really the only case where we can get ERROR_ACCESS_DENIED? I thought there might be others...
I'm also not sure if the change is correct but there's a big chance it is. Native sets errno, doserrno and GetLastError to EBADF and ERROR_ACCESS_DENIED. Since it's very unlikely that SetLastError is called directly in msvcrt I assume that ReadFile is called. Msvcrt does not store open mode of fd, one would need to call e.g. NtQueryInformationFile to distinguish between ERROR_ACCESS_DENIED errors. Probably the only way of checking it is to create a custom device handle that will return ERROR_ACCESS_DENIED on read. Since it's hard to test and is an unlikely use case I didn't test it.