* 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.
This commit is contained in:
Christopher Faylor 2000-11-26 21:45:16 +00:00
parent e0cdea91fe
commit fe1c7fe7a6
2 changed files with 30 additions and 0 deletions

View File

@ -1,3 +1,10 @@
Sun Nov 26 16:26:14 2000 Christopher Faylor <cgf@cygnus.com>
* 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.
Sun Nov 26 14:37:29 2000 Christopher Faylor <cgf@cygnus.com>
* include/cygwin/version.h: Bump DLL minor version number to 7.

View File

@ -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);