This is the mail archive of the
cygwin-cvs@cygwin.com
mailing list for the Cygwin project.
[newlib-cygwin] cygwin: pread() returns non-zero if read beyond EOF
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: cygwin-cvs at sourceware dot org
- Date: 8 Nov 2017 12:32:16 -0000
- Subject: [newlib-cygwin] cygwin: pread() returns non-zero if read beyond EOF
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=46702f92ea499d15cb43c7c46ff9ad05f26aec6d
commit 46702f92ea499d15cb43c7c46ff9ad05f26aec6d
Author: Xiaofeng Liu <liuxf09@yahoo.com>
Date: Wed Nov 8 13:21:30 2017 +0100
cygwin: pread() returns non-zero if read beyond EOF
NtReadFile returns EOF status but doesn't set information to 0.
Set return value explicitly on EOF.
Diff:
---
winsup/cygwin/fhandler_disk_file.cc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index bc8fead..2e4cf49 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -1529,7 +1529,9 @@ fhandler_disk_file::pread (void *buf, size_t count, off_t offset)
goto non_atomic;
status = NtReadFile (prw_handle, NULL, NULL, NULL, &io, buf, count,
&off, NULL);
- if (!NT_SUCCESS (status) && status != STATUS_END_OF_FILE)
+ if (status == STATUS_END_OF_FILE)
+ res = 0;
+ else if (!NT_SUCCESS (status))
{
if (pc.isdir ())
{
@@ -1557,7 +1559,8 @@ fhandler_disk_file::pread (void *buf, size_t count, off_t offset)
__seterrno_from_nt_status (status);
return -1;
}
- res = io.Information; /* Valid on EOF. */
+ else
+ res = io.Information; /* Valid on EOF. */
}
else
{