From ea693d86142c6b4b293a7a9e49f27c4fc48ac897 Mon Sep 17 00:00:00 2001 From: Erik Sohns Date: Sat, 13 Jul 2024 21:31:23 +0200 Subject: [PATCH] support 64 bit filesizes when calling ACE_OS::fstat() and _FILE_OFFSET_BITS==64 on Win32 systems --- ACE/ace/OS_NS_sys_stat.inl | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/ACE/ace/OS_NS_sys_stat.inl b/ACE/ace/OS_NS_sys_stat.inl index b3a7d38e142ef..c8ee9e08d138a 100644 --- a/ACE/ace/OS_NS_sys_stat.inl +++ b/ACE/ace/OS_NS_sys_stat.inl @@ -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 (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 (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);