diff options
Diffstat (limited to 'src/lib/corelib/tools')
-rw-r--r-- | src/lib/corelib/tools/fileinfo.cpp | 8 | ||||
-rw-r--r-- | src/lib/corelib/tools/filetime.cpp | 21 | ||||
-rw-r--r-- | src/lib/corelib/tools/filetime.h | 22 |
3 files changed, 43 insertions, 8 deletions
diff --git a/src/lib/corelib/tools/fileinfo.cpp b/src/lib/corelib/tools/fileinfo.cpp index c4ba0e5e0..a1571b954 100644 --- a/src/lib/corelib/tools/fileinfo.cpp +++ b/src/lib/corelib/tools/fileinfo.cpp @@ -371,7 +371,9 @@ bool FileInfo::exists() const FileTime FileInfo::lastModified() const { -#if HAS_CLOCK_GETTIME +#if APPLE_STAT_TIMESPEC + return m_stat.st_mtimespec; +#elif HAS_CLOCK_GETTIME return m_stat.st_mtim; #else return m_stat.st_mtime; @@ -380,7 +382,9 @@ FileTime FileInfo::lastModified() const FileTime FileInfo::lastStatusChange() const { -#if HAS_CLOCK_GETTIME +#if APPLE_STAT_TIMESPEC + return m_stat.st_ctimespec; +#elif HAS_CLOCK_GETTIME return m_stat.st_ctim; #else return m_stat.st_ctime; diff --git a/src/lib/corelib/tools/filetime.cpp b/src/lib/corelib/tools/filetime.cpp index 3f7148594..8b34ba81e 100644 --- a/src/lib/corelib/tools/filetime.cpp +++ b/src/lib/corelib/tools/filetime.cpp @@ -55,6 +55,20 @@ template<bool> struct CompileTimeAssert; template<> struct CompileTimeAssert<true> {}; #endif +#ifdef APPLE_CUSTOM_CLOCK_GETTIME +#include <sys/time.h> +// clk_id isn't used, only the CLOCK_REALTIME case is implemented. +int clock_gettime(int /*clk_id*/, struct timespec *t) +{ + struct timeval tv; + // Resolution of gettimeofday is 1000nsecs = 1 microsecond. + int ret = gettimeofday(&tv, NULL); + t->tv_sec = tv.tv_sec; + t->tv_nsec = tv.tv_usec * 1000; + return ret; +} +#endif + FileTime::FileTime() { #ifdef Q_OS_WIN @@ -124,6 +138,13 @@ FileTime FileTime::currentTime() FILETIME *const ft = reinterpret_cast<FILETIME *>(&result.m_fileTime); SystemTimeToFileTime(&st, ft); return result; +#elif defined APPLE_CUSTOM_CLOCK_GETTIME + InternalType t; + // Explicitly use our custom version, so that we don't get an additional unresolved symbol on a + // system that actually provides one, but isn't used due to the minimium deployment target + // being lower. + qbs::Internal::clock_gettime(CLOCK_REALTIME, &t); + return t; #elif HAS_CLOCK_GETTIME InternalType t; clock_gettime(CLOCK_REALTIME, &t); 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 { |