Exemple #1
0
int
rpl_fstat (int fd, struct stat *buf)
{
#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
  /* Handle the case when rpl_open() used a dummy file descriptor to work
     around an open() that can't normally visit directories.  */
  const char *name = _gl_directory_name (fd);
  if (name != NULL)
    return stat (name, buf);
#endif

#ifdef WINDOWS_NATIVE
  /* Fill the fields ourselves, because the original fstat function returns
     values for st_atime, st_mtime, st_ctime that depend on the current time
     zone.  See
     <https://lists.gnu.org/r/bug-gnulib/2017-04/msg00134.html>  */
  HANDLE h = (HANDLE) _get_osfhandle (fd);

  if (h == INVALID_HANDLE_VALUE)
    {
      errno = EBADF;
      return -1;
    }
  return _gl_fstat_by_handle (h, NULL, buf);
#else
  return stat_time_normalize (orig_fstat (fd, buf), buf);
#endif
}
Exemple #2
0
static int
fstat_nothrow (int fd, struct stat *buf)
{
  int result;

  TRY_MSVC_INVAL
    {
      result = orig_fstat (fd, buf);
    }
  CATCH_MSVC_INVAL
    {
      result = -1;
      errno = EBADF;
    }
  DONE_MSVC_INVAL;

  return result;
}