qmake: improve time stamp precision of the touch() function

sync-up with qmake; no effect on creator.

Change-Id: I6928660230d84f8511bf0f58e268906d2e575e04
(cherry picked from qtbase/d83a20af1d05b5958d3559482b715777a57dea7a)
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Simon Hausmann
2017-02-23 14:53:27 +01:00
committed by Oswald Buddenhagen
parent 1ccf674e97
commit 6bee0b695d

View File

@@ -54,6 +54,7 @@
#include <time.h>
#include <utime.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
@@ -1828,10 +1829,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;
}