4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 12:29:32 +08:00

* dir.cc (readdir): Ensure that errno is *only* set when we've run out of

filenames.
* fhandler.cc (fhandler_disk_file::fstat): Use modern method for saving errno,
making it effective for the whole function.
This commit is contained in:
Christopher Faylor 2000-08-10 19:20:11 +00:00
parent 38a6bf987b
commit b58f5598cb
3 changed files with 26 additions and 34 deletions

View File

@ -1,3 +1,10 @@
Thu Aug 10 15:17:53 2000 Christopher Faylor <cgf@cygnus.com>
* dir.cc (readdir): Ensure that errno is *only* set when we've run out
of filenames.
* fhandler.cc (fhandler_disk_file::fstat): Use modern method for saving
errno, making it effective for the whole function.
Tue Aug 8 22:25:39 2000 Christopher Faylor <cgf@cygnus.com> Tue Aug 8 22:25:39 2000 Christopher Faylor <cgf@cygnus.com>
* select.cc (allocfd_set): Zero allocated fd_set. * select.cc (allocfd_set): Zero allocated fd_set.

View File

@ -128,8 +128,7 @@ readdir (DIR * dir)
{ {
WIN32_FIND_DATA buf; WIN32_FIND_DATA buf;
HANDLE handle; HANDLE handle;
struct dirent *res = 0; struct dirent *res = NULL;
int prior_errno;
if (dir->__d_cookie != __DIRENT_COOKIE) if (dir->__d_cookie != __DIRENT_COOKIE)
{ {
@ -138,40 +137,28 @@ readdir (DIR * dir)
return res; return res;
} }
if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE) if (dir->__d_u.__d_data.__handle == INVALID_HANDLE_VALUE)
{ {
if (FindNextFileA (dir->__d_u.__d_data.__handle, &buf) == 0) handle = FindFirstFileA (dir->__d_dirname, &buf);
DWORD lasterr = GetLastError ();
dir->__d_u.__d_data.__handle = handle;
if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES))
{ {
prior_errno = get_errno(); seterrno_from_win_error (__FILE__, __LINE__, lasterr);
(void) FindClose (dir->__d_u.__d_data.__handle);
dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
__seterrno ();
/* POSIX says you shouldn't set errno when readdir can't
find any more files; if another error we leave it set. */
if (get_errno () == ENMFILE)
set_errno (prior_errno);
syscall_printf ("%p = readdir (%p)", res, dir);
return res; return res;
} }
} }
else else if (!FindNextFileA (dir->__d_u.__d_data.__handle, &buf))
{ {
handle = FindFirstFileA (dir->__d_dirname, &buf); DWORD lasterr = GetLastError ();
(void) FindClose (dir->__d_u.__d_data.__handle);
if (handle == INVALID_HANDLE_VALUE) dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
{ /* POSIX says you shouldn't set errno when readdir can't
/* It's possible that someone else deleted or emptied the directory find any more files; so, if another error we leave it set. */
or some such between the opendir () call and here. */ if (lasterr != ERROR_NO_MORE_FILES)
prior_errno = get_errno (); seterrno_from_win_error (__FILE__, __LINE__, lasterr);
__seterrno (); syscall_printf ("%p = readdir (%p)", res, dir);
/* POSIX says you shouldn't set errno when readdir can't return res;
find any more files; if another error we leave it set. */
if (get_errno () == ENMFILE)
set_errno (prior_errno);
syscall_printf ("%p = readdir (%p)", res, dir);
return res;
}
dir->__d_u.__d_data.__handle = handle;
} }
/* We get here if `buf' contains valid data. */ /* We get here if `buf' contains valid data. */

View File

@ -865,7 +865,7 @@ fhandler_disk_file::fstat (struct stat *buf)
{ {
int res = 0; // avoid a compiler warning int res = 0; // avoid a compiler warning
BY_HANDLE_FILE_INFORMATION local; BY_HANDLE_FILE_INFORMATION local;
int old_errno = get_errno (); save_errno saved_errno;
memset (buf, 0, sizeof (*buf)); memset (buf, 0, sizeof (*buf));
@ -907,12 +907,10 @@ fhandler_disk_file::fstat (struct stat *buf)
if (!get_win32_name ()) if (!get_win32_name ())
{ {
set_errno (ENOENT); saved_errno.set (ENOENT);
return -1; return -1;
} }
set_errno (old_errno);
buf->st_atime = to_time_t (&local.ftLastAccessTime); buf->st_atime = to_time_t (&local.ftLastAccessTime);
buf->st_mtime = to_time_t (&local.ftLastWriteTime); buf->st_mtime = to_time_t (&local.ftLastWriteTime);
buf->st_ctime = to_time_t (&local.ftCreationTime); buf->st_ctime = to_time_t (&local.ftCreationTime);