summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc12
2 files changed, 18 insertions, 0 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 289b7288c..d90f03902 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,11 @@
2011-05-05 Corinna Vinschen <corinna@vinschen.de>
+ * 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 <corinna@vinschen.de>
+
* fhandler.cc (is_at_eof): Drop static storage class. Drop err
parameter since we don't change the Win32 error here anymore.
(fhandler_base::raw_read): Accommodate change to is_at_eof.
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 ())
{