diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2016-12-31 08:33:01 (GMT) |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-09-16 07:54:11 (GMT) |
commit | f50a5250e49347df802d7844358f5ea567ddfac2 (patch) | |
tree | f0ae320a2dcd0e2031f42f1eb5f6a4ffc15afdad | |
parent | 5fcdcf95cb62ab3d593c36ef90df27cef63874a1 (diff) | |
download | Ninja-f50a5250e49347df802d7844358f5ea567ddfac2.zip Ninja-f50a5250e49347df802d7844358f5ea567ddfac2.tar.gz Ninja-f50a5250e49347df802d7844358f5ea567ddfac2.tar.bz2 |
Read file timestamps in higher resolution.
This uses nanoseconds on POSIX (±~292 years) and 100-ns increments on
Windows (±~29247 years).
The fallbacks to different structure fields is the only thing grabbed
from #337, with a slight modification in implementation.
-rw-r--r-- | src/disk_interface.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc index 28530b1..ffa58db 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -61,12 +61,11 @@ int MakeDir(const string& path) { TimeStamp TimeStampFromFileTime(const FILETIME& filetime) { // FILETIME is in 100-nanosecond increments since the Windows epoch. // We don't much care about epoch correctness but we do want the - // resulting value to fit in an integer. + // resulting value to fit in a 64-bit integer. uint64_t mtime = ((uint64_t)filetime.dwHighDateTime << 32) | ((uint64_t)filetime.dwLowDateTime); - mtime /= 1000000000LL / 100; // 100ns -> s. - mtime -= 12622770400LL; // 1600 epoch -> 2000 epoch (subtract 400 years). - return (TimeStamp)mtime; + // 1600 epoch -> 2000 epoch (subtract 400 years). + return (TimeStamp)mtime - 12622770400LL * 1000000000LL / 100; } TimeStamp StatSingleFile(const string& path, string* err) { @@ -192,7 +191,17 @@ TimeStamp RealDiskInterface::Stat(const string& path, string* err) const { // that it doesn't exist. if (st.st_mtime == 0) return 1; - return st.st_mtime; +#if defined(__APPLE__) && !defined(_POSIX_C_SOURCE) + return ((int64_t)st.st_mtimespec.tv_sec * 1000000000LL + + st.st_mtimespec.tv_nsec); +#elif defined(_LARGEFILE64_SOURCE) + return (int64_t)st.st_mtim.tv_sec * 1000000000LL + st.st_mtim.tv_nsec; +#elif defined(__CYGWIN__) + return (int64_t)st.st_mtime * 1000000000LL; +#else + // see http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html + return (int64_t)st.st_mtime * 1000000000LL + st.st_mtimensec; +#endif #endif } |