Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From d5686dae1e4acdc5ea51d025dd25e337a1028f2a Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Mon, 14 Feb 2011 17:55:29 +0100
- Subject: [PATCH 01/14] Test should fail, debug output here is useless
- ---
- tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp | 5 +----
- 1 files changed, 1 insertions(+), 4 deletions(-)
- diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- index f89e033..0ae3271 100644
- --- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- +++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- @@ -359,10 +359,7 @@ void tst_QTemporaryFile::stressTest()
- for (int i = 0; i < iterations; ++i) {
- QTemporaryFile file;
- file.setAutoRemove(false);
- - if (!file.open()) {
- - qDebug() << "Could not open File:" << file.fileName();
- - continue;
- - }
- + QVERIFY(file.open());
- QVERIFY(!names.contains(file.fileName()));
- names.insert(file.fileName());
- }
- --
- 1.7.3.4
- From 1ae062818c7577c24a686980621125e86c5df8b1 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Mon, 14 Feb 2011 17:57:04 +0100
- Subject: [PATCH 02/14] Adding unicode test case for QTemporaryFile
- Task-number: QTBUG-4796
- Reviewed-by: ?
- ---
- tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp | 122 ++++++++++++++++++++++
- 1 files changed, 122 insertions(+), 0 deletions(-)
- diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- index 0ae3271..995107a 100644
- --- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- +++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- @@ -75,6 +75,10 @@ public:
- public slots:
- void init();
- void cleanup();
- +
- + void initTestCase();
- + void cleanupTestCase();
- +
- private slots:
- void construction();
- void fileTemplate();
- @@ -97,9 +101,24 @@ private slots:
- void setTemplateAfterOpen();
- void autoRemoveAfterFailedRename();
- + void QTBUG_4796_data();
- + void QTBUG_4796();
- +
- public:
- };
- +void tst_QTemporaryFile::initTestCase()
- +{
- + // For QTBUG_4796
- + QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX"));
- +}
- +
- +void tst_QTemporaryFile::cleanupTestCase()
- +{
- + // From QTBUG_4796
- + QVERIFY(QDir().rmdir("test-XXXXXX"));
- +}
- +
- void tst_QTemporaryFile::construction()
- {
- QTemporaryFile file(0);
- @@ -591,5 +610,108 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename()
- cleaner.reset();
- }
- +void tst_QTemporaryFile::QTBUG_4796_data()
- +{
- + QTest::addColumn<QString>("prefix");
- + QTest::addColumn<QString>("suffix");
- + QTest::addColumn<bool>("openResult");
- +
- + QString unicode = QString::fromUtf8("\xc3\xa5\xc3\xa6\xc3\xb8");
- +
- + QTest::newRow("<empty>") << QString() << QString() << true;
- + QTest::newRow("blaXXXXXX") << QString("bla") << QString() << true;
- + QTest::newRow("XXXXXXbla") << QString() << QString("bla") << true;
- + QTest::newRow("does-not-exist/qt_temp.XXXXXX") << QString("does-not-exist/qt_temp") << QString() << false;
- + QTest::newRow("XXXXXX<unicode>") << QString() << unicode << true;
- + QTest::newRow("<unicode>XXXXXX") << unicode << QString() << true;
- + QTest::newRow("<unicode>XXXXXX<unicode>") << unicode << unicode << true;
- +}
- +
- +void tst_QTemporaryFile::QTBUG_4796()
- +{
- + QVERIFY(QDir("test-XXXXXX").exists());
- +
- + struct CleanOnReturn
- + {
- + ~CleanOnReturn()
- + {
- + Q_FOREACH(QString tempName, tempNames)
- + QFile::remove(tempName);
- + }
- +
- + void reset()
- + {
- + tempNames.clear();
- + }
- +
- + QStringList tempNames;
- + };
- +
- + CleanOnReturn cleaner;
- +
- + QFETCH(QString, prefix);
- + QFETCH(QString, suffix);
- + QFETCH(bool, openResult);
- +
- + {
- + QString fileTemplate1 = prefix + QString("XX") + suffix;
- + QString fileTemplate2 = prefix + QString("XXXX") + suffix;
- + QString fileTemplate3 = prefix + QString("XXXXXX") + suffix;
- + QString fileTemplate4 = prefix + QString("XXXXXXXX") + suffix;
- +
- + QTemporaryFile file1(fileTemplate1);
- + QTemporaryFile file2(fileTemplate2);
- + QTemporaryFile file3(fileTemplate3);
- + QTemporaryFile file4(fileTemplate4);
- + QTemporaryFile file5("test-XXXXXX/" + fileTemplate1);
- + QTemporaryFile file6("test-XXXXXX/" + fileTemplate3);
- +
- + QCOMPARE(file1.open(), openResult);
- + QCOMPARE(file2.open(), openResult);
- + QCOMPARE(file3.open(), openResult);
- + QCOMPARE(file4.open(), openResult);
- + QCOMPARE(file5.open(), openResult);
- + QCOMPARE(file6.open(), openResult);
- +
- + QCOMPARE(file1.exists(), openResult);
- + QCOMPARE(file2.exists(), openResult);
- + QCOMPARE(file3.exists(), openResult);
- + QCOMPARE(file4.exists(), openResult);
- + QCOMPARE(file5.exists(), openResult);
- + QCOMPARE(file6.exists(), openResult);
- +
- + // make sure the file exists under the *correct* name
- + if (openResult) {
- + cleaner.tempNames << file1.fileName()
- + << file2.fileName()
- + << file3.fileName()
- + << file4.fileName()
- + << file5.fileName()
- + << file6.fileName();
- +
- + QVERIFY(file1.fileName().startsWith(fileTemplate1 + QLatin1Char('.')));
- + QVERIFY(file2.fileName().startsWith(fileTemplate2 + QLatin1Char('.')));
- + QVERIFY(file5.fileName().startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.')));
- + QVERIFY(file6.fileName().startsWith("test-XXXXXX/" + prefix));
- +
- + if (!prefix.isEmpty()) {
- + QVERIFY(file3.fileName().startsWith(prefix));
- + QVERIFY(file4.fileName().startsWith(prefix));
- + }
- +
- + if (!suffix.isEmpty()) {
- + QVERIFY(file3.fileName().endsWith(suffix));
- + QVERIFY(file4.fileName().endsWith(suffix));
- + QVERIFY(file6.fileName().endsWith(suffix));
- + }
- + }
- + }
- +
- + Q_FOREACH(QString tempName, cleaner.tempNames)
- + QVERIFY( !QFile::exists(tempName) );
- +
- + cleaner.reset();
- +}
- +
- QTEST_MAIN(tst_QTemporaryFile)
- #include "tst_qtemporaryfile.moc"
- --
- 1.7.3.4
- From c14e04ef22147f972908b74d6e63a896b9dc9450 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Wed, 30 Mar 2011 14:11:33 +0200
- Subject: [PATCH 03/14] Extending fileTemplate autotest
- ... to also verify template prefix and corner cases with runs of less
- than 6 Xs.
- Reviewed-by: ?
- ---
- tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp | 40 ++++++++++++++--------
- 1 files changed, 26 insertions(+), 14 deletions(-)
- diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- index 995107a..4e36301 100644
- --- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- +++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
- @@ -163,26 +163,35 @@ void tst_QTemporaryFile::cleanup()
- void tst_QTemporaryFile::fileTemplate_data()
- {
- QTest::addColumn<QString>("constructorTemplate");
- + QTest::addColumn<QString>("prefix");
- QTest::addColumn<QString>("suffix");
- QTest::addColumn<QString>("fileTemplate");
- - QTest::newRow("constructor default") << "" << "" << "";
- - QTest::newRow("constructor with xxx sufix") << "qt_XXXXXXxxx" << "xxx" << "";
- - QTest::newRow("constructor with xXx sufix") << "qt_XXXXXXxXx" << "xXx" << "";
- - QTest::newRow("constructor with no sufix") << "qt_XXXXXX" << "" << "";
- - QTest::newRow("constructor with >6 X's and xxx suffix") << "qt_XXXXXXXXXXxxx" << "xxx" << "";
- - QTest::newRow("constructor with >6 X's, no suffix") << "qt_XXXXXXXXXX" << "" << "";
- -
- - QTest::newRow("set template, no suffix") << "" << "" << "foo";
- - QTest::newRow("set template, with lowercase XXXXXX") << "" << "xxxxxx" << "qt_XXXXXXxxxxxx";
- - QTest::newRow("set template, with xxx") << "" << ".xxx" << "qt_XXXXXX.xxx";
- - QTest::newRow("set template, with >6 X's") << "" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx";
- - QTest::newRow("set template, with >6 X's, no suffix") << "" << "" << "qt_XXXXXXXXXXXXXX";
- + QTest::newRow("constructor default") << "" << "." << "" << "";
- + QTest::newRow("constructor with xxx sufix") << "qt_XXXXXXxxx" << "qt_" << "xxx" << "";
- + QTest::newRow("constructor with xXx sufix") << "qt_XXXXXXxXx" << "qt_" << "xXx" << "";
- + QTest::newRow("constructor with no sufix") << "qt_XXXXXX" << "qt_" << "" << "";
- + QTest::newRow("constructor with >6 X's and xxx suffix") << "qt_XXXXXXXXXXxxx" << "qt_" << "xxx" << "";
- + QTest::newRow("constructor with >6 X's, no suffix") << "qt_XXXXXXXXXX" << "qt_" << "" << "";
- +
- + QTest::newRow("constructor with XXXX suffix") << "qt_XXXXXX_XXXX" << "qt_" << "_XXXX" << "";
- + QTest::newRow("constructor with XXXXX suffix") << "qt_XXXXXX_XXXXX" << "qt_" << "_XXXXX" << "";
- + QTest::newRow("constructor with XXXX prefix") << "qt_XXXX" << "qt_XXXX." << "" << "";
- + QTest::newRow("constructor with XXXXX prefix") << "qt_XXXXX" << "qt_XXXXX." << "" << "";
- + QTest::newRow("constructor with XXXX prefix and suffix") << "qt_XXXX_XXXXXX_XXXX" << "qt_XXXX_" << "_XXXX" << "";
- + QTest::newRow("constructor with XXXXX prefix and suffix") << "qt_XXXXX_XXXXXX_XXXXX" << "qt_XXXXX_" << "_XXXXX" << "";
- +
- + QTest::newRow("set template, no suffix") << "" << "foo" << "" << "foo";
- + QTest::newRow("set template, with lowercase XXXXXX") << "" << "qt_" << "xxxxxx" << "qt_XXXXXXxxxxxx";
- + QTest::newRow("set template, with xxx") << "" << "qt_" << ".xxx" << "qt_XXXXXX.xxx";
- + QTest::newRow("set template, with >6 X's") << "" << "qt_" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx";
- + QTest::newRow("set template, with >6 X's, no suffix") << "" << "qt_" << "" << "qt_XXXXXXXXXXXXXX";
- }
- void tst_QTemporaryFile::fileTemplate()
- {
- QFETCH(QString, constructorTemplate);
- + QFETCH(QString, prefix);
- QFETCH(QString, suffix);
- QFETCH(QString, fileTemplate);
- @@ -192,8 +201,11 @@ void tst_QTemporaryFile::fileTemplate()
- QCOMPARE(file.open(), true);
- - QCOMPARE(file.fileName().right(suffix.length()), suffix);
- - file.close();
- + if (prefix.length())
- + QCOMPARE(file.fileName().left(prefix.length()), prefix);
- +
- + if (suffix.length())
- + QCOMPARE(file.fileName().right(suffix.length()), suffix);
- }
- --
- 1.7.3.4
- From db8c0140a28ad4bf11f3225551419b2bc565cd85 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Fri, 25 Mar 2011 17:11:53 +0100
- Subject: [PATCH 04/14] Remove duplicate #include
- ---
- src/corelib/io/qtemporaryfile.cpp | 1 -
- 1 files changed, 0 insertions(+), 1 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 56ed746..1a07d08 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -49,7 +49,6 @@
- #include "private/qabstractfileengine_p.h"
- #include "private/qfsfileengine_p.h"
- -#include <stdlib.h>
- #if !defined(Q_OS_WINCE)
- # include <errno.h>
- # include <sys/stat.h>
- --
- 1.7.3.4
- From 0f7bd4898a67ff0cdf32b290dfed8bb826041f2c Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Wed, 10 Nov 2010 11:32:19 +0100
- Subject: [PATCH 05/14] Removing dead code in QTemporaryFile
- The option to create a directory is never used, so let's drop it. There
- are bigger issues with this code.
- Reviewed-by: ? pending
- ---
- src/corelib/io/qtemporaryfile.cpp | 22 ++++------------------
- 1 files changed, 4 insertions(+), 18 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 1a07d08..835f24f 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -108,7 +108,7 @@ QT_BEGIN_NAMESPACE
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- -static int _gettemp(char *path, int *doopen, int domkdir, int slen)
- +static int _gettemp(char *path, int *doopen, int slen)
- {
- char *start, *trv, *suffp;
- QT_STATBUF sbuf;
- @@ -119,11 +119,6 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
- pid_t pid;
- #endif
- - if (doopen && domkdir) {
- - errno = EINVAL;
- - return 0;
- - }
- -
- for (trv = path; *trv; ++trv)
- ;
- trv -= slen;
- @@ -166,7 +161,7 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
- * check the target directory; if you have six X's and it
- * doesn't exist this runs for a *very* long time.
- */
- - if (doopen || domkdir) {
- + if (doopen) {
- for (;; --trv) {
- if (trv <= path)
- break;
- @@ -234,15 +229,6 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
- }
- if (errno != EEXIST)
- return 0;
- - } else if (domkdir) {
- -#ifdef Q_OS_WIN
- - if (QT_MKDIR(path) == 0)
- -#else
- - if (QT_MKDIR(path, 0700) == 0)
- -#endif
- - return 1;
- - if (errno != EEXIST)
- - return 0;
- }
- #ifndef Q_OS_WIN
- else if (QT_LSTAT(path, &sbuf))
- @@ -281,7 +267,7 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
- static int qt_mkstemps(char *path, int slen)
- {
- int fd = 0;
- - return (_gettemp(path, &fd, 0, slen) ? fd : -1);
- + return (_gettemp(path, &fd, slen) ? fd : -1);
- }
- #endif
- @@ -391,7 +377,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
- return false;
- #else
- - if (!_gettemp(filename, 0, 0, suffixLength)) {
- + if (!_gettemp(filename, 0, suffixLength)) {
- delete [] filename;
- return false;
- }
- --
- 1.7.3.4
- From 890258bd43be1cc9a559d694dd067816ddb2971c Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Thu, 11 Nov 2010 15:22:49 +0100
- Subject: [PATCH 06/14] QTemporaryFile: More dead code elimination
- There are exactly 2 uses of the _gettemp function: one for windows
- platforms, one for all others. Windows requests a file name, others
- request a valid file descriptor for that file name.
- Despite the 2 distinct use cases, the code was full of #ifdefs to keep
- never used code paths compiling.
- With this change the qt_mkstemp wrapper is eliminated, together with
- dead code inside if (doopen) {} blocks on Windows platforms. The more
- proper Q_OS_WIN macro is preferred to Q_WS_WIN.
- _gettemp is also changed to return the valid file descriptor on
- non-Windows platforms.
- Reviewed-by: ? pending
- ---
- src/corelib/io/qtemporaryfile.cpp | 113 ++++++++++---------------------------
- 1 files changed, 29 insertions(+), 84 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 835f24f..bb38906 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -65,9 +65,6 @@
- #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- # include <process.h>
- -# if defined(_MSC_VER) && _MSC_VER >= 1400
- -# include <share.h>
- -# endif
- #endif
- #if defined(Q_OS_WINCE)
- @@ -108,7 +105,7 @@ QT_BEGIN_NAMESPACE
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- -static int _gettemp(char *path, int *doopen, int slen)
- +static int _gettemp(char *path, int slen)
- {
- char *start, *trv, *suffp;
- QT_STATBUF sbuf;
- @@ -126,7 +123,7 @@ static int _gettemp(char *path, int *doopen, int slen)
- --trv;
- if (trv < path) {
- errno = EINVAL;
- - return 0;
- + return -1;
- }
- #if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400
- pid = _getpid();
- @@ -157,82 +154,38 @@ static int _gettemp(char *path, int *doopen, int slen)
- }
- start = trv + 1;
- +#ifndef Q_OS_WIN
- /*
- * check the target directory; if you have six X's and it
- * doesn't exist this runs for a *very* long time.
- */
- - if (doopen) {
- - for (;; --trv) {
- - if (trv <= path)
- - break;
- - if (*trv == '/') {
- - *trv = '\0';
- -#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
- - if (trv - path == 2 && path[1] == ':') {
- - // Special case for Windows drives
- - // (e.g., "C:" => "C:\").
- - // ### Better to use a Windows
- - // call for this.
- - char drive[] = "c:\\";
- - drive[0] = path[0];
- - rval = QT_STAT(drive, &sbuf);
- - } else
- -#endif
- - rval = QT_STAT(path, &sbuf);
- - *trv = '/';
- - if (rval != 0)
- - return 0;
- - if (!S_ISDIR(sbuf.st_mode)) {
- - errno = ENOTDIR;
- - return 0;
- - }
- - break;
- + for (;; --trv) {
- + if (trv <= path)
- + break;
- + if (*trv == '/') {
- + *trv = '\0';
- + rval = QT_STAT(path, &sbuf);
- + *trv = '/';
- + if (rval != 0)
- + return -1;
- + if (!S_ISDIR(sbuf.st_mode)) {
- + errno = ENOTDIR;
- + return -1;
- }
- + break;
- }
- }
- +#endif
- for (;;) {
- - if (doopen) {
- -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400
- - if (_sopen_s(doopen, path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR|QT_OPEN_BINARY
- -# ifdef QT_LARGEFILE_SUPPORT
- - |QT_OPEN_LARGEFILE
- -# endif
- - , _SH_DENYNO, _S_IREAD | _S_IWRITE)== 0)
- -#else // WIN && !CE
- -# if defined(Q_OS_WINCE)
- - QString targetPath;
- - if (QDir::isAbsolutePath(QString::fromLatin1(path)))
- - targetPath = QLatin1String(path);
- - else
- - targetPath = QDir::currentPath().append(QLatin1Char('/')) + QLatin1String(path);
- -
- - if ((*doopen =
- - QT_OPEN(targetPath.toLocal8Bit(), O_CREAT|O_EXCL|O_RDWR
- -# else // CE
- - // this is Unix or older MSVC
- - if ((*doopen =
- - QT_OPEN(path, QT_OPEN_CREAT|O_EXCL|QT_OPEN_RDWR
- -# endif
- -# ifdef QT_LARGEFILE_SUPPORT
- - |QT_OPEN_LARGEFILE
- -# endif
- -# if defined(Q_OS_WINCE)
- - |_O_BINARY
- -# elif defined(Q_OS_WIN)
- - |O_BINARY
- -# endif
- - , 0600)) >= 0)
- -#endif // WIN && !CE
- - {
- - return 1;
- - }
- +#ifndef Q_OS_WIN
- + {
- + int fd = QT_OPEN(path, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600);
- + if (fd != -1)
- + return fd;
- if (errno != EEXIST)
- - return 0;
- + return -1;
- }
- -#ifndef Q_OS_WIN
- - else if (QT_LSTAT(path, &sbuf))
- - return (errno == ENOENT) ? 1 : 0;
- #else
- if (!QFileInfo(QLatin1String(path)).exists())
- return 1;
- @@ -241,10 +194,10 @@ static int _gettemp(char *path, int *doopen, int slen)
- /* tricky little algorwwithm for backward compatibility */
- for (trv = start;;) {
- if (!*trv)
- - return 0;
- + return -1;
- if (*trv == 'Z') {
- if (trv == suffp)
- - return 0;
- + return -1;
- *trv++ = 'a';
- } else {
- if (isdigit(*trv))
- @@ -253,7 +206,7 @@ static int _gettemp(char *path, int *doopen, int slen)
- *trv = 'A';
- else {
- if (trv == suffp)
- - return 0;
- + return -1;
- ++*trv;
- }
- break;
- @@ -263,14 +216,6 @@ static int _gettemp(char *path, int *doopen, int slen)
- /*NOTREACHED*/
- }
- -#ifndef Q_WS_WIN
- -static int qt_mkstemps(char *path, int slen)
- -{
- - int fd = 0;
- - return (_gettemp(path, &fd, slen) ? fd : -1);
- -}
- -#endif
- -
- //************* QTemporaryFileEngine
- class QTemporaryFileEngine : public QFSFileEngine
- {
- @@ -354,8 +299,8 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6);
- char *filename = qstrdup(qfilename.toLocal8Bit());
- -#ifndef Q_WS_WIN
- - int fd = qt_mkstemps(filename, suffixLength);
- +#ifndef Q_OS_WIN
- + int fd = _gettemp(filename, suffixLength);
- if (fd != -1) {
- // First open the fd as an external file descriptor to
- // initialize the engine properly.
- @@ -377,7 +322,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
- return false;
- #else
- - if (!_gettemp(filename, 0, suffixLength)) {
- + if (_gettemp(filename, suffixLength) == -1) {
- delete [] filename;
- return false;
- }
- --
- 1.7.3.4
- From c4e6fa24b20921a0b1bfeda3fe37da52ffeb2163 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Fri, 25 Mar 2011 18:13:04 +0100
- Subject: [PATCH 07/14] Don't pre-check if directory exists as it's unnecessary
- On Posix platforms, when attempting to atomically create file and obtain
- descriptor, we only continue if we get an EEXIST error. If the path
- points to a non-existing directory, we should get ENOENT and will fail
- as well.
- On Windows, the check was already ignored. We would detect the file does
- not exist, attempt to obtain a handle upon return to
- QTemporaryFileEngine::open and fail there without running "for a *very*
- long time".
- Checking if the directory exists beforehand is not only unnecessary it
- also constitutes a race condition. Trusting the result of this check is
- dangerous and doubly useless.
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 35 -----------------------------------
- 1 files changed, 0 insertions(+), 35 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index bb38906..a9bed8b 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -51,8 +51,6 @@
- #if !defined(Q_OS_WINCE)
- # include <errno.h>
- -# include <sys/stat.h>
- -# include <sys/types.h>
- #endif
- #include <stdlib.h>
- @@ -67,10 +65,6 @@
- # include <process.h>
- #endif
- -#if defined(Q_OS_WINCE)
- -# include <types.h>
- -#endif
- -
- #if defined(Q_OS_VXWORKS)
- # include <taskLib.h>
- #endif
- @@ -108,8 +102,6 @@ QT_BEGIN_NAMESPACE
- static int _gettemp(char *path, int slen)
- {
- char *start, *trv, *suffp;
- - QT_STATBUF sbuf;
- - int rval;
- #if defined(Q_OS_WIN)
- int pid;
- #else
- @@ -137,10 +129,6 @@ static int _gettemp(char *path, int slen)
- pid /= 10;
- }
- -#ifndef S_ISDIR
- -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
- -#endif
- -
- while (trv >= path && *trv == 'X') {
- char c;
- @@ -154,29 +142,6 @@ static int _gettemp(char *path, int slen)
- }
- start = trv + 1;
- -#ifndef Q_OS_WIN
- - /*
- - * check the target directory; if you have six X's and it
- - * doesn't exist this runs for a *very* long time.
- - */
- - for (;; --trv) {
- - if (trv <= path)
- - break;
- - if (*trv == '/') {
- - *trv = '\0';
- - rval = QT_STAT(path, &sbuf);
- - *trv = '/';
- - if (rval != 0)
- - return -1;
- - if (!S_ISDIR(sbuf.st_mode)) {
- - errno = ENOTDIR;
- - return -1;
- - }
- - break;
- - }
- - }
- -#endif
- -
- for (;;) {
- #ifndef Q_OS_WIN
- {
- --
- 1.7.3.4
- From 5c1d3a05fb32711261e5e57a58ac3805a3b9a3b4 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Mon, 28 Mar 2011 13:42:58 +0200
- Subject: [PATCH 08/14] Adding comments; variable scoping
- There should be no semantic differences, otherwise.
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 52 +++++++++++++++++++++---------------
- 1 files changed, 30 insertions(+), 22 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index a9bed8b..939ea34 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -102,11 +102,6 @@ QT_BEGIN_NAMESPACE
- static int _gettemp(char *path, int slen)
- {
- char *start, *trv, *suffp;
- -#if defined(Q_OS_WIN)
- - int pid;
- -#else
- - pid_t pid;
- -#endif
- for (trv = path; *trv; ++trv)
- ;
- @@ -117,32 +112,43 @@ static int _gettemp(char *path, int slen)
- errno = EINVAL;
- return -1;
- }
- +
- + // Initialize placeholder with random chars + PID.
- + {
- +#if defined(Q_OS_WIN)
- + int pid;
- +#else
- + pid_t pid;
- +#endif
- +
- #if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400
- - pid = _getpid();
- + pid = _getpid();
- #elif defined(Q_OS_VXWORKS)
- - pid = (pid_t) taskIdCurrent;
- + pid = (pid_t) taskIdCurrent;
- #else
- - pid = getpid();
- + pid = getpid();
- #endif
- - while (trv >= path && *trv == 'X' && pid != 0) {
- - *trv-- = (pid % 10) + '0';
- - pid /= 10;
- - }
- + while (trv >= path && *trv == 'X' && pid != 0) {
- + *trv-- = (pid % 10) + '0';
- + pid /= 10;
- + }
- - while (trv >= path && *trv == 'X') {
- - char c;
- + while (trv >= path && *trv == 'X') {
- + char c;
- - // CHANGE arc4random() -> random()
- - pid = (qrand() & 0xffff) % (26+26);
- - if (pid < 26)
- - c = pid + 'A';
- - else
- - c = (pid - 26) + 'a';
- - *trv-- = c;
- + // CHANGE arc4random() -> random()
- + int pid = (qrand() & 0xffff) % (26+26);
- + if (pid < 26)
- + c = pid + 'A';
- + else
- + c = (pid - 26) + 'a';
- + *trv-- = c;
- + }
- + start = trv + 1;
- }
- - start = trv + 1;
- for (;;) {
- + // Atomically create file and obtain handle
- #ifndef Q_OS_WIN
- {
- int fd = QT_OPEN(path, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600);
- @@ -158,6 +164,8 @@ static int _gettemp(char *path, int slen)
- /* tricky little algorwwithm for backward compatibility */
- for (trv = start;;) {
- + // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
- + // String progression: "ZZaiC" => "aabiC"
- if (!*trv)
- return -1;
- if (*trv == 'Z') {
- --
- 1.7.3.4
- From 8abe099089ec1c9e633fe33e9d79a345018b7aaa Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Fri, 25 Mar 2011 16:41:52 +0100
- Subject: [PATCH 09/14] Remove duplication with QCoreApplication::applicationId
- The duplication was there to allow qmake and other tools to compile
- without a full build of QtCore. Cleaning up this code justifies losing
- the benefit of PID-tagged temporary files in those tools.
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 24 +++++-------------------
- 1 files changed, 5 insertions(+), 19 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 939ea34..fe94964 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -61,12 +61,8 @@
- # include "private/qcore_unix_p.h" // overrides QT_OPEN
- #endif
- -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- -# include <process.h>
- -#endif
- -
- -#if defined(Q_OS_VXWORKS)
- -# include <taskLib.h>
- +#if defined(QT_BUILD_CORE_LIB)
- +#include "qcoreapplication.h"
- #endif
- QT_BEGIN_NAMESPACE
- @@ -115,23 +111,13 @@ static int _gettemp(char *path, int slen)
- // Initialize placeholder with random chars + PID.
- {
- -#if defined(Q_OS_WIN)
- - int pid;
- -#else
- - pid_t pid;
- -#endif
- -
- -#if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400
- - pid = _getpid();
- -#elif defined(Q_OS_VXWORKS)
- - pid = (pid_t) taskIdCurrent;
- -#else
- - pid = getpid();
- -#endif
- +#if defined(QT_BUILD_CORE_LIB)
- + qint64 pid = QCoreApplication::applicationPid();
- while (trv >= path && *trv == 'X' && pid != 0) {
- *trv-- = (pid % 10) + '0';
- pid /= 10;
- }
- +#endif
- while (trv >= path && *trv == 'X') {
- char c;
- --
- 1.7.3.4
- From 27de64cf56552202f8aa298c32f6b94f83dd56cd Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Mon, 28 Mar 2011 18:44:09 +0200
- Subject: [PATCH 10/14] Split argument validation of _gettemp as separate function
- This removes knowledge about the structure of the filename template from
- the randomization process and is a pre-requisite to adding Unicode
- support to the code.
- Task-number: QTBUG-4796
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 76 +++++++++++++++++++++++++------------
- 1 files changed, 51 insertions(+), 25 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index fe94964..f6e3426 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -95,9 +95,12 @@ QT_BEGIN_NAMESPACE
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- +static int createFileFromTemplate(char *const path,
- + char *const placeholderStart, char *const placeholderEnd);
- +
- static int _gettemp(char *path, int slen)
- {
- - char *start, *trv, *suffp;
- + char *trv, *suffp;
- for (trv = path; *trv; ++trv)
- ;
- @@ -109,28 +112,51 @@ static int _gettemp(char *path, int slen)
- return -1;
- }
- + while (trv >= path && *trv == 'X')
- + --trv;
- +
- + char *const placeholderStart = trv + 1;
- + char *const placeholderEnd = suffp;
- +
- + return createFileFromTemplate(path, placeholderStart, placeholderEnd);
- +}
- +
- +/*!
- + \internal
- +
- + Generates a unique file path and returns a native handle to the open file.
- + \a path is used as a template when generating unique paths,
- + \a placeholderStart and \a placeholderEnd delimit the sub-string that will
- + be randomized.
- +
- + Returns an open handle to the newly created file if successful, an invalid
- + handle otherwise. In both cases, the string in \a path will be changed and
- + contain the generated path name.
- +*/
- +static int createFileFromTemplate(char *const path,
- + char *const placeholderStart, char *const placeholderEnd)
- +{
- + Q_ASSERT(placeholderEnd > placeholderStart);
- +
- // Initialize placeholder with random chars + PID.
- {
- + char *rIter = placeholderEnd;
- +
- #if defined(QT_BUILD_CORE_LIB)
- qint64 pid = QCoreApplication::applicationPid();
- - while (trv >= path && *trv == 'X' && pid != 0) {
- - *trv-- = (pid % 10) + '0';
- + do {
- + *--rIter = (pid % 10) + '0';
- pid /= 10;
- - }
- + } while (rIter != placeholderStart && pid != 0);
- #endif
- - while (trv >= path && *trv == 'X') {
- - char c;
- -
- - // CHANGE arc4random() -> random()
- - int pid = (qrand() & 0xffff) % (26+26);
- - if (pid < 26)
- - c = pid + 'A';
- + while (rIter != placeholderStart) {
- + char ch = char((qrand() & 0xffff) % (26 + 26));
- + if (ch < 26)
- + *--rIter = ch + 'A';
- else
- - c = (pid - 26) + 'a';
- - *trv-- = c;
- + *--rIter = ch - 26 + 'a';
- }
- - start = trv + 1;
- }
- for (;;) {
- @@ -149,24 +175,24 @@ static int _gettemp(char *path, int slen)
- #endif
- /* tricky little algorwwithm for backward compatibility */
- - for (trv = start;;) {
- + for (char *iter = placeholderStart;;) {
- // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
- // String progression: "ZZaiC" => "aabiC"
- - if (!*trv)
- + if (!*iter)
- return -1;
- - if (*trv == 'Z') {
- - if (trv == suffp)
- + if (*iter == 'Z') {
- + if (iter == placeholderEnd)
- return -1;
- - *trv++ = 'a';
- + *iter++ = 'a';
- } else {
- - if (isdigit(*trv))
- - *trv = 'a';
- - else if (*trv == 'z') /* inc from z to A */
- - *trv = 'A';
- + if (isdigit(*iter))
- + *iter = 'a';
- + else if (*iter == 'z') /* inc from z to A */
- + *iter = 'A';
- else {
- - if (trv == suffp)
- + if (iter == placeholderEnd)
- return -1;
- - ++*trv;
- + ++*iter;
- }
- break;
- }
- --
- 1.7.3.4
- From ac11acdf579d93517f1b3ded64ee20a13c9a7f73 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Tue, 29 Mar 2011 17:55:04 +0200
- Subject: [PATCH 11/14] Don't overrun XXXXXX placeholder when generating next filename
- Checking of boundary condition needs to happen whenever there is a
- change. Checking anywhere else is useless.
- This fixes an issue where we would overrun the placeholder if there was
- a 'Z' next to the placeholder string.
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 4 +---
- 1 files changed, 1 insertions(+), 3 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index f6e3426..4ff0ee3 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -181,17 +181,15 @@ static int createFileFromTemplate(char *const path,
- if (!*iter)
- return -1;
- if (*iter == 'Z') {
- + *iter++ = 'a';
- if (iter == placeholderEnd)
- return -1;
- - *iter++ = 'a';
- } else {
- if (isdigit(*iter))
- *iter = 'a';
- else if (*iter == 'z') /* inc from z to A */
- *iter = 'A';
- else {
- - if (iter == placeholderEnd)
- - return -1;
- ++*iter;
- }
- break;
- --
- 1.7.3.4
- From 791b819fa707fc758a36e82dacc317152b5dc1e9 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Wed, 30 Mar 2011 16:59:11 +0200
- Subject: [PATCH 12/14] Check for null no longer needed
- With proper checks for boundary conditions, we no longer need to protect
- against reaching the terminating null character.
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 2 --
- 1 files changed, 0 insertions(+), 2 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 4ff0ee3..1d9466d 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -178,8 +178,6 @@ static int createFileFromTemplate(char *const path,
- for (char *iter = placeholderStart;;) {
- // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
- // String progression: "ZZaiC" => "aabiC"
- - if (!*iter)
- - return -1;
- if (*iter == 'Z') {
- *iter++ = 'a';
- if (iter == placeholderEnd)
- --
- 1.7.3.4
- From 42f2817abf6496b65bde1ce8c09d629286dad853 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Wed, 30 Mar 2011 13:45:40 +0200
- Subject: [PATCH 13/14] Prefer use of QByteArray to qstrdup and manual memory management
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 15 ++++++---------
- 1 files changed, 6 insertions(+), 9 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 1d9466d..92065cb 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -278,10 +278,11 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- qfilename += QLatin1String(".XXXXXX");
- int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6);
- - char *filename = qstrdup(qfilename.toLocal8Bit());
- + QByteArray filename = qfilename.toLocal8Bit();
- + char *path = filename.data();
- #ifndef Q_OS_WIN
- - int fd = _gettemp(filename, suffixLength);
- + int fd = _gettemp(path, suffixLength);
- if (fd != -1) {
- // First open the fd as an external file descriptor to
- // initialize the engine properly.
- @@ -291,26 +292,22 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- d->closeFileHandle = true;
- // Restore the file names (open() resets them).
- - d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename)); //note that filename is NOT a native path
- + d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length())); //note that filename is NOT a native path
- filePathIsTemplate = false;
- - delete [] filename;
- return true;
- }
- QT_CLOSE(fd);
- }
- - delete [] filename;
- setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
- return false;
- #else
- - if (_gettemp(filename, suffixLength) == -1) {
- - delete [] filename;
- + if (_gettemp(path, suffixLength) == -1) {
- return false;
- }
- QString template_ = d->fileEntry.filePath();
- - d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename));
- - delete [] filename;
- + d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length()));
- if (QFSFileEngine::open(openMode)) {
- filePathIsTemplate = false;
- --
- 1.7.3.4
- From 318277c7aaa28f5d91e28a49e9e1b91ac44ccf8f Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
- Date: Wed, 30 Mar 2011 14:27:00 +0200
- Subject: [PATCH 14/14] QTemporaryFile: Locate placeholder before re-encoding
- Previously, the placeholder was identified in unicode-based QString, and
- the offset was assumed to be correct after conversion to the local 8-bit
- encoding. This assumption is obviously wrong for variable-sized
- encoding, such as utf-8.
- With this change, the placeholder is still identified in the original
- QString, but conversion to 8-bit encoding is done in a step-wise fashion
- and offsets recomputed. This allows us to drop the intermediary argument
- verification in _gettemp.
- Task-number: QTBUG-4796
- Reviewed-by: ?
- ---
- src/corelib/io/qtemporaryfile.cpp | 71 +++++++++++++++++++++----------------
- 1 files changed, 40 insertions(+), 31 deletions(-)
- diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
- index 92065cb..34c01a6 100644
- --- a/src/corelib/io/qtemporaryfile.cpp
- +++ b/src/corelib/io/qtemporaryfile.cpp
- @@ -95,31 +95,6 @@ QT_BEGIN_NAMESPACE
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- -static int createFileFromTemplate(char *const path,
- - char *const placeholderStart, char *const placeholderEnd);
- -
- -static int _gettemp(char *path, int slen)
- -{
- - char *trv, *suffp;
- -
- - for (trv = path; *trv; ++trv)
- - ;
- - trv -= slen;
- - suffp = trv;
- - --trv;
- - if (trv < path) {
- - errno = EINVAL;
- - return -1;
- - }
- -
- - while (trv >= path && *trv == 'X')
- - --trv;
- -
- - char *const placeholderStart = trv + 1;
- - char *const placeholderEnd = suffp;
- -
- - return createFileFromTemplate(path, placeholderStart, placeholderEnd);
- -}
- /*!
- \internal
- @@ -274,15 +249,49 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- return QFSFileEngine::open(openMode);
- QString qfilename = d->fileEntry.filePath();
- - if(!qfilename.contains(QLatin1String("XXXXXX")))
- - qfilename += QLatin1String(".XXXXXX");
- - int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6);
- - QByteArray filename = qfilename.toLocal8Bit();
- + // Find placeholder string.
- + size_t phPos = size_t(qfilename.length());
- + size_t phLength = 0;
- +
- + while (phPos != 0) {
- + --phPos;
- +
- + if (qfilename[phPos] == QLatin1Char('X')) {
- + ++phLength;
- + continue;
- + }
- +
- + if (qfilename[phPos] == QLatin1Char('/')
- + || phLength >= 6) {
- + ++phPos;
- + break;
- + }
- +
- + phLength = 0;
- + }
- +
- + QStringRef prefix, suffix;
- + if (phLength < 6) {
- + qfilename += QLatin1Char('.');
- + prefix = QStringRef(&qfilename);
- + phLength = 6;
- + } else {
- + prefix = qfilename.leftRef(phPos);
- + suffix = qfilename.midRef(phPos + phLength);
- + }
- +
- + QByteArray filename = prefix.toLocal8Bit();
- + phPos = filename.length();
- + if (suffix.isEmpty())
- + filename.resize(phPos + phLength);
- + else
- + filename.insert(phPos + phLength, suffix.toLocal8Bit());
- +
- char *path = filename.data();
- #ifndef Q_OS_WIN
- - int fd = _gettemp(path, suffixLength);
- + int fd = createFileFromTemplate(path, path + phPos, path + phPos + phLength);
- if (fd != -1) {
- // First open the fd as an external file descriptor to
- // initialize the engine properly.
- @@ -302,7 +311,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
- setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
- return false;
- #else
- - if (_gettemp(path, suffixLength) == -1) {
- + if (createFileFromTemplate(path, path + phPos, path + phPos + phLength) == -1) {
- return false;
- }
- --
- 1.7.3.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement