Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 36.89 KB | None | 0 0
  1. From 7e8b178278069309e9cc9ec686c7a90632c315f2 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  3. Date: Fri, 5 Aug 2011 10:30:32 +0200
  4. Subject: [PATCH 01/13] Modulus of negative dividends is undefined or negative
  5.  
  6. ... depending on who you ask. Since it is possible for applicationPid to
  7. return negative values this means we would introduce garbage ['()*+,-./]
  8. in the generated filenames.
  9.  
  10. Reviewed-by: Denis Dzyubenko
  11. ---
  12. src/corelib/io/qtemporaryfile.cpp |    2 +-
  13.  1 files changed, 1 insertions(+), 1 deletions(-)
  14.  
  15. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  16. index 0855d93..5bc07cb 100644
  17. --- a/src/corelib/io/qtemporaryfile.cpp
  18. +++ b/src/corelib/io/qtemporaryfile.cpp
  19. @@ -118,7 +118,7 @@ static int createFileFromTemplate(char *const path,
  20.          char *rIter = placeholderEnd;
  21.  
  22.  #if defined(QT_BUILD_CORE_LIB)
  23. -        qint64 pid = QCoreApplication::applicationPid();
  24. +        quint64 pid = quint64(QCoreApplication::applicationPid());
  25.          do {
  26.              *--rIter = (pid % 10) + '0';
  27.              pid /= 10;
  28. --
  29. 1.7.5.2
  30.  
  31.  
  32. From c0dbb2ae2bb7590301b760746335784c516fee38 Mon Sep 17 00:00:00 2001
  33. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  34. Date: Fri, 5 Aug 2011 10:32:08 +0200
  35. Subject: [PATCH 02/13] Changed if/if/else/if/eleven chain to switch
  36.  
  37. Inlined isdigit in switch statement. Removed unused #includes.
  38. Documented unreachable segment with code (Q_ASSERT).
  39.  
  40. Reviewed-by: Denis Dzyubenko
  41. ---
  42. src/corelib/io/qtemporaryfile.cpp |   37 ++++++++++++++++++++++---------------
  43.  1 files changed, 22 insertions(+), 15 deletions(-)
  44.  
  45. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  46. index 5bc07cb..9753332 100644
  47. --- a/src/corelib/io/qtemporaryfile.cpp
  48. +++ b/src/corelib/io/qtemporaryfile.cpp
  49. @@ -53,10 +53,6 @@
  50.  #  include <errno.h>
  51.  #endif
  52.  
  53. -#include <stdlib.h>
  54. -#include <time.h>
  55. -#include <ctype.h>
  56. -
  57.  #if defined(Q_OS_UNIX)
  58.  # include "private/qcore_unix_p.h"      // overrides QT_OPEN
  59.  #endif
  60. @@ -153,23 +149,34 @@ static int createFileFromTemplate(char *const path,
  61.          for (char *iter = placeholderStart;;) {
  62.              // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
  63.              // String progression: "ZZaiC" => "aabiC"
  64. -            if (*iter == 'Z') {
  65. -                *iter++ = 'a';
  66. -                if (iter == placeholderEnd)
  67. -                    return -1;
  68. -            } else {
  69. -                if (isdigit(*iter))
  70. +            switch (*iter) {
  71. +                case 'Z':
  72. +                    // Rollover, advance next character
  73.                      *iter = 'a';
  74. -                else if (*iter == 'z') /* inc from z to A */
  75. +                    if (++iter == placeholderEnd)
  76. +                        return -1;
  77. +
  78. +                    continue;
  79. +
  80. +                case '0': case '1': case '2': case '3': case '4':
  81. +                case '5': case '6': case '7': case '8': case '9':
  82. +                    *iter = 'a';
  83. +                    break;
  84. +
  85. +                case 'z':
  86. +                    // increment 'z' to 'A'
  87.                      *iter = 'A';
  88. -                else {
  89. +                    break;
  90. +
  91. +                default:
  92.                      ++*iter;
  93. -                }
  94. -                break;
  95. +                    break;
  96.              }
  97. +            break;
  98.          }
  99.      }
  100. -    /*NOTREACHED*/
  101. +
  102. +    Q_ASSERT(false);
  103.  }
  104.  
  105.  //************* QTemporaryFileEngine
  106. --
  107. 1.7.5.2
  108.  
  109.  
  110. From df4db419fabd1099c846116cc7cf2d04feafd157 Mon Sep 17 00:00:00 2001
  111. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  112. Date: Fri, 5 Aug 2011 10:32:25 +0200
  113. Subject: [PATCH 03/13] Don't convert template's path separators again
  114.  
  115. ---
  116. src/corelib/io/qtemporaryfile.cpp |    2 +-
  117.  1 files changed, 1 insertions(+), 1 deletions(-)
  118.  
  119. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  120. index 9753332..aae3eb6 100644
  121. --- a/src/corelib/io/qtemporaryfile.cpp
  122. +++ b/src/corelib/io/qtemporaryfile.cpp
  123. @@ -330,7 +330,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  124.          return true;
  125.      }
  126.  
  127. -    d->fileEntry = QFileSystemEntry(template_);
  128. +    d->fileEntry = QFileSystemEntry(template_, QFileSystemEntry::FromInternalPath());
  129.      return false;
  130.  #endif
  131.  }
  132. --
  133. 1.7.5.2
  134.  
  135.  
  136. From 763da9b1cbae094590fb8f66508e34c38378b633 Mon Sep 17 00:00:00 2001
  137. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  138. Date: Fri, 5 Aug 2011 10:32:51 +0200
  139. Subject: [PATCH 04/13] Use fromLocal8Bit for reversing toLocal8Bit
  140.  
  141. path is converted to 8-bit encoding using toLocal8Bit in
  142. QTemporaryFileEngine::open. The reverse operation should be used here.
  143. ---
  144. src/corelib/io/qtemporaryfile.cpp |    2 +-
  145.  1 files changed, 1 insertions(+), 1 deletions(-)
  146.  
  147. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  148. index aae3eb6..d457601 100644
  149. --- a/src/corelib/io/qtemporaryfile.cpp
  150. +++ b/src/corelib/io/qtemporaryfile.cpp
  151. @@ -141,7 +141,7 @@ static int createFileFromTemplate(char *const path,
  152.                  return -1;
  153.          }
  154.  #else
  155. -        if (!QFileInfo(QLatin1String(path)).exists())
  156. +        if (!QFileInfo(QString::fromLocal8Bit(path)).exists())
  157.              return 1;
  158.  #endif
  159.  
  160. --
  161. 1.7.5.2
  162.  
  163.  
  164. From 3958cfec41c775fc3ce3ef02ebba6f627fcbbe3e Mon Sep 17 00:00:00 2001
  165. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  166. Date: Fri, 5 Aug 2011 10:35:55 +0200
  167. Subject: [PATCH 05/13] Encapsulate pointer manipulations to
  168.  createFileTemplate function
  169.  
  170. , where we actually control how we use the pointers. Reduce some code
  171. duplication in #ifdefs.
  172.  
  173. Reviewed-by: ?
  174. ---
  175. src/corelib/io/qtemporaryfile.cpp |   33 ++++++++++++++++++---------------
  176.  1 files changed, 18 insertions(+), 15 deletions(-)
  177.  
  178. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  179. index d457601..9228f94 100644
  180. --- a/src/corelib/io/qtemporaryfile.cpp
  181. +++ b/src/corelib/io/qtemporaryfile.cpp
  182. @@ -96,18 +96,22 @@ QT_BEGIN_NAMESPACE
  183.      \internal
  184.  
  185.      Generates a unique file path and returns a native handle to the open file.
  186. -    \a path is used as a template when generating unique paths,
  187. -    \a placeholderStart and \a placeholderEnd delimit the sub-string that will
  188. -    be randomized.
  189. +    \a path is used as a template when generating unique paths, \a pos
  190. +    identifies the position of the first character that will be replaced in the
  191. +    template and \a length the number of characters that may be substituted.
  192.  
  193.      Returns an open handle to the newly created file if successful, an invalid
  194.      handle otherwise. In both cases, the string in \a path will be changed and
  195.      contain the generated path name.
  196.  */
  197. -static int createFileFromTemplate(char *const path,
  198. -        char *const placeholderStart, char *const placeholderEnd)
  199. +static int createFileFromTemplate(QByteArray &path, size_t pos, size_t length)
  200.  {
  201. -    Q_ASSERT(placeholderEnd > placeholderStart);
  202. +    Q_ASSERT(length != 0);
  203. +    Q_ASSERT(pos < size_t(path.length()));
  204. +    Q_ASSERT(length < size_t(path.length()) - pos);
  205. +
  206. +    char *const placeholderStart = path.data() + pos;
  207. +    char *const placeholderEnd = placeholderStart + length;
  208.  
  209.      // Initialize placeholder with random chars + PID.
  210.      {
  211. @@ -134,14 +138,16 @@ static int createFileFromTemplate(char *const path,
  212.          // Atomically create file and obtain handle
  213.  #ifndef Q_OS_WIN
  214.          {
  215. -            int fd = QT_OPEN(path, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600);
  216. +            int fd = QT_OPEN(path.constData(),
  217. +                    QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE,
  218. +                    0600);
  219.              if (fd != -1)
  220.                  return fd;
  221.              if (errno != EEXIST)
  222.                  return -1;
  223.          }
  224.  #else
  225. -        if (!QFileInfo(QString::fromLocal8Bit(path)).exists())
  226. +        if (!QFileInfo(QString::fromLocal8Bit(path.constData(), path.length())).exists())
  227.              return 1;
  228.  #endif
  229.  
  230. @@ -295,10 +301,9 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  231.      else
  232.          filename.insert(phPos + phLength, suffix.toLocal8Bit());
  233.  
  234. -    char *path = filename.data();
  235. +    int fd = createFileFromTemplate(filename, phPos, phLength);
  236.  
  237.  #ifndef Q_OS_WIN
  238. -    int fd = createFileFromTemplate(path, path + phPos, path + phPos + phLength);
  239.      if (fd != -1) {
  240.          // First open the fd as an external file descriptor to
  241.          // initialize the engine properly.
  242. @@ -308,7 +313,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  243.              d->closeFileHandle = true;
  244.  
  245.              // Restore the file names (open() resets them).
  246. -            d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length())); //note that filename is NOT a native path
  247. +            d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename.constData(), filename.length())); //note that filename is NOT a native path
  248.              filePathIsTemplate = false;
  249.              return true;
  250.          }
  251. @@ -318,13 +323,11 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  252.      setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
  253.      return false;
  254.  #else
  255. -    if (createFileFromTemplate(path, path + phPos, path + phPos + phLength) == -1) {
  256. +    if (fd == -1)
  257.          return false;
  258. -    }
  259.  
  260.      QString template_ = d->fileEntry.filePath();
  261. -    d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length()));
  262. -
  263. +    d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename.constData(), filename.length()));
  264.      if (QFSFileEngine::open(openMode)) {
  265.          filePathIsTemplate = false;
  266.          return true;
  267. --
  268. 1.7.5.2
  269.  
  270.  
  271. From 3be403715bca1edf2dbcc081e4990578ed1c1a0b Mon Sep 17 00:00:00 2001
  272. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  273. Date: Fri, 5 Aug 2011 10:57:19 +0200
  274. Subject: [PATCH 06/13] Use QStringBuilder when copying template for
  275.  modification
  276.  
  277. This avoids modifying the original string in the case where a
  278. placeholder marker is not found. By marking the variable const we
  279. further avoid checks on the reference count and detaches, also allowing
  280. us to safely reuse it later in the function.
  281.  
  282. The new approach also fixes an issue where suffix wasn't empty, but the
  283. toLocal8Bit conversion would be. This resulted in a buffer overflow
  284. inside createFileFromTemplate.
  285.  
  286. Reviewed-by: ?
  287. ---
  288. src/corelib/io/qtemporaryfile.cpp |   62 ++++++++++++++++++++++++++++---------
  289.  1 files changed, 47 insertions(+), 15 deletions(-)
  290.  
  291. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  292. index 9228f94..1d3f7ca 100644
  293. --- a/src/corelib/io/qtemporaryfile.cpp
  294. +++ b/src/corelib/io/qtemporaryfile.cpp
  295. @@ -45,6 +45,7 @@
  296.  
  297.  #include "qplatformdefs.h"
  298.  #include "qabstractfileengine.h"
  299. +#include "qstringbuilder.h"
  300.  #include "private/qfile_p.h"
  301.  #include "private/qabstractfileengine_p.h"
  302.  #include "private/qfsfileengine_p.h"
  303. @@ -63,6 +64,38 @@
  304.  
  305.  QT_BEGIN_NAMESPACE
  306.  
  307. +struct Placeholder
  308. +{
  309. +    Placeholder(int size)
  310. +        : size_(size)
  311. +    {
  312. +    }
  313. +
  314. +    int size() const
  315. +    {
  316. +        return size_;
  317. +    }
  318. +
  319. +private:
  320. +    int size_;
  321. +};
  322. +
  323. +template <>
  324. +struct QConcatenable<Placeholder>
  325. +{
  326. +    typedef Placeholder type;
  327. +    typedef QByteArray ConvertTo;
  328. +    enum { ExactSize = true };
  329. +    static int size(const Placeholder &p) { return p.size(); }
  330. +
  331. +    template <class CharT>
  332. +    static inline void appendTo(const Placeholder &p, CharT *&out)
  333. +    {
  334. +        // Uninitialized
  335. +        out += p.size();
  336. +    }
  337. +};
  338. +
  339.  /*
  340.   * Copyright (c) 1987, 1993
  341.   * The Regents of the University of California.  All rights reserved.
  342. @@ -261,7 +294,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  343.      if (!filePathIsTemplate)
  344.          return QFSFileEngine::open(openMode);
  345.  
  346. -    QString qfilename = d->fileEntry.filePath();
  347. +    const QString qfilename = d->fileEntry.filePath();
  348.  
  349.      // Find placeholder string.
  350.      uint phPos = qfilename.length();
  351. @@ -284,22 +317,22 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  352.          phLength = 0;
  353.      }
  354.  
  355. -    QStringRef prefix, suffix;
  356. +    QByteArray filename;
  357. +
  358.      if (phLength < 6) {
  359. -        qfilename += QLatin1Char('.');
  360. -        prefix = QStringRef(&qfilename);
  361. +        filename = qfilename.toLocal8Bit();
  362. +
  363. +        phPos = filename.length() + 1; // Account for added dot in prefix
  364.          phLength = 6;
  365. +        filename = filename % '.' % Placeholder(phLength);
  366.      } else {
  367. -        prefix = qfilename.leftRef(phPos);
  368. -        suffix = qfilename.midRef(phPos + phLength);
  369. -    }
  370. +        QByteArray prefix, suffix;
  371. +        prefix = qfilename.leftRef(phPos).toLocal8Bit();
  372. +        suffix = qfilename.midRef(phPos + phLength).toLocal8Bit();
  373.  
  374. -    QByteArray filename = prefix.toLocal8Bit();
  375. -    phPos = filename.length();
  376. -    if (suffix.isEmpty())
  377. -        filename.resize(phPos + phLength);
  378. -    else
  379. -        filename.insert(phPos + phLength, suffix.toLocal8Bit());
  380. +        phPos = prefix.length();
  381. +        filename = prefix % Placeholder(phLength) % suffix;
  382. +    }
  383.  
  384.      int fd = createFileFromTemplate(filename, phPos, phLength);
  385.  
  386. @@ -326,14 +359,13 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  387.      if (fd == -1)
  388.          return false;
  389.  
  390. -    QString template_ = d->fileEntry.filePath();
  391.      d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename.constData(), filename.length()));
  392.      if (QFSFileEngine::open(openMode)) {
  393.          filePathIsTemplate = false;
  394.          return true;
  395.      }
  396.  
  397. -    d->fileEntry = QFileSystemEntry(template_, QFileSystemEntry::FromInternalPath());
  398. +    d->fileEntry = QFileSystemEntry(qfilename, QFileSystemEntry::FromInternalPath());
  399.      return false;
  400.  #endif
  401.  }
  402. --
  403. 1.7.5.2
  404.  
  405.  
  406. From 9553b9b1e8fbadd9981835a7ac0f5f73d394ea64 Mon Sep 17 00:00:00 2001
  407. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  408. Date: Fri, 5 Aug 2011 10:39:53 +0200
  409. Subject: [PATCH 07/13] Make Symbian follow Windows code in temporary path
  410.  generation
  411.  
  412. On the one hand, we stop using OpenC here. On the other, we no longer
  413. use an atomic create and obtain file handle API -- just as we don't on
  414. Windows yet.
  415.  
  416. This is a stepping stone to removing back and forth conversions of path
  417. names when generating unique names and also towards the use of native
  418. APIs for creating and obtaining a file handle atomically.
  419.  
  420. Reviewed-by: ?
  421. ---
  422. src/corelib/io/qtemporaryfile.cpp |   13 +++++--------
  423.  1 files changed, 5 insertions(+), 8 deletions(-)
  424.  
  425. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  426. index 1d3f7ca..b079d3e 100644
  427. --- a/src/corelib/io/qtemporaryfile.cpp
  428. +++ b/src/corelib/io/qtemporaryfile.cpp
  429. @@ -50,12 +50,9 @@
  430.  #include "private/qabstractfileengine_p.h"
  431.  #include "private/qfsfileengine_p.h"
  432.  
  433. -#if !defined(Q_OS_WINCE)
  434. -#  include <errno.h>
  435. -#endif
  436. -
  437. -#if defined(Q_OS_UNIX)
  438. -# include "private/qcore_unix_p.h"      // overrides QT_OPEN
  439. +#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  440. +#include "private/qcore_unix_p.h"       // overrides QT_OPEN
  441. +#include <errno.h>
  442.  #endif
  443.  
  444.  #if defined(QT_BUILD_CORE_LIB)
  445. @@ -169,7 +166,7 @@ static int createFileFromTemplate(QByteArray &path, size_t pos, size_t length)
  446.  
  447.      for (;;) {
  448.          // Atomically create file and obtain handle
  449. -#ifndef Q_OS_WIN
  450. +#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  451.          {
  452.              int fd = QT_OPEN(path.constData(),
  453.                      QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE,
  454. @@ -336,7 +333,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  455.  
  456.      int fd = createFileFromTemplate(filename, phPos, phLength);
  457.  
  458. -#ifndef Q_OS_WIN
  459. +#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  460.      if (fd != -1) {
  461.          // First open the fd as an external file descriptor to
  462.          // initialize the engine properly.
  463. --
  464. 1.7.5.2
  465.  
  466.  
  467. From 9b68b786487988ccd861a5abe1b2b50a4e0a5880 Mon Sep 17 00:00:00 2001
  468. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  469. Date: Fri, 5 Aug 2011 10:40:46 +0200
  470. Subject: [PATCH 08/13] Avoid spurious detaching in
  471.  QDir::to/fromNativeSeparators
  472.  
  473. The new code avoids non-const detaching operations until needed and uses
  474. a pointer into the "raw" QChar data from then on, thus skipping unneeded
  475. checks on the reference count for further detaching.
  476.  
  477. These functions are used all the time by the file system classes so this
  478. small optimization won't hurt. In particular, it will help users who
  479. already use '/' when passing paths into Qt.
  480.  
  481. Reviewed-by: Peter Hartmann
  482. ---
  483. src/corelib/io/qdir.cpp |   38 ++++++++++++++++++++++++++++----------
  484.  1 files changed, 28 insertions(+), 10 deletions(-)
  485.  
  486. diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
  487. index b31cf69..f9196e0 100644
  488. --- a/src/corelib/io/qdir.cpp
  489. +++ b/src/corelib/io/qdir.cpp
  490. @@ -802,14 +802,23 @@ QString QDir::convertSeparators(const QString &pathName)
  491.  */
  492.  QString QDir::toNativeSeparators(const QString &pathName)
  493.  {
  494. -    QString n(pathName);
  495.  #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
  496. -    for (int i = 0; i < (int)n.length(); ++i) {
  497. -        if (n[i] == QLatin1Char('/'))
  498. -            n[i] = QLatin1Char('\\');
  499. +    int i = pathName.indexOf(QLatin1Char('/'));
  500. +    if (i != -1) {
  501. +        QString n(pathName);
  502. +
  503. +        QChar * const data = n.data();
  504. +        data[i++] = QLatin1Char('\\');
  505. +
  506. +        for (; i < n.length(); ++i) {
  507. +            if (data[i] == QLatin1Char('/'))
  508. +                data[i] = QLatin1Char('\\');
  509. +        }
  510. +
  511. +        return n;
  512.      }
  513.  #endif
  514. -    return n;
  515. +    return pathName;
  516.  }
  517.  
  518.  /*!
  519. @@ -826,14 +835,23 @@ QString QDir::toNativeSeparators(const QString &pathName)
  520.  */
  521.  QString QDir::fromNativeSeparators(const QString &pathName)
  522.  {
  523. -    QString n(pathName);
  524.  #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
  525. -    for (int i = 0; i < (int)n.length(); ++i) {
  526. -        if (n[i] == QLatin1Char('\\'))
  527. -            n[i] = QLatin1Char('/');
  528. +    int i = pathName.indexOf(QLatin1Char('\\'));
  529. +    if (i != -1) {
  530. +        QString n(pathName);
  531. +
  532. +        QChar * const data = n.data();
  533. +        data[i++] = QLatin1Char('/');
  534. +
  535. +        for (; i < n.length(); ++i) {
  536. +            if (data[i] == QLatin1Char('\\'))
  537. +                data[i] = QLatin1Char('/');
  538. +        }
  539. +
  540. +        return n;
  541.      }
  542.  #endif
  543. -    return n;
  544. +    return pathName;
  545.  }
  546.  
  547.  /*!
  548. --
  549. 1.7.5.2
  550.  
  551.  
  552. From d1f2e21a1b25f635f4aee22d731825dcbd8024b5 Mon Sep 17 00:00:00 2001
  553. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  554. Date: Fri, 5 Aug 2011 10:58:08 +0200
  555. Subject: [PATCH 09/13] Minimize encoding conversions when generating unique
  556.  file name
  557.  
  558. With minor adjustments, createFileFromTemplate is made to work directly
  559. on (UTF-16) QString data, which is already in the native encoding for
  560. Windows and Symbian. This is possible because the function only fills
  561. out the placeholder sub-string, without touching adjacent characters.
  562.  
  563. This eliminates unnecessary conversions on those platforms.
  564.  
  565. Reviewed-by: ?
  566. ---
  567. src/corelib/io/qtemporaryfile.cpp |   50 +++++++++++++++++++++++++-----------
  568.  1 files changed, 35 insertions(+), 15 deletions(-)
  569.  
  570. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  571. index b079d3e..292ad50 100644
  572. --- a/src/corelib/io/qtemporaryfile.cpp
  573. +++ b/src/corelib/io/qtemporaryfile.cpp
  574. @@ -61,6 +61,14 @@
  575.  
  576.  QT_BEGIN_NAMESPACE
  577.  
  578. +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
  579. +typedef ushort Char;
  580. +typedef QLatin1Char Latin1Char;
  581. +#else // POSIX
  582. +typedef char Char;
  583. +typedef char Latin1Char;
  584. +#endif
  585. +
  586.  struct Placeholder
  587.  {
  588.      Placeholder(int size)
  589. @@ -134,23 +142,24 @@ struct QConcatenable<Placeholder>
  590.      handle otherwise. In both cases, the string in \a path will be changed and
  591.      contain the generated path name.
  592.  */
  593. -static int createFileFromTemplate(QByteArray &path, size_t pos, size_t length)
  594. +static int createFileFromTemplate(QFileSystemEntry::NativePath &path,
  595. +        size_t pos, size_t length)
  596.  {
  597.      Q_ASSERT(length != 0);
  598.      Q_ASSERT(pos < size_t(path.length()));
  599.      Q_ASSERT(length < size_t(path.length()) - pos);
  600.  
  601. -    char *const placeholderStart = path.data() + pos;
  602. -    char *const placeholderEnd = placeholderStart + length;
  603. +    Char *const placeholderStart = (Char *)path.data() + pos;
  604. +    Char *const placeholderEnd = placeholderStart + length;
  605.  
  606.      // Initialize placeholder with random chars + PID.
  607.      {
  608. -        char *rIter = placeholderEnd;
  609. +        Char *rIter = placeholderEnd;
  610.  
  611.  #if defined(QT_BUILD_CORE_LIB)
  612.          quint64 pid = quint64(QCoreApplication::applicationPid());
  613.          do {
  614. -            *--rIter = (pid % 10) + '0';
  615. +            *--rIter = Latin1Char((pid % 10) + '0');
  616.              pid /= 10;
  617.          } while (rIter != placeholderStart && pid != 0);
  618.  #endif
  619. @@ -158,9 +167,9 @@ static int createFileFromTemplate(QByteArray &path, size_t pos, size_t length)
  620.          while (rIter != placeholderStart) {
  621.              char ch = char((qrand() & 0xffff) % (26 + 26));
  622.              if (ch < 26)
  623. -                *--rIter = ch + 'A';
  624. +                *--rIter = Latin1Char(ch + 'A');
  625.              else
  626. -                *--rIter = ch - 26 + 'a';
  627. +                *--rIter = Latin1Char(ch - 26 + 'a');
  628.          }
  629.      }
  630.  
  631. @@ -177,18 +186,18 @@ static int createFileFromTemplate(QByteArray &path, size_t pos, size_t length)
  632.                  return -1;
  633.          }
  634.  #else
  635. -        if (!QFileInfo(QString::fromLocal8Bit(path.constData(), path.length())).exists())
  636. +        if (!QFileInfo(path).exists())
  637.              return 1;
  638.  #endif
  639.  
  640.          /* tricky little algorwwithm for backward compatibility */
  641. -        for (char *iter = placeholderStart;;) {
  642. +        for (Char *iter = placeholderStart;;) {
  643.              // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
  644.              // String progression: "ZZaiC" => "aabiC"
  645. -            switch (*iter) {
  646. +            switch (char(*iter)) {
  647.                  case 'Z':
  648.                      // Rollover, advance next character
  649. -                    *iter = 'a';
  650. +                    *iter = Latin1Char('a');
  651.                      if (++iter == placeholderEnd)
  652.                          return -1;
  653.  
  654. @@ -196,12 +205,12 @@ static int createFileFromTemplate(QByteArray &path, size_t pos, size_t length)
  655.  
  656.                  case '0': case '1': case '2': case '3': case '4':
  657.                  case '5': case '6': case '7': case '8': case '9':
  658. -                    *iter = 'a';
  659. +                    *iter = Latin1Char('a');
  660.                      break;
  661.  
  662.                  case 'z':
  663.                      // increment 'z' to 'A'
  664. -                    *iter = 'A';
  665. +                    *iter = Latin1Char('A');
  666.                      break;
  667.  
  668.                  default:
  669. @@ -314,8 +323,9 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  670.          phLength = 0;
  671.      }
  672.  
  673. -    QByteArray filename;
  674. +    QFileSystemEntry::NativePath filename;
  675.  
  676. +#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  677.      if (phLength < 6) {
  678.          filename = qfilename.toLocal8Bit();
  679.  
  680. @@ -330,6 +340,16 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  681.          phPos = prefix.length();
  682.          filename = prefix % Placeholder(phLength) % suffix;
  683.      }
  684. +#else
  685. +    if (phLength < 6) {
  686. +        phPos = qfilename.length() + 1; // Account for added dot in prefix
  687. +        phLength = 6;
  688. +        filename = qfilename % '.' % Placeholder(phLength);
  689. +    } else
  690. +        filename = qfilename;
  691. +
  692. +    // No native separators, not a "native path"
  693. +#endif
  694.  
  695.      int fd = createFileFromTemplate(filename, phPos, phLength);
  696.  
  697. @@ -356,7 +376,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  698.      if (fd == -1)
  699.          return false;
  700.  
  701. -    d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename.constData(), filename.length()));
  702. +    d->fileEntry = QFileSystemEntry(filename, QFileSystemEntry::FromInternalPath());
  703.      if (QFSFileEngine::open(openMode)) {
  704.          filePathIsTemplate = false;
  705.          return true;
  706. --
  707. 1.7.5.2
  708.  
  709.  
  710. From 1794f7252c270504df9eda3d041d37f3f1382a86 Mon Sep 17 00:00:00 2001
  711. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  712. Date: Fri, 5 Aug 2011 10:45:08 +0200
  713. Subject: [PATCH 10/13] Use native paths on Windows and Symbian
  714.  
  715. On these platforms, we know the native encoding for file names and can
  716. make conversions ahead of time.
  717.  
  718. Reviewed-by: ?
  719. ---
  720. src/corelib/io/qtemporaryfile.cpp |   21 ++++++++++++++++-----
  721.  1 files changed, 16 insertions(+), 5 deletions(-)
  722.  
  723. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  724. index 292ad50..6157a22 100644
  725. --- a/src/corelib/io/qtemporaryfile.cpp
  726. +++ b/src/corelib/io/qtemporaryfile.cpp
  727. @@ -300,7 +300,14 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  728.      if (!filePathIsTemplate)
  729.          return QFSFileEngine::open(openMode);
  730.  
  731. -    const QString qfilename = d->fileEntry.filePath();
  732. +    const QString qfilename =
  733. +#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  734. +        // Since the native encoding is out of our control, we need to process
  735. +        // the path as UTF-16 before doing any conversions
  736. +        d->fileEntry.filePath();
  737. +#else
  738. +        d->fileEntry.nativeFilePath();
  739. +#endif
  740.  
  741.      // Find placeholder string.
  742.      uint phPos = qfilename.length();
  743. @@ -314,8 +321,14 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  744.              continue;
  745.          }
  746.  
  747. -        if (qfilename[phPos] == QLatin1Char('/')
  748. -                || phLength >= 6) {
  749. +        if (phLength >= 6
  750. +                || qfilename[phPos] ==
  751. +#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  752. +                    QLatin1Char('/')
  753. +#else
  754. +                    QLatin1Char('\\')
  755. +#endif
  756. +                ) {
  757.              ++phPos;
  758.              break;
  759.          }
  760. @@ -347,8 +360,6 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  761.          filename = qfilename % '.' % Placeholder(phLength);
  762.      } else
  763.          filename = qfilename;
  764. -
  765. -    // No native separators, not a "native path"
  766.  #endif
  767.  
  768.      int fd = createFileFromTemplate(filename, phPos, phLength);
  769. --
  770. 1.7.5.2
  771.  
  772.  
  773. From 870690cad1598de8c6029acc820ef203707d5811 Mon Sep 17 00:00:00 2001
  774. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  775. Date: Fri, 5 Aug 2011 10:47:01 +0200
  776. Subject: [PATCH 11/13] Cleanup #includes
  777.  
  778. These are already required and included by qfsfileengine_p.h.
  779. ---
  780. src/corelib/io/qtemporaryfile.cpp |    2 --
  781.  1 files changed, 0 insertions(+), 2 deletions(-)
  782.  
  783. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  784. index 6157a22..828f4e5 100644
  785. --- a/src/corelib/io/qtemporaryfile.cpp
  786. +++ b/src/corelib/io/qtemporaryfile.cpp
  787. @@ -44,10 +44,8 @@
  788.  #ifndef QT_NO_TEMPORARYFILE
  789.  
  790.  #include "qplatformdefs.h"
  791. -#include "qabstractfileengine.h"
  792.  #include "qstringbuilder.h"
  793.  #include "private/qfile_p.h"
  794. -#include "private/qabstractfileengine_p.h"
  795.  #include "private/qfsfileengine_p.h"
  796.  
  797.  #if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  798. --
  799. 1.7.5.2
  800.  
  801.  
  802. From 39bdf994fc7773aab601d6906f4487bba9b4d6d8 Mon Sep 17 00:00:00 2001
  803. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  804. Date: Fri, 5 Aug 2011 11:00:51 +0200
  805. Subject: [PATCH 12/13] Atomic implementation of create file and obtain handle
  806.  for Win/Symbian
  807.  
  808. createFileFromTemplate now not only generates a unique name, but also
  809. acquires a file handle on all platforms. The function directly modifies
  810. the file engine's native handle, returns true on success.
  811.  
  812. Errors, other than "file exists" are propagated up with resulting
  813. failure in opening the temporary file.
  814.  
  815. Fixes a long standing security issue on Windows.
  816.  
  817. This change otherwise unifies error handling and should give consistent
  818. behaviour across all platforms.
  819.  
  820. Reviewed-by: ?
  821. ---
  822. src/corelib/io/qtemporaryfile.cpp |  131 ++++++++++++++++++++++++-------------
  823.  1 files changed, 86 insertions(+), 45 deletions(-)
  824.  
  825. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  826. index 828f4e5..687166c 100644
  827. --- a/src/corelib/io/qtemporaryfile.cpp
  828. +++ b/src/corelib/io/qtemporaryfile.cpp
  829. @@ -47,6 +47,11 @@
  830.  #include "qstringbuilder.h"
  831.  #include "private/qfile_p.h"
  832.  #include "private/qfsfileengine_p.h"
  833. +#include "private/qsystemerror_p.h"
  834. +
  835. +#if defined(Q_OS_SYMBIAN)
  836. +#include "private/qcore_symbian_p.h"
  837. +#endif
  838.  
  839.  #if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  840.  #include "private/qcore_unix_p.h"       // overrides QT_OPEN
  841. @@ -59,12 +64,22 @@
  842.  
  843.  QT_BEGIN_NAMESPACE
  844.  
  845. -#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
  846. +#ifdef Q_OS_WIN
  847.  typedef ushort Char;
  848.  typedef QLatin1Char Latin1Char;
  849. +typedef HANDLE NativeFileHandle;
  850. +#elif defined(Q_OS_SYMBIAN)
  851. +typedef ushort Char;
  852. +typedef QLatin1Char Latin1Char;
  853. +#ifdef  SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  854. +typedef RFile64 NativeFileHandle;
  855. +#else
  856. +typedef RFile NativeFileHandle;
  857. +#endif
  858.  #else // POSIX
  859.  typedef char Char;
  860.  typedef char Latin1Char;
  861. +typedef int NativeFileHandle;
  862.  #endif
  863.  
  864.  struct Placeholder
  865. @@ -140,8 +155,9 @@ struct QConcatenable<Placeholder>
  866.      handle otherwise. In both cases, the string in \a path will be changed and
  867.      contain the generated path name.
  868.  */
  869. -static int createFileFromTemplate(QFileSystemEntry::NativePath &path,
  870. -        size_t pos, size_t length)
  871. +static bool createFileFromTemplate(NativeFileHandle &file,
  872. +        QFileSystemEntry::NativePath &path, size_t pos, size_t length,
  873. +        QSystemError &error)
  874.  {
  875.      Q_ASSERT(length != 0);
  876.      Q_ASSERT(pos < size_t(path.length()));
  877. @@ -171,21 +187,50 @@ static int createFileFromTemplate(QFileSystemEntry::NativePath &path,
  878.          }
  879.      }
  880.  
  881. +#ifdef Q_OS_SYMBIAN
  882. +    RFs& fs = qt_s60GetRFs();
  883. +#endif
  884. +
  885.      for (;;) {
  886.          // Atomically create file and obtain handle
  887. -#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  888. -        {
  889. -            int fd = QT_OPEN(path.constData(),
  890. -                    QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE,
  891. -                    0600);
  892. -            if (fd != -1)
  893. -                return fd;
  894. -            if (errno != EEXIST)
  895. -                return -1;
  896. +#if defined(Q_OS_WIN)
  897. +        file = CreateFile((const wchar_t *)path.constData(),
  898. +                GENERIC_READ | GENERIC_WRITE,
  899. +                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW,
  900. +                FILE_ATTRIBUTE_NORMAL, NULL);
  901. +
  902. +        if (file != INVALID_HANDLE_VALUE)
  903. +            return true;
  904. +
  905. +        DWORD err = GetLastError();
  906. +        if (err != ERROR_FILE_EXISTS) {
  907. +            error = QSystemError(err, QSystemError::NativeError);
  908. +            return false;
  909. +        }
  910. +#elif defined(Q_OS_SYMBIAN)
  911. +        TInt err = file.Create(fs, qt_QString2TPtrC(path),
  912. +                EFileRead | EFileWrite);
  913. +
  914. +        if (err == KErrNone)
  915. +            return true;
  916. +
  917. +        if (err != KErrAlreadyExists) {
  918. +            error = QSystemError(err, QSystemError::NativeError);
  919. +            return false;
  920. +        }
  921. +#else // POSIX
  922. +        file = QT_OPEN(path.constData(),
  923. +                QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE,
  924. +                0600);
  925. +
  926. +        if (file != -1)
  927. +            return true;
  928. +
  929. +        int err = errno;
  930. +        if (err != EEXIST) {
  931. +            error = QSystemError(err, QSystemError::NativeError);
  932. +            return false;
  933.          }
  934. -#else
  935. -        if (!QFileInfo(path).exists())
  936. -            return 1;
  937.  #endif
  938.  
  939.          /* tricky little algorwwithm for backward compatibility */
  940. @@ -196,8 +241,11 @@ static int createFileFromTemplate(QFileSystemEntry::NativePath &path,
  941.                  case 'Z':
  942.                      // Rollover, advance next character
  943.                      *iter = Latin1Char('a');
  944. -                    if (++iter == placeholderEnd)
  945. -                        return -1;
  946. +                    if (++iter == placeholderEnd) {
  947. +                        // Out of alternatives. Return file exists error, previously set.
  948. +                        error = QSystemError(err, QSystemError::NativeError);
  949. +                        return false;
  950. +                    }
  951.  
  952.                      continue;
  953.  
  954. @@ -360,40 +408,33 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  955.          filename = qfilename;
  956.  #endif
  957.  
  958. -    int fd = createFileFromTemplate(filename, phPos, phLength);
  959. +    QSystemError error;
  960. +#if defined(Q_OS_WIN)
  961. +    NativeFileHandle &file = d->fileHandle;
  962. +#elif defined(Q_OS_SYMBIAN)
  963. +    NativeFileHandle &file = d->symbianFile;
  964. +#else // POSIX
  965. +    NativeFileHandle &file = d->fd;
  966. +#endif
  967.  
  968. -#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  969. -    if (fd != -1) {
  970. -        // First open the fd as an external file descriptor to
  971. -        // initialize the engine properly.
  972. -        if (QFSFileEngine::open(openMode, fd)) {
  973. +    if (!createFileFromTemplate(file, filename, phPos, phLength, error)) {
  974. +        setError(QFile::OpenError, error.toString());
  975. +        return false;
  976. +    }
  977.  
  978. -            // Allow the engine to close the handle even if it's "external".
  979. -            d->closeFileHandle = true;
  980. +    d->fileEntry = QFileSystemEntry(filename, QFileSystemEntry::FromNativePath());
  981.  
  982. -            // Restore the file names (open() resets them).
  983. -            d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename.constData(), filename.length())); //note that filename is NOT a native path
  984. -            filePathIsTemplate = false;
  985. -            return true;
  986. -        }
  987. +#if !defined(Q_OS_WIN)
  988. +    d->closeFileHandle = true;
  989. +#endif
  990.  
  991. -        QT_CLOSE(fd);
  992. -    }
  993. -    setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
  994. -    return false;
  995. -#else
  996. -    if (fd == -1)
  997. -        return false;
  998. +    filePathIsTemplate = false;
  999.  
  1000. -    d->fileEntry = QFileSystemEntry(filename, QFileSystemEntry::FromInternalPath());
  1001. -    if (QFSFileEngine::open(openMode)) {
  1002. -        filePathIsTemplate = false;
  1003. -        return true;
  1004. -    }
  1005. +    d->openMode = openMode;
  1006. +    d->lastFlushFailed = false;
  1007. +    d->tried_stat = 0;
  1008.  
  1009. -    d->fileEntry = QFileSystemEntry(qfilename, QFileSystemEntry::FromInternalPath());
  1010. -    return false;
  1011. -#endif
  1012. +    return true;
  1013.  }
  1014.  
  1015.  bool QTemporaryFileEngine::remove()
  1016. --
  1017. 1.7.5.2
  1018.  
  1019.  
  1020. From 9868ecd4ebdea88058201a51308fe61f1a4d8b31 Mon Sep 17 00:00:00 2001
  1021. From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= <joao.abecasis@nokia.com>
  1022. Date: Fri, 5 Aug 2011 10:49:44 +0200
  1023. Subject: [PATCH 13/13] Use "native paths" on POSIX platforms as well
  1024.  
  1025. And don't rely solely on "local8Bit" conversions.
  1026.  
  1027. QFile defines an API for overriding how encoding conversions are done
  1028. for filenames. In generating unique names, QTemporaryFile ignored that
  1029. API and hardcoded the use of local 8-bit, implicitly assuming that that
  1030. was appropriate.
  1031.  
  1032. With this change, we switch that assumption to one where user supplied
  1033. encoding function keeps the byte value of 'X' and '/', also assuming
  1034. that encoded 'X' takes up a single-byte (i.e., the byte sequence for
  1035. "XXXXXX" remains unchanged).
  1036.  
  1037. There was also, and there still is an assumption in name generation that
  1038. byte values for ASCII alpha-numeric characters are valid in the "native"
  1039. encoding.
  1040.  
  1041. In practice this change is compatible with UTF-8, Latin-1 and other
  1042. ISO/IEC 8859 encodings. At any rate, it's very likely that only UTF-8 is
  1043. relevant here.
  1044.  
  1045. Reviewed-by: ?
  1046. ---
  1047. src/corelib/io/qtemporaryfile.cpp |   30 +++---------------------------
  1048.  1 files changed, 3 insertions(+), 27 deletions(-)
  1049.  
  1050. diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
  1051. index 687166c..e565ba5 100644
  1052. --- a/src/corelib/io/qtemporaryfile.cpp
  1053. +++ b/src/corelib/io/qtemporaryfile.cpp
  1054. @@ -346,14 +346,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  1055.      if (!filePathIsTemplate)
  1056.          return QFSFileEngine::open(openMode);
  1057.  
  1058. -    const QString qfilename =
  1059. -#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  1060. -        // Since the native encoding is out of our control, we need to process
  1061. -        // the path as UTF-16 before doing any conversions
  1062. -        d->fileEntry.filePath();
  1063. -#else
  1064. -        d->fileEntry.nativeFilePath();
  1065. -#endif
  1066. +    const QFileSystemEntry::NativePath qfilename = d->fileEntry.nativeFilePath();
  1067.  
  1068.      // Find placeholder string.
  1069.      uint phPos = qfilename.length();
  1070. @@ -362,7 +355,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  1071.      while (phPos != 0) {
  1072.          --phPos;
  1073.  
  1074. -        if (qfilename[phPos] == QLatin1Char('X')) {
  1075. +        if (qfilename[phPos] == Latin1Char('X')) {
  1076.              ++phLength;
  1077.              continue;
  1078.          }
  1079. @@ -370,7 +363,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  1080.          if (phLength >= 6
  1081.                  || qfilename[phPos] ==
  1082.  #if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  1083. -                    QLatin1Char('/')
  1084. +                    '/'
  1085.  #else
  1086.                      QLatin1Char('\\')
  1087.  #endif
  1088. @@ -384,29 +377,12 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
  1089.  
  1090.      QFileSystemEntry::NativePath filename;
  1091.  
  1092. -#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
  1093. -    if (phLength < 6) {
  1094. -        filename = qfilename.toLocal8Bit();
  1095. -
  1096. -        phPos = filename.length() + 1; // Account for added dot in prefix
  1097. -        phLength = 6;
  1098. -        filename = filename % '.' % Placeholder(phLength);
  1099. -    } else {
  1100. -        QByteArray prefix, suffix;
  1101. -        prefix = qfilename.leftRef(phPos).toLocal8Bit();
  1102. -        suffix = qfilename.midRef(phPos + phLength).toLocal8Bit();
  1103. -
  1104. -        phPos = prefix.length();
  1105. -        filename = prefix % Placeholder(phLength) % suffix;
  1106. -    }
  1107. -#else
  1108.      if (phLength < 6) {
  1109.          phPos = qfilename.length() + 1; // Account for added dot in prefix
  1110.          phLength = 6;
  1111.          filename = qfilename % '.' % Placeholder(phLength);
  1112.      } else
  1113.          filename = qfilename;
  1114. -#endif
  1115.  
  1116.      QSystemError error;
  1117.  #if defined(Q_OS_WIN)
  1118. --
  1119. 1.7.5.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement