diff -ur cygwin-1.3.10-1.orig/winsup/cygwin/fhandler.cc cygwin-1.3.10-1/winsup/cygwin/fhandler.cc --- cygwin-1.3.10-1.orig/winsup/cygwin/fhandler.cc Tue Feb 19 19:25:00 2002 +++ cygwin-1.3.10-1/winsup/cygwin/fhandler.cc Wed May 8 17:08:54 2002 @@ -241,6 +241,11 @@ /* This is really EOF. */ bytes_read = 0; break; + case ERROR_ACCESS_DENIED: + /* Windows returns this when reading from a file opened O_WRONLY, + but POSIX expects EBADF. */ + set_errno(EBADF); + return -1; case ERROR_MORE_DATA: /* `bytes_read' is supposedly valid. */ break; @@ -614,6 +619,11 @@ __seterrno (); if (get_errno () == EPIPE) raise (SIGPIPE); + /* Windows returns E_ACCESS_DENIED when writing to a file + opened with O_RDONLY, but POSIX expects EBADF. */ + if (get_errno () == EACCES) { + set_errno(EBADF); + } /* This might fail, but it's the best we can hope for */ SetFilePointer (get_handle (), current_position, 0, FILE_BEGIN); return -1;