Skip to content

Commit

Permalink
support 64 bit filesizes when calling ACE_OS::fstat() and _FILE_OFFSE…
Browse files Browse the repository at this point in the history
…T_BITS==64 on Win32 systems
  • Loading branch information
Erik Sohns committed Jul 13, 2024
1 parent 2431f5e commit ea693d8
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions ACE/ace/OS_NS_sys_stat.inl
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,29 @@ namespace ACE_OS
ACE_OS::set_errno_to_last_error ();
return -1;
}
else if (fdata.nFileSizeHigh != 0)
if ((fdata.nFileSizeHigh != 0) && (sizeof (stp->st_size) < sizeof (ULONGLONG)))
{
errno = EINVAL;
errno = EINVAL; // return an error rather than incorrect values
return -1;
}
else
{
stp->st_size = fdata.nFileSizeLow;
stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime).sec ();
stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime).sec ();
stp->st_ctime = ACE_Time_Value (fdata.ftCreationTime).sec ();
stp->st_nlink = static_cast<short> (fdata.nNumberOfLinks);
stp->st_dev = stp->st_rdev = 0; // No equivalent conversion.
stp->st_mode = S_IXOTH | S_IROTH |
(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0 : S_IWOTH) |
(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? S_IFDIR : S_IFREG);
}

#if defined (_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
ULARGE_INTEGER ul;
ul.HighPart = fdata.nFileSizeHigh;
ul.LowPart = fdata.nFileSizeLow;
stp->st_size = ul.QuadPart;
#else
stp->st_size = fdata.nFileSizeLow;
#endif /* _FILE_OFFSET_BITS */
stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime).sec ();
stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime).sec ();
stp->st_ctime = ACE_Time_Value (fdata.ftCreationTime).sec ();
stp->st_nlink = static_cast<short> (fdata.nNumberOfLinks);
stp->st_dev = stp->st_rdev = 0; // No equivalent conversion.
stp->st_mode = S_IXOTH | S_IROTH |
(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0 : S_IWOTH) |
(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? S_IFDIR : S_IFREG);

return 0;
#elif defined (ACE_LACKS_FSTAT)
ACE_NOTSUP_RETURN (-1);
Expand Down

0 comments on commit ea693d8

Please sign in to comment.