summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/io.pri1
-rw-r--r--src/corelib/io/qdebug_p.h129
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp2
-rw-r--r--src/corelib/io/qiodevice.cpp23
-rw-r--r--src/corelib/io/qiodevice_p.h2
-rw-r--r--src/corelib/io/qprocess.cpp6
-rw-r--r--src/corelib/io/qprocess_unix.cpp19
-rw-r--r--src/corelib/io/qstandardpaths.cpp3
-rw-r--r--src/corelib/io/qwinoverlappedionotifier.cpp9
9 files changed, 166 insertions, 28 deletions
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index 78349fbc49..4c189bfe57 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -7,6 +7,7 @@ HEADERS += \
io/qdatastream_p.h \
io/qdataurl_p.h \
io/qdebug.h \
+ io/qdebug_p.h \
io/qdir.h \
io/qdir_p.h \
io/qdiriterator.h \
diff --git a/src/corelib/io/qdebug_p.h b/src/corelib/io/qdebug_p.h
new file mode 100644
index 0000000000..0525929169
--- /dev/null
+++ b/src/corelib/io/qdebug_p.h
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDEBUG_P_H
+#define QDEBUG_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qdebug.h"
+#include "QtCore/qmetaobject.h"
+#include "QtCore/qflags.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QtDebugUtils {
+
+// inline helpers for formatting basic classes.
+
+template <class Point>
+static inline void formatQPoint(QDebug &debug, const Point &point)
+{
+ debug << point.x() << ',' << point.y();
+}
+
+template <class Size>
+static inline void formatQSize(QDebug &debug, const Size &size)
+{
+ debug << size.width() << ", " << size.height();
+}
+
+template <class Rect>
+static inline void formatQRect(QDebug &debug, const Rect &rect)
+{
+ debug << rect.x() << ',' << rect.y() << ' ' << rect.width() << 'x' << rect.height();
+}
+
+template <class Margins>
+static inline void formatQMargins(QDebug &debug, const Margins &margins)
+{
+ debug << margins.left() << ", " << margins.top() << ", " << margins.right()
+ << ", " << margins.bottom();
+}
+
+#ifndef QT_NO_QOBJECT
+template <class QEnum>
+static inline void formatQEnum(QDebug &debug, QEnum value)
+{
+ const QMetaObject *metaObject = qt_getEnumMetaObject(value);
+ const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(value)));
+ if (const char *key = me.valueToKey(value))
+ debug << key;
+ else
+ debug << int(value);
+}
+
+template <class QEnum>
+static inline void formatNonNullQEnum(QDebug &debug, const char *prefix, QEnum value)
+{
+ if (value) {
+ debug << prefix;
+ formatQEnum(debug, value);
+ }
+}
+
+template <class Enum>
+static inline void formatQFlags(QDebug &debug, const QFlags<Enum> &value)
+{
+ const QMetaObject *metaObject = qt_getEnumMetaObject(Enum());
+ const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(Enum())));
+ const QDebugStateSaver saver(debug);
+ debug.noquote();
+ debug << me.valueToKeys(value);
+}
+
+template <class Enum>
+static inline void formatNonNullQFlags(QDebug &debug, const char *prefix, const QFlags<Enum> &value)
+{
+ if (value) {
+ debug << prefix;
+ formatQFlags(debug, value);
+ }
+}
+
+#endif // !QT_NO_QOBJECT
+
+} // namespace QtDebugUtils
+
+QT_END_NAMESPACE
+
+#endif // QDEBUG_P_H
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 5b18a85dd4..19343f22ff 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -545,7 +545,7 @@ bool QFSFileEngine::renameOverwrite(const QString &newName)
(wchar_t*)d->fileEntry.nativeFilePath().utf16()) != 0;
if (!ret) {
ret = ::DeleteFile((wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16()) != 0;
- if (ret)
+ if (ret || ::GetLastError() == ERROR_FILE_NOT_FOUND)
ret = ::MoveFile((wchar_t*)d->fileEntry.nativeFilePath().utf16(),
(wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16()) != 0;
}
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 7eb917c71f..7a87a78c60 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -972,6 +972,7 @@ QByteArray QIODevice::readAll()
QByteArray result;
qint64 readBytes = 0;
+ const bool sequential = d->isSequential();
// flush internal read buffer
if (!(d->openMode & Text) && !d->buffer.isEmpty()) {
@@ -979,11 +980,12 @@ QByteArray QIODevice::readAll()
return QByteArray();
result = d->buffer.readAll();
readBytes = result.size();
- d->pos += readBytes;
+ if (!sequential)
+ d->pos += readBytes;
}
qint64 theSize;
- if (d->isSequential() || (theSize = size()) == 0) {
+ if (sequential || (theSize = size()) == 0) {
// Size is unknown, read incrementally.
qint64 readResult;
do {
@@ -1629,6 +1631,23 @@ QString QIODevice::errorString() const
\sa read(), write()
*/
+/*!
+ \internal
+ \fn int qt_subtract_from_timeout(int timeout, int elapsed)
+
+ Reduces the \a timeout by \a elapsed, taking into account that -1 is a
+ special value for timeouts.
+*/
+
+int qt_subtract_from_timeout(int timeout, int elapsed)
+{
+ if (timeout == -1)
+ return -1;
+
+ timeout = timeout - elapsed;
+ return timeout < 0 ? 0 : timeout;
+}
+
#if !defined(QT_NO_DEBUG_STREAM)
QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)
diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h
index 7b4657f262..f4cf387eb5 100644
--- a/src/corelib/io/qiodevice_p.h
+++ b/src/corelib/io/qiodevice_p.h
@@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE
#define QIODEVICE_BUFFERSIZE Q_INT64_C(16384)
#endif
+Q_CORE_EXPORT int qt_subtract_from_timeout(int timeout, int elapsed);
+
// This is QIODevice's read buffer, optimized for read(), isEmpty() and getChar()
class QIODevicePrivateLinearBuffer
{
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index d5c861f9ad..80eb08b01b 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -1806,8 +1806,7 @@ bool QProcess::waitForBytesWritten(int msecs)
bool started = waitForStarted(msecs);
if (!started)
return false;
- if (msecs != -1)
- msecs -= stopWatch.elapsed();
+ msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed());
}
return d->waitForBytesWritten(msecs);
@@ -1843,8 +1842,7 @@ bool QProcess::waitForFinished(int msecs)
bool started = waitForStarted(msecs);
if (!started)
return false;
- if (msecs != -1)
- msecs -= stopWatch.elapsed();
+ msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed());
}
return d->waitForFinished(msecs);
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index fcebc08d7f..ffdf6f9e2e 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -822,19 +822,6 @@ void QProcessPrivate::killProcess()
::kill(pid_t(pid), SIGKILL);
}
-/*
- Returns the difference between msecs and elapsed. If msecs is -1,
- however, -1 is returned.
-*/
-static int qt_timeout_value(int msecs, int elapsed)
-{
- if (msecs == -1)
- return -1;
-
- int timeout = msecs - elapsed;
- return timeout < 0 ? 0 : timeout;
-}
-
bool QProcessPrivate::waitForStarted(int msecs)
{
Q_Q(QProcess);
@@ -909,7 +896,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
- int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
+ int timeout = qt_subtract_from_timeout(msecs, stopWatch.elapsed());
#ifdef Q_OS_BLACKBERRY
int ret = bb_select(notifiers, nfds + 1, &fdread, &fdwrite, timeout);
#else
@@ -990,7 +977,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
- int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
+ int timeout = qt_subtract_from_timeout(msecs, stopWatch.elapsed());
#ifdef Q_OS_BLACKBERRY
int ret = bb_select(notifiers, nfds + 1, &fdread, &fdwrite, timeout);
#else
@@ -1065,7 +1052,7 @@ bool QProcessPrivate::waitForFinished(int msecs)
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
- int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
+ int timeout = qt_subtract_from_timeout(msecs, stopWatch.elapsed());
#ifdef Q_OS_BLACKBERRY
int ret = bb_select(notifiers, nfds + 1, &fdread, &fdwrite, timeout);
#else
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index 4fd429cad4..c5c596fd2e 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -113,6 +113,9 @@ QT_BEGIN_NAMESPACE
\value GenericCacheLocation Returns a directory location where user-specific non-essential
(cached) data, shared across applications, should be written. This is a generic value.
Note that the returned path may be empty if the system has no concept of shared cache.
+ \value GenericDataLocation Returns a directory location where persistent
+ data shared across applications can be stored. This is a generic value. The returned
+ path is never empty.
\value RuntimeLocation Returns a directory location where runtime communication
files should be written, like Unix local sockets. This is a generic value.
The returned path may be empty on some systems.
diff --git a/src/corelib/io/qwinoverlappedionotifier.cpp b/src/corelib/io/qwinoverlappedionotifier.cpp
index 17d546c0ce..083feb4a20 100644
--- a/src/corelib/io/qwinoverlappedionotifier.cpp
+++ b/src/corelib/io/qwinoverlappedionotifier.cpp
@@ -41,6 +41,7 @@
#include <qthread.h>
#include <qt_windows.h>
#include <private/qobject_p.h>
+#include <private/qiodevice_p.h>
QT_BEGIN_NAMESPACE
@@ -332,11 +333,9 @@ bool QWinOverlappedIoNotifier::waitForNotified(int msecs, OVERLAPPED *overlapped
return false;
if (triggeredOverlapped == overlapped)
return true;
- if (msecs != -1) {
- t = msecs - stopWatch.elapsed();
- if (t < 0)
- return false;
- }
+ msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed());
+ if (t == 0)
+ return false;
}
}