1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmFileTime.h"
8 // Use a platform-specific API to get file times efficiently.
9 #if !defined(_WIN32) || defined(__CYGWIN__)
10 # include "cm_sys_stat.h"
14 # include "cmsys/Encoding.hxx"
17 bool cmFileTime::Load(std::string const& fileName)
19 #if !defined(_WIN32) || defined(__CYGWIN__)
20 // POSIX version. Use the stat function.
22 if (::stat(fileName.c_str(), &fst) != 0) {
25 # if CMake_STAT_HAS_ST_MTIM
26 // Nanosecond resolution
27 this->Time = fst.st_mtim.tv_sec * UtPerS + fst.st_mtim.tv_nsec;
28 # elif CMake_STAT_HAS_ST_MTIMESPEC
29 // Nanosecond resolution
30 this->Time = fst.st_mtimespec.tv_sec * UtPerS + fst.st_mtimespec.tv_nsec;
33 this->Time = fst.st_mtime * UtPerS;
36 // Windows version. Get the modification time from extended file attributes.
37 WIN32_FILE_ATTRIBUTE_DATA fdata;
38 if (!GetFileAttributesExW(cmsys::Encoding::ToWide(fileName).c_str(),
39 GetFileExInfoStandard, &fdata)) {
43 // Copy the file time to the output location.
44 using uint64 = unsigned long long;
46 this->Time = static_cast<TimeType>(
47 (uint64(fdata.ftLastWriteTime.dwHighDateTime) << 32) +
48 fdata.ftLastWriteTime.dwLowDateTime);