Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-11-27 00:45:16 +0300
committerChristopher Faylor <me@cgf.cx>2000-11-27 00:45:16 +0300
commitfe1c7fe7a6f2a3e422c1185e3126208ce48d434b (patch)
tree5b0c94bce2af40c9ebd7fdea04de45612267e638 /winsup/cygwin/fhandler.cc
parente0cdea91fe6d67230cb9f2f624c9e39865dbeca1 (diff)
* fhandler.cc (is_at_eof): New function.
(fhandler_base::raw_read): Detect special case where last error == ERROR_NOACCESS but the file is at EOF. Most UNIXes do not consider this to be an error.
Diffstat (limited to 'winsup/cygwin/fhandler.cc')
-rw-r--r--winsup/cygwin/fhandler.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 3efd81efb..ed0ebb42f 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -186,6 +186,26 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit
}
}
+/* Detect if we are sitting at EOF for conditions where Windows
+ returns an error but UNIX doesn't. */
+static int __stdcall
+is_at_eof (HANDLE h, DWORD err)
+{
+ DWORD size, upper1, curr;
+
+ size = GetFileSize (h, &upper1);
+ if (upper1 != 0xffffffff || GetLastError () == NO_ERROR)
+ {
+ LONG upper2 = 0;
+ curr = SetFilePointer (h, 0, &upper2, FILE_CURRENT);
+ if (curr == size && upper1 == (DWORD) upper2)
+ return 1;
+ }
+
+ SetLastError (err);
+ return 0;
+}
+
/* Normal file i/o handlers. */
/* Cover function to ReadFile to achieve (as much as possible) Posix style
@@ -211,6 +231,9 @@ fhandler_base::raw_read (void *ptr, size_t ulen)
case ERROR_MORE_DATA:
/* `bytes_read' is supposedly valid. */
break;
+ case ERROR_NOACCESS:
+ if (is_at_eof (get_handle (), errcode))
+ return 0;
default:
syscall_printf ("ReadFile %s failed, %E", unix_path_name_);
__seterrno_from_win_error (errcode);