Files
CMake/Source/cmFileTime.cxx
Brad King 8832f78dd6 IWYU: Update for Debian 13 CI job
`include-what-you-use` diagnostics, in practice, are specific to
the environment's compiler and standard library.  Update includes
to satisfy IWYU for our CI job under Debian 13.  Some patterns:

* Types named in virtual `override` signatures no longer require
  includes since the overridden signature already names them.

* A function argument's type needs to be included even if its constructor
  is called only by implicit conversion.  For example, constructing a
  `std::function` from a lambda now requires `<functional>`.

* Some prior mysterious `<type_traits>` inclusions are no longer required.
2025-11-12 14:54:35 -05:00

52 lines
1.5 KiB
C++

/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmFileTime.h"
#include <ctime>
#include <string>
// Use a platform-specific API to get file times efficiently.
#if !defined(_WIN32) || defined(__CYGWIN__)
# include "cm_sys_stat.h"
#else
# include <windows.h>
# include "cmsys/Encoding.hxx"
#endif
bool cmFileTime::Load(std::string const& fileName)
{
#if !defined(_WIN32) || defined(__CYGWIN__)
// POSIX version. Use the stat function.
struct stat fst;
if (::stat(fileName.c_str(), &fst) != 0) {
return false;
}
# if CMake_STAT_HAS_ST_MTIM
// Nanosecond resolution
this->Time = fst.st_mtim.tv_sec * UtPerS + fst.st_mtim.tv_nsec;
# elif CMake_STAT_HAS_ST_MTIMESPEC
// Nanosecond resolution
this->Time = fst.st_mtimespec.tv_sec * UtPerS + fst.st_mtimespec.tv_nsec;
# else
// Second resolution
this->Time = fst.st_mtime * UtPerS;
# endif
#else
// Windows version. Get the modification time from extended file attributes.
WIN32_FILE_ATTRIBUTE_DATA fdata;
if (!GetFileAttributesExW(cmsys::Encoding::ToWide(fileName).c_str(),
GetFileExInfoStandard, &fdata)) {
return false;
}
// Copy the file time to the output location.
using uint64 = unsigned long long;
this->Time = static_cast<TimeType>(
(uint64(fdata.ftLastWriteTime.dwHighDateTime) << 32) +
fdata.ftLastWriteTime.dwLowDateTime);
#endif
return true;
}