From d83a20af1d05b5958d3559482b715777a57dea7a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 23 Feb 2017 14:53:27 +0100 Subject: Improve time stamp precision of qmake's touch function On POSIX compliant platforms, the default precision we apply to preserving time stamps is seconds. However we can do better and use utimensat() - if available - to increase the precision to nanoseconds. The values are provided by statbuf's st_mtim. This is guarded for compatibility with older systems, similar to commit 494ced13292fa9d7b572f5310090f6b8fab36e26. Change-Id: I6928660230d84f8511bf0f58e268906d2e575e04 Reviewed-by: Oswald Buddenhagen --- qmake/library/qmakebuiltins.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'qmake') diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp index b30373b596..808bf53da4 100644 --- a/qmake/library/qmakebuiltins.cpp +++ b/qmake/library/qmakebuiltins.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -1818,10 +1819,16 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( evalError(fL1S("Cannot stat() reference file %1: %2.").arg(rfn, fL1S(strerror(errno)))); return ReturnFalse; } +#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L + const struct timespec times[2] = { { 0, UTIME_NOW }, st.st_mtim }; + const bool utimeError = utimensat(AT_FDCWD, tfn.toLocal8Bit().constData(), times, 0) < 0; +#else struct utimbuf utb; utb.actime = time(0); utb.modtime = st.st_mtime; - if (utime(tfn.toLocal8Bit().constData(), &utb)) { + const bool utimeError = utime(tfn.toLocal8Bit().constData(), &utb) < 0; +#endif + if (utimeError) { evalError(fL1S("Cannot touch %1: %2.").arg(tfn, fL1S(strerror(errno)))); return ReturnFalse; } -- cgit v1.2.3