summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2016-11-17 16:10:11 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2016-11-22 19:10:05 +0000
commite2b856d56290e9b3eaaf889b3e0a08badbaa6046 (patch)
treee7bd0a780ffb8c2ae5f9bddcd08431368b8d0292
parent53edaf0fb7146e20029afcdbb57003025db8b7bf (diff)
QDir::tempPath - use NSTemporaryDirectory on Darwin
Instead of hardcoded "/tmp". Task-number: QTBUG-57165 Change-Id: I9d3ae157c22ce131281b8279149eea87a26244e8 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 3cc27bf847..a3b28a8d95 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -59,6 +59,13 @@
#include <MobileCoreServices/MobileCoreServices.h>
#endif
+#if defined(Q_OS_DARWIN)
+// We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but
+// we need these declarations:
+Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
+extern "C" NSString *NSTemporaryDirectory();
+#endif
+
QT_BEGIN_NAMESPACE
#if defined(Q_OS_DARWIN)
@@ -706,8 +713,17 @@ QString QFileSystemEngine::tempPath()
return QDir::cleanPath(temp);
#else
QString temp = QFile::decodeName(qgetenv("TMPDIR"));
- if (temp.isEmpty())
- temp = QLatin1String("/tmp");
+ if (temp.isEmpty()) {
+#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)
+ if (NSString *nsPath = NSTemporaryDirectory()) {
+ temp = QString::fromCFString((CFStringRef)nsPath);
+ } else {
+#else
+ {
+#endif
+ temp = QLatin1String("/tmp");
+ }
+ }
return QDir::cleanPath(temp);
#endif
}