Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/DefaultFileSystem.cpp

Issue 10565049: Implement milliseconds time resolution for lastModified on Linux and Android (Closed)
Patch Set: Created May 14, 2013, 12:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/DefaultFileSystem.cpp
===================================================================
--- a/src/DefaultFileSystem.cpp
+++ b/src/DefaultFileSystem.cpp
@@ -117,23 +117,26 @@ FileSystem::StatResult DefaultFileSystem
if (errno == ENOENT)
return result;
throw RuntimeErrorWithErrno("Unable to stat " + path);
}
result.exists = true;
result.isFile = S_ISREG(nativeStat.st_mode);
result.isDirectory = S_ISDIR(nativeStat.st_mode);
- /*
- * In order to get millisecond resolution for modification times, it's necessary to use the 'stat' structure defined in
- * POSIX 2008, which has 'struct timespec st_mtim' instead of 'time_t st_mtime'. Use "#define _POSIX_C_SOURCE 200809L"
- * before the headers to invoke. The trouble is that not all systems may have this available, a category that includes
- * MS Windows, and so we'll need multiple implementations.
- */
- result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000;
+ #define MSEC_IN_SEC 1000
+ #define NSEC_IN_MSEC 1000000
+ // Note: _POSIX_C_SOURCE macro is defined automatically on Linux due to g++
+ // defining _GNU_SOURCE macro.
+#if _POSIX_C_SOURCE >= 200809L
+ result.lastModified = static_cast<int64_t>(nativeStat.st_mtim.tv_sec) * MSEC_IN_SEC
+ + static_cast<int64_t>(nativeStat.st_mtim.tv_nsec) / NSEC_IN_MSEC;
+#else
+ result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * MSEC_IN_SEC;
+#endif
return result;
#endif
}
std::string DefaultFileSystem::Resolve(const std::string& path) const
{
if (basePath == "")
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld