summaryrefslogtreecommitdiffstats
path: root/qmake/library/ioutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmake/library/ioutils.cpp')
-rw-r--r--qmake/library/ioutils.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp
index 67d2f541a1..39264952c6 100644
--- a/qmake/library/ioutils.cpp
+++ b/qmake/library/ioutils.cpp
@@ -37,8 +37,13 @@
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
+# include <utime.h>
+# include <fcntl.h>
+# include <errno.h>
#endif
+#define fL1S(s) QString::fromLatin1(s)
+
QT_BEGIN_NAMESPACE
using namespace QMakeInternal;
@@ -183,4 +188,69 @@ QString IoUtils::shellQuoteWin(const QString &arg)
return ret;
}
+#if defined(PROEVALUATOR_FULL)
+
+# if defined(Q_OS_WIN)
+static QString windowsErrorCode()
+{
+ wchar_t *string = 0;
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPWSTR)&string,
+ 0,
+ NULL);
+ QString ret = QString::fromWCharArray(string);
+ LocalFree((HLOCAL)string);
+ return ret.trimmed();
+}
+# endif
+
+bool IoUtils::touchFile(const QString &targetFileName, const QString &referenceFileName, QString *errorString)
+{
+# ifdef Q_OS_UNIX
+ struct stat st;
+ if (stat(referenceFileName.toLocal8Bit().constData(), &st)) {
+ *errorString = fL1S("Cannot stat() reference file %1: %2.").arg(referenceFileName, fL1S(strerror(errno)));
+ return false;
+ }
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
+ const struct timespec times[2] = { { 0, UTIME_NOW }, st.st_mtim };
+ const bool utimeError = utimensat(AT_FDCWD, targetFileName.toLocal8Bit().constData(), times, 0) < 0;
+# else
+ struct utimbuf utb;
+ utb.actime = time(0);
+ utb.modtime = st.st_mtime;
+ const bool utimeError= utime(targetFileName.toLocal8Bit().constData(), &utb) < 0;
+# endif
+ if (utimeError) {
+ *errorString = fL1S("Cannot touch %1: %2.").arg(targetFileName, fL1S(strerror(errno)));
+ return false;
+ }
+# else
+ HANDLE rHand = CreateFile((wchar_t*)referenceFileName.utf16(),
+ GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (rHand == INVALID_HANDLE_VALUE) {
+ *errorString = fL1S("Cannot open reference file %1: %2").arg(referenceFileName, windowsErrorCode());
+ return false;
+ }
+ FILETIME ft;
+ GetFileTime(rHand, 0, 0, &ft);
+ CloseHandle(rHand);
+ HANDLE wHand = CreateFile((wchar_t*)targetFileName.utf16(),
+ GENERIC_WRITE, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (wHand == INVALID_HANDLE_VALUE) {
+ *errorString = fL1S("Cannot open %1: %2").arg(targetFileName, windowsErrorCode());
+ return false;
+ }
+ SetFileTime(wHand, 0, 0, &ft);
+ CloseHandle(wHand);
+# endif
+ return true;
+}
+#endif
+
QT_END_NAMESPACE