summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qdatastream.h7
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp6
-rw-r--r--src/corelib/io/qtemporarydir.cpp52
3 files changed, 38 insertions, 27 deletions
diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h
index 5956f9ac40..ac58677b77 100644
--- a/src/corelib/io/qdatastream.h
+++ b/src/corelib/io/qdatastream.h
@@ -63,6 +63,9 @@ template <class Key, class T> class QMap;
#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED)
class QDataStreamPrivate;
+namespace QtPrivate {
+class StreamStateSaver;
+}
class Q_CORE_EXPORT QDataStream
{
public:
@@ -193,6 +196,7 @@ private:
Status q_status;
int readBlock(char *data, int len);
+ friend class QtPrivate::StreamStateSaver;
};
namespace QtPrivate {
@@ -202,7 +206,8 @@ class StreamStateSaver
public:
inline StreamStateSaver(QDataStream *s) : stream(s), oldStatus(s->status())
{
- stream->resetStatus();
+ if (!stream->dev || !stream->dev->isTransactionStarted())
+ stream->resetStatus();
}
inline ~StreamStateSaver()
{
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 70c347978e..5c79a745fa 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -378,15 +378,13 @@ qint64 QFSFileEnginePrivate::nativeWrite(const char *data, qint64 len)
if (fileHandle == INVALID_HANDLE_VALUE)
return -1;
- qint64 bytesToWrite = DWORD(len); // <- lossy
+ qint64 bytesToWrite = len;
// Writing on Windows fails with ERROR_NO_SYSTEM_RESOURCES when
// the chunks are too large, so we limit the block size to 32MB.
- static const DWORD maxBlockSize = 32 * 1024 * 1024;
-
+ const DWORD blockSize = DWORD(qMin(bytesToWrite, qint64(32 * 1024 * 1024)));
qint64 totalWritten = 0;
do {
- DWORD blockSize = qMin<DWORD>(bytesToWrite, maxBlockSize);
DWORD bytesWritten;
if (!WriteFile(fileHandle, data + totalWritten, blockSize, &bytesWritten, NULL)) {
if (totalWritten == 0) {
diff --git a/src/corelib/io/qtemporarydir.cpp b/src/corelib/io/qtemporarydir.cpp
index 563913bc12..6e50a8513e 100644
--- a/src/corelib/io/qtemporarydir.cpp
+++ b/src/corelib/io/qtemporarydir.cpp
@@ -51,8 +51,12 @@
#include "qcoreapplication.h"
#endif
+#if !defined(Q_OS_QNX) && !defined(Q_OS_WIN) && !defined(Q_OS_ANDROID) && !defined(Q_OS_INTEGRITY)
+# define USE_SYSTEM_MKDTEMP
+#endif
+
#include <stdlib.h> // mkdtemp
-#if defined(Q_OS_QNX) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_INTEGRITY)
+#ifndef USE_SYSTEM_MKDTEMP
#include <private/qfilesystemengine_p.h>
#endif
@@ -98,8 +102,7 @@ static QString defaultTemplateName()
return QDir::tempPath() + QLatin1Char('/') + baseName + QLatin1String("-XXXXXX");
}
-#if defined(Q_OS_QNX ) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_INTEGRITY)
-
+#ifndef USE_SYSTEM_MKDTEMP
static int nextRand(int &v)
{
int r = v % 62;
@@ -109,30 +112,28 @@ static int nextRand(int &v)
return r;
}
-QPair<QString, bool> q_mkdtemp(char *templateName)
+QPair<QString, bool> q_mkdtemp(QString templateName)
{
- static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ Q_ASSERT(templateName.endsWith(QLatin1String("XXXXXX")));
- const size_t length = strlen(templateName);
+ static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- char *XXXXXX = templateName + length - 6;
+ const int length = templateName.size();
- Q_ASSERT((length >= 6u) && strncmp(XXXXXX, "XXXXXX", 6) == 0);
+ QChar *XXXXXX = templateName.data() + length - 6;
for (int i = 0; i < 256; ++i) {
int v = qrand();
/* Fill in the random bits. */
- XXXXXX[0] = letters[nextRand(v)];
- XXXXXX[1] = letters[nextRand(v)];
- XXXXXX[2] = letters[nextRand(v)];
- XXXXXX[3] = letters[nextRand(v)];
- XXXXXX[4] = letters[nextRand(v)];
- XXXXXX[5] = letters[v % 62];
-
- QString templateNameStr = QFile::decodeName(templateName);
-
- QFileSystemEntry fileSystemEntry(templateNameStr);
+ XXXXXX[0] = QLatin1Char(letters[nextRand(v)]);
+ XXXXXX[1] = QLatin1Char(letters[nextRand(v)]);
+ XXXXXX[2] = QLatin1Char(letters[nextRand(v)]);
+ XXXXXX[3] = QLatin1Char(letters[nextRand(v)]);
+ XXXXXX[4] = QLatin1Char(letters[nextRand(v)]);
+ XXXXXX[5] = QLatin1Char(letters[v % 62]);
+
+ QFileSystemEntry fileSystemEntry(templateName);
if (QFileSystemEngine::createDirectory(fileSystemEntry, false)) {
QSystemError error;
QFileSystemEngine::setPermissions(fileSystemEntry,
@@ -141,10 +142,10 @@ QPair<QString, bool> q_mkdtemp(char *templateName)
QFile::ExeOwner, error);
if (error.error() != 0) {
if (!QFileSystemEngine::removeDirectory(fileSystemEntry, false))
- qWarning() << "Unable to remove unused directory" << templateNameStr;
+ qWarning() << "Unable to remove unused directory" << templateName;
continue;
}
- return qMakePair(QFile::decodeName(templateName), true);
+ return qMakePair(templateName, true);
}
# ifdef Q_OS_WIN
const int exists = ERROR_ALREADY_EXISTS;
@@ -159,7 +160,7 @@ QPair<QString, bool> q_mkdtemp(char *templateName)
return qMakePair(qt_error_string(), false);
}
-#else // defined(Q_OS_QNX ) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+#else // !USE_SYSTEM_MKDTEMP
QPair<QString, bool> q_mkdtemp(char *templateName)
{
@@ -167,14 +168,21 @@ QPair<QString, bool> q_mkdtemp(char *templateName)
return qMakePair(ok ? QFile::decodeName(templateName) : qt_error_string(), ok);
}
-#endif
+#endif // USE_SYSTEM_MKDTEMP
void QTemporaryDirPrivate::create(const QString &templateName)
{
+#ifndef USE_SYSTEM_MKDTEMP
+ QString buffer = templateName;
+ if (!buffer.endsWith(QLatin1String("XXXXXX")))
+ buffer += QLatin1String("XXXXXX");
+ const QPair<QString, bool> result = q_mkdtemp(buffer);
+#else // !USE_SYSTEM_MKDTEMP
QByteArray buffer = QFile::encodeName(templateName);
if (!buffer.endsWith("XXXXXX"))
buffer += "XXXXXX";
QPair<QString, bool> result = q_mkdtemp(buffer.data()); // modifies buffer
+#endif // USE_SYSTEM_MKDTEMP
pathOrError = result.first;
success = result.second;
}