diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 289b7288c..d90f03902 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2011-05-05 Corinna Vinschen + + * fhandler_disk_file.cc (fhandler_disk_file::pread): Correctly return + with errno set to EBADF if file open mode is incorrect. + (fhandler_disk_file::pwrite): Ditto. + 2011-05-05 Corinna Vinschen * fhandler.cc (is_at_eof): Drop static storage class. Drop err diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 1c586f3c6..b491fd34f 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -1415,6 +1415,12 @@ out: ssize_t __stdcall fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset) { + if ((get_flags () & O_ACCMODE) == O_WRONLY) + { + set_errno (EBADF); + return -1; + } + /* In binary mode, we can use an atomic NtReadFile call. */ if (rbinary ()) { @@ -1476,6 +1482,12 @@ fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset) ssize_t __stdcall fhandler_disk_file::pwrite (void *buf, size_t count, _off64_t offset) { + if ((get_flags () & O_ACCMODE) == O_RDONLY) + { + set_errno (EBADF); + return -1; + } + /* In binary mode, we can use an atomic NtWriteFile call. */ if (wbinary ()) {