diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e6e2f125f..67cbb46d1 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +Wed Apr 26 16:20:00 2000 Corinna Vinschen + + * syscalls.cc (stat_worker): Previous patch could succeed + in stating a non-existant file. + Wed Apr 26 01:07:16 2000 Christopher Faylor * exceptions.cc (interruptible): Allocate slightly more space for diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index e5f087161..d45909883 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -978,6 +978,7 @@ stat_worker (const char *caller, const char *name, struct stat *buf, int nofollow) { int res = -1; + int oret = 1; int atts; char root[MAX_PATH]; UINT dtype; @@ -1013,8 +1014,8 @@ stat_worker (const char *caller, const char *name, struct stat *buf, (os_being_run == winNT && dtype != DRIVE_NO_ROOT_DIR && dtype != DRIVE_UNKNOWN)) - && fh.open (real_path, O_RDONLY | O_BINARY | O_DIROPEN | - (nofollow ? O_NOSYMLINK : 0), 0)) + && (oret = fh.open (real_path, O_RDONLY | O_BINARY | O_DIROPEN | + (nofollow ? O_NOSYMLINK : 0), 0))) { res = fh.fstat (buf); fh.close (); @@ -1029,10 +1030,10 @@ stat_worker (const char *caller, const char *name, struct stat *buf, buf->st_nlink = (dtype == DRIVE_REMOTE ? 1 : num_entries (real_path.get_win32 ())); } - else if (atts != -1 || GetLastError () != ERROR_FILE_NOT_FOUND) + else if (atts != -1 || (!oret && get_errno () != ENOENT)) { - /* Unfortunately, the above open may fail. So we have - to care for this case here, too. */ + /* Unfortunately, the above open may fail if the file exists, though. + So we have to care for this case here, too. */ WIN32_FIND_DATA wfd; HANDLE handle; buf->st_nlink = 1;