aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/tools/filetime.h
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2018-05-17 18:39:20 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2018-05-18 14:42:08 +0000
commit2aa3131bef6444a800f6e6259cecf44851eb0454 (patch)
treed1d6a254734ca2cea668999ca7f68cc5fa5b4079 /src/lib/corelib/tools/filetime.h
parent6acefea159067b2bb512a964f52cf905042a5ad1 (diff)
Fix FileTime and FileInfo stat times implementation on macOS
This requires a couple of changes: 1) When targeting macOS 10.12+, clock_gettime is available and can be used directly for FileTime::currentTime(). 2) For lower versions, we partially implement the clock_gettime CLOCK_REALTIME usecase, as it is done in macOS libc sources, and explicitly use that version. 3) The file stat structure has slightly different field names on macOS, so the accessed names were adjusted in FileInfo::lastModified() and FileInfo::lastStatusChange(). Two more things are worth mentioning: 1) Both the stock and custom implementations of clock_gettime() have 1000nsec = 1microsecond resolution, and not a 1ns one. 2) The stat.st_mtimespec field can store nanosecond values, but in practice with HFS+ the date resolution is 1 second. This is not true for APFS, which has a 1ns resolution. Change-Id: I1ecdc6e9db7a9c1dc5f9a9a0859ec25a34165c4d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/lib/corelib/tools/filetime.h')
-rw-r--r--src/lib/corelib/tools/filetime.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/lib/corelib/tools/filetime.h b/src/lib/corelib/tools/filetime.h
index d68c6ac4a..73e9d4544 100644
--- a/src/lib/corelib/tools/filetime.h
+++ b/src/lib/corelib/tools/filetime.h
@@ -45,17 +45,27 @@
#include <QtCore/qdatastream.h>
#include <QtCore/qdebug.h>
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(__APPLE__)
#include <time.h>
-#define BUILD_HOST_HAS_CLOCK_GETTIME (_POSIX_C_SOURCE >= 199309L)
+#define HAS_CLOCK_GETTIME (_POSIX_C_SOURCE >= 199309L)
+#endif // Q_OS_UNIX
+
#ifdef __APPLE__
+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
-#define HAS_CLOCK_GETTIME BUILD_HOST_HAS_CLOCK_GETTIME
+// macOS 10.12+ ships clock_gettime.
+#else
+// We implement our own clock_gettime.
+#define APPLE_CUSTOM_CLOCK_GETTIME 1
#endif // __MAC_OS_X_VERSION_MIN_REQUIRED
-#else // __APPLE__
-#define HAS_CLOCK_GETTIME BUILD_HOST_HAS_CLOCK_GETTIME
+
+// Either way we have a clock_gettime in the end.
+#define HAS_CLOCK_GETTIME 1
+
+// Apple stat struct has slightly different names for time fields.
+#define APPLE_STAT_TIMESPEC 1
+
#endif // __APPLE__
-#endif // Q_OS_UNIX
namespace qbs {
namespace Internal {