| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfiledevice.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qplatformdefs.h" | - | ||||||||||||||||||
| 35 | #include "qfiledevice.h" | - | ||||||||||||||||||
| 36 | #include "qfiledevice_p.h" | - | ||||||||||||||||||
| 37 | #include "qfsfileengine_p.h" | - | ||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||
| 40 | #define tr(X) QString::fromLatin1(X) | - | ||||||||||||||||||
| 41 | #endif | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | static const int QFILE_WRITEBUFFER_SIZE = 16384; | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | QFileDevicePrivate::QFileDevicePrivate() | - | ||||||||||||||||||
| 48 | : fileEngine(0), | - | ||||||||||||||||||
| 49 | writeBuffer(QFILE_WRITEBUFFER_SIZE), cachedSize(0), | - | ||||||||||||||||||
| 50 | error(QFile::NoError), lastWasWrite(false) | - | ||||||||||||||||||
| 51 | { | - | ||||||||||||||||||
| 52 | } executed 58573 times by 216 tests: end of blockExecuted by:
| 58573 | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | QFileDevicePrivate::~QFileDevicePrivate() | - | ||||||||||||||||||
| 55 | { | - | ||||||||||||||||||
| 56 | delete fileEngine; | - | ||||||||||||||||||
| 57 | fileEngine = 0; | - | ||||||||||||||||||
| 58 | } executed 58565 times by 220 tests: end of blockExecuted by:
| 58565 | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | QAbstractFileEngine * QFileDevicePrivate::engine() const | - | ||||||||||||||||||
| 61 | { | - | ||||||||||||||||||
| 62 | if (!fileEngine)
| 0-451 | ||||||||||||||||||
| 63 | fileEngine = new QFSFileEngine; never executed: fileEngine = new QFSFileEngine; | 0 | ||||||||||||||||||
| 64 | return fileEngine; executed 451 times by 7 tests: return fileEngine;Executed by:
| 451 | ||||||||||||||||||
| 65 | } | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | void QFileDevicePrivate::setError(QFileDevice::FileError err) | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | error = err; | - | ||||||||||||||||||
| 70 | errorString.clear(); | - | ||||||||||||||||||
| 71 | } executed 649116 times by 216 tests: end of blockExecuted by:
| 649116 | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | void QFileDevicePrivate::setError(QFileDevice::FileError err, const QString &errStr) | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | error = err; | - | ||||||||||||||||||
| 76 | errorString = errStr; | - | ||||||||||||||||||
| 77 | } executed 4140 times by 62 tests: end of blockExecuted by:
| 4140 | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | void QFileDevicePrivate::setError(QFileDevice::FileError err, int errNum) | - | ||||||||||||||||||
| 80 | { | - | ||||||||||||||||||
| 81 | error = err; | - | ||||||||||||||||||
| 82 | errorString = qt_error_string(errNum); | - | ||||||||||||||||||
| 83 | } never executed: end of block | 0 | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | /*! | - | ||||||||||||||||||
| 86 | \enum QFileDevice::FileError | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | This enum describes the errors that may be returned by the error() | - | ||||||||||||||||||
| 89 | function. | - | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | \value NoError No error occurred. | - | ||||||||||||||||||
| 92 | \value ReadError An error occurred when reading from the file. | - | ||||||||||||||||||
| 93 | \value WriteError An error occurred when writing to the file. | - | ||||||||||||||||||
| 94 | \value FatalError A fatal error occurred. | - | ||||||||||||||||||
| 95 | \value ResourceError Out of resources (e.g., too many open files, out of memory, etc.) | - | ||||||||||||||||||
| 96 | \value OpenError The file could not be opened. | - | ||||||||||||||||||
| 97 | \value AbortError The operation was aborted. | - | ||||||||||||||||||
| 98 | \value TimeOutError A timeout occurred. | - | ||||||||||||||||||
| 99 | \value UnspecifiedError An unspecified error occurred. | - | ||||||||||||||||||
| 100 | \value RemoveError The file could not be removed. | - | ||||||||||||||||||
| 101 | \value RenameError The file could not be renamed. | - | ||||||||||||||||||
| 102 | \value PositionError The position in the file could not be changed. | - | ||||||||||||||||||
| 103 | \value ResizeError The file could not be resized. | - | ||||||||||||||||||
| 104 | \value PermissionsError The file could not be accessed. | - | ||||||||||||||||||
| 105 | \value CopyError The file could not be copied. | - | ||||||||||||||||||
| 106 | */ | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | /*! | - | ||||||||||||||||||
| 109 | \enum QFileDevice::Permission | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | This enum is used by the permission() function to report the | - | ||||||||||||||||||
| 112 | permissions and ownership of a file. The values may be OR-ed | - | ||||||||||||||||||
| 113 | together to test multiple permissions and ownership values. | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | \value ReadOwner The file is readable by the owner of the file. | - | ||||||||||||||||||
| 116 | \value WriteOwner The file is writable by the owner of the file. | - | ||||||||||||||||||
| 117 | \value ExeOwner The file is executable by the owner of the file. | - | ||||||||||||||||||
| 118 | \value ReadUser The file is readable by the user. | - | ||||||||||||||||||
| 119 | \value WriteUser The file is writable by the user. | - | ||||||||||||||||||
| 120 | \value ExeUser The file is executable by the user. | - | ||||||||||||||||||
| 121 | \value ReadGroup The file is readable by the group. | - | ||||||||||||||||||
| 122 | \value WriteGroup The file is writable by the group. | - | ||||||||||||||||||
| 123 | \value ExeGroup The file is executable by the group. | - | ||||||||||||||||||
| 124 | \value ReadOther The file is readable by anyone. | - | ||||||||||||||||||
| 125 | \value WriteOther The file is writable by anyone. | - | ||||||||||||||||||
| 126 | \value ExeOther The file is executable by anyone. | - | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | \warning Because of differences in the platforms supported by Qt, | - | ||||||||||||||||||
| 129 | the semantics of ReadUser, WriteUser and ExeUser are | - | ||||||||||||||||||
| 130 | platform-dependent: On Unix, the rights of the owner of the file | - | ||||||||||||||||||
| 131 | are returned and on Windows the rights of the current user are | - | ||||||||||||||||||
| 132 | returned. This behavior might change in a future Qt version. | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | \note On NTFS file systems, ownership and permissions checking is | - | ||||||||||||||||||
| 135 | disabled by default for performance reasons. To enable it, | - | ||||||||||||||||||
| 136 | include the following line: | - | ||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | \snippet ntfsp.cpp 0 | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | Permission checking is then turned on and off by incrementing and | - | ||||||||||||||||||
| 141 | decrementing \c qt_ntfs_permission_lookup by 1. | - | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | \snippet ntfsp.cpp 1 | - | ||||||||||||||||||
| 144 | */ | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | //************* QFileDevice | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | /*! | - | ||||||||||||||||||
| 149 | \class QFileDevice | - | ||||||||||||||||||
| 150 | \inmodule QtCore | - | ||||||||||||||||||
| 151 | \since 5.0 | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | \brief The QFileDevice class provides an interface for reading from and writing to open files. | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | \ingroup io | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | \reentrant | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | QFileDevice is the base class for I/O devices that can read and write text and binary files | - | ||||||||||||||||||
| 160 | and \l{The Qt Resource System}{resources}. QFile offers the main functionality, | - | ||||||||||||||||||
| 161 | QFileDevice serves as a base class for sharing functionality with other file devices such | - | ||||||||||||||||||
| 162 | as QTemporaryFile, by providing all the operations that can be done on files that have | - | ||||||||||||||||||
| 163 | been opened by QFile or QTemporaryFile. | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | \sa QFile, QTemporaryFile | - | ||||||||||||||||||
| 166 | */ | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | /*! | - | ||||||||||||||||||
| 169 | \enum QFileDevice::FileHandleFlag | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | This enum is used when opening a file to specify additional | - | ||||||||||||||||||
| 172 | options which only apply to files and not to a generic | - | ||||||||||||||||||
| 173 | QIODevice. | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | \value AutoCloseHandle The file handle passed into open() should be | - | ||||||||||||||||||
| 176 | closed by close(), the default behavior is that close just flushes | - | ||||||||||||||||||
| 177 | the file and the application is responsible for closing the file handle. | - | ||||||||||||||||||
| 178 | When opening a file by name, this flag is ignored as Qt always owns the | - | ||||||||||||||||||
| 179 | file handle and must close it. | - | ||||||||||||||||||
| 180 | \value DontCloseHandle If not explicitly closed, the underlying file | - | ||||||||||||||||||
| 181 | handle is left open when the QFile object is destroyed. | - | ||||||||||||||||||
| 182 | */ | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||
| 185 | QFileDevice::QFileDevice() | - | ||||||||||||||||||
| 186 | : QIODevice(*new QFileDevicePrivate) | - | ||||||||||||||||||
| 187 | { | - | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | QFileDevice::QFileDevice(QFileDevicePrivate &dd) | - | ||||||||||||||||||
| 190 | : QIODevice(dd) | - | ||||||||||||||||||
| 191 | { | - | ||||||||||||||||||
| 192 | } | - | ||||||||||||||||||
| 193 | #else | - | ||||||||||||||||||
| 194 | /*! | - | ||||||||||||||||||
| 195 | \internal | - | ||||||||||||||||||
| 196 | */ | - | ||||||||||||||||||
| 197 | QFileDevice::QFileDevice() | - | ||||||||||||||||||
| 198 | : QIODevice(*new QFileDevicePrivate, 0) | - | ||||||||||||||||||
| 199 | { | - | ||||||||||||||||||
| 200 | } never executed: end of block | 0 | ||||||||||||||||||
| 201 | /*! | - | ||||||||||||||||||
| 202 | \internal | - | ||||||||||||||||||
| 203 | */ | - | ||||||||||||||||||
| 204 | QFileDevice::QFileDevice(QObject *parent) | - | ||||||||||||||||||
| 205 | : QIODevice(*new QFileDevicePrivate, parent) | - | ||||||||||||||||||
| 206 | { | - | ||||||||||||||||||
| 207 | } never executed: end of block | 0 | ||||||||||||||||||
| 208 | /*! | - | ||||||||||||||||||
| 209 | \internal | - | ||||||||||||||||||
| 210 | */ | - | ||||||||||||||||||
| 211 | QFileDevice::QFileDevice(QFileDevicePrivate &dd, QObject *parent) | - | ||||||||||||||||||
| 212 | : QIODevice(dd, parent) | - | ||||||||||||||||||
| 213 | { | - | ||||||||||||||||||
| 214 | } executed 58573 times by 216 tests: end of blockExecuted by:
| 58573 | ||||||||||||||||||
| 215 | #endif | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | /*! | - | ||||||||||||||||||
| 218 | Destroys the file device, closing it if necessary. | - | ||||||||||||||||||
| 219 | */ | - | ||||||||||||||||||
| 220 | QFileDevice::~QFileDevice() | - | ||||||||||||||||||
| 221 | { | - | ||||||||||||||||||
| 222 | close(); | - | ||||||||||||||||||
| 223 | } executed 58565 times by 220 tests: end of blockExecuted by:
| 58565 | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | /*! | - | ||||||||||||||||||
| 226 | Returns \c true if the file can only be manipulated sequentially; | - | ||||||||||||||||||
| 227 | otherwise returns \c false. | - | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | Most files support random-access, but some special files may not. | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | \sa QIODevice::isSequential() | - | ||||||||||||||||||
| 232 | */ | - | ||||||||||||||||||
| 233 | bool QFileDevice::isSequential() const | - | ||||||||||||||||||
| 234 | { | - | ||||||||||||||||||
| 235 | Q_D(const QFileDevice); | - | ||||||||||||||||||
| 236 | return d->fileEngine && d->fileEngine->isSequential(); executed 94236 times by 143 tests: return d->fileEngine && d->fileEngine->isSequential();Executed by:
| 0-94236 | ||||||||||||||||||
| 237 | } | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | /*! | - | ||||||||||||||||||
| 240 | Returns the file handle of the file. | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | This is a small positive integer, suitable for use with C library | - | ||||||||||||||||||
| 243 | functions such as \c fdopen() and \c fcntl(). On systems that use file | - | ||||||||||||||||||
| 244 | descriptors for sockets (i.e. Unix systems, but not Windows) the handle | - | ||||||||||||||||||
| 245 | can be used with QSocketNotifier as well. | - | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | If the file is not open, or there is an error, handle() returns -1. | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | This function is not supported on Windows CE. | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | \sa QSocketNotifier | - | ||||||||||||||||||
| 252 | */ | - | ||||||||||||||||||
| 253 | int QFileDevice::handle() const | - | ||||||||||||||||||
| 254 | { | - | ||||||||||||||||||
| 255 | Q_D(const QFileDevice); | - | ||||||||||||||||||
| 256 | if (!isOpen() || !d->fileEngine)
| 0-35 | ||||||||||||||||||
| 257 | return -1; executed 4 times by 1 test: return -1;Executed by:
| 4 | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | return d->fileEngine->handle(); executed 35 times by 6 tests: return d->fileEngine->handle();Executed by:
| 35 | ||||||||||||||||||
| 260 | } | - | ||||||||||||||||||
| 261 | - | |||||||||||||||||||
| 262 | /*! | - | ||||||||||||||||||
| 263 | Returns the name of the file. | - | ||||||||||||||||||
| 264 | The default implementation in QFileDevice returns a null string. | - | ||||||||||||||||||
| 265 | */ | - | ||||||||||||||||||
| 266 | QString QFileDevice::fileName() const | - | ||||||||||||||||||
| 267 | { | - | ||||||||||||||||||
| 268 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 269 | } | - | ||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | static inline qint64 _qfile_writeData(QAbstractFileEngine *engine, QRingBuffer *buffer) | - | ||||||||||||||||||
| 272 | { | - | ||||||||||||||||||
| 273 | qint64 ret = engine->write(buffer->readPointer(), buffer->nextDataBlockSize()); | - | ||||||||||||||||||
| 274 | if (ret > 0)
| 6-18438 | ||||||||||||||||||
| 275 | buffer->free(ret); executed 18438 times by 42 tests: buffer->free(ret);Executed by:
| 18438 | ||||||||||||||||||
| 276 | return ret; executed 18444 times by 42 tests: return ret;Executed by:
| 18444 | ||||||||||||||||||
| 277 | } | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | /*! | - | ||||||||||||||||||
| 280 | Flushes any buffered data to the file. Returns \c true if successful; | - | ||||||||||||||||||
| 281 | otherwise returns \c false. | - | ||||||||||||||||||
| 282 | */ | - | ||||||||||||||||||
| 283 | bool QFileDevice::flush() | - | ||||||||||||||||||
| 284 | { | - | ||||||||||||||||||
| 285 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 286 | if (!d->fileEngine) {
| 0-58964 | ||||||||||||||||||
| 287 | qWarning("QFileDevice::flush: No file engine. Is IODevice open?"); | - | ||||||||||||||||||
| 288 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 289 | } | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | if (!d->writeBuffer.isEmpty()) {
| 18444-40520 | ||||||||||||||||||
| 292 | qint64 size = d->writeBuffer.size(); | - | ||||||||||||||||||
| 293 | if (_qfile_writeData(d->fileEngine, &d->writeBuffer) != size) {
| 6-18438 | ||||||||||||||||||
| 294 | QFileDevice::FileError err = d->fileEngine->error(); | - | ||||||||||||||||||
| 295 | if (err == QFileDevice::UnspecifiedError)
| 0-6 | ||||||||||||||||||
| 296 | err = QFileDevice::WriteError; never executed: err = QFileDevice::WriteError; | 0 | ||||||||||||||||||
| 297 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 298 | return false; executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | } executed 18438 times by 42 tests: end of blockExecuted by:
| 18438 | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | if (!d->fileEngine->flush()) {
| 0-58958 | ||||||||||||||||||
| 303 | QFileDevice::FileError err = d->fileEngine->error(); | - | ||||||||||||||||||
| 304 | if (err == QFileDevice::UnspecifiedError)
| 0 | ||||||||||||||||||
| 305 | err = QFileDevice::WriteError; never executed: err = QFileDevice::WriteError; | 0 | ||||||||||||||||||
| 306 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 307 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 308 | } | - | ||||||||||||||||||
| 309 | return true; executed 58958 times by 180 tests: return true;Executed by:
| 58958 | ||||||||||||||||||
| 310 | } | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | /*! | - | ||||||||||||||||||
| 313 | Calls QFileDevice::flush() and closes the file. Errors from flush are ignored. | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | \sa QIODevice::close() | - | ||||||||||||||||||
| 316 | */ | - | ||||||||||||||||||
| 317 | void QFileDevice::close() | - | ||||||||||||||||||
| 318 | { | - | ||||||||||||||||||
| 319 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 320 | if (!isOpen())
| 36721-40805 | ||||||||||||||||||
| 321 | return; executed 36721 times by 194 tests: return;Executed by:
| 36721 | ||||||||||||||||||
| 322 | bool flushed = flush(); | - | ||||||||||||||||||
| 323 | QIODevice::close(); | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | // reset write buffer | - | ||||||||||||||||||
| 326 | d->lastWasWrite = false; | - | ||||||||||||||||||
| 327 | d->writeBuffer.clear(); | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | // keep earlier error from flush | - | ||||||||||||||||||
| 330 | if (d->fileEngine->close() && flushed)
| 0-40805 | ||||||||||||||||||
| 331 | unsetError(); executed 40803 times by 180 tests: unsetError();Executed by:
| 40803 | ||||||||||||||||||
| 332 | else if (flushed)
| 0-2 | ||||||||||||||||||
| 333 | d->setError(d->fileEngine->error(), d->fileEngine->errorString()); never executed: d->setError(d->fileEngine->error(), d->fileEngine->errorString()); | 0 | ||||||||||||||||||
| 334 | } executed 40805 times by 180 tests: end of blockExecuted by:
| 40805 | ||||||||||||||||||
| 335 | - | |||||||||||||||||||
| 336 | /*! | - | ||||||||||||||||||
| 337 | \reimp | - | ||||||||||||||||||
| 338 | */ | - | ||||||||||||||||||
| 339 | qint64 QFileDevice::pos() const | - | ||||||||||||||||||
| 340 | { | - | ||||||||||||||||||
| 341 | return QIODevice::pos(); executed 481322 times by 100 tests: return QIODevice::pos();Executed by:
| 481322 | ||||||||||||||||||
| 342 | } | - | ||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | /*! | - | ||||||||||||||||||
| 345 | Returns \c true if the end of the file has been reached; otherwise returns | - | ||||||||||||||||||
| 346 | false. | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | For regular empty files on Unix (e.g. those in \c /proc), this function | - | ||||||||||||||||||
| 349 | returns \c true, since the file system reports that the size of such a file is | - | ||||||||||||||||||
| 350 | 0. Therefore, you should not depend on atEnd() when reading data from such a | - | ||||||||||||||||||
| 351 | file, but rather call read() until no more data can be read. | - | ||||||||||||||||||
| 352 | */ | - | ||||||||||||||||||
| 353 | bool QFileDevice::atEnd() const | - | ||||||||||||||||||
| 354 | { | - | ||||||||||||||||||
| 355 | Q_D(const QFileDevice); | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | // If there's buffered data left, we're not at the end. | - | ||||||||||||||||||
| 358 | if (!d->buffer.isEmpty())
| 4588-107109 | ||||||||||||||||||
| 359 | return false; executed 107109 times by 19 tests: return false;Executed by:
| 107109 | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | if (!isOpen())
| 0-4588 | ||||||||||||||||||
| 362 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | if (!d->ensureFlushed())
| 0-4588 | ||||||||||||||||||
| 365 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | // If the file engine knows best, say what it says. | - | ||||||||||||||||||
| 368 | if (d->fileEngine->supportsExtension(QAbstractFileEngine::AtEndExtension)) {
| 0-4588 | ||||||||||||||||||
| 369 | // Check if the file engine supports AtEndExtension, and if it does, | - | ||||||||||||||||||
| 370 | // check if the file engine claims to be at the end. | - | ||||||||||||||||||
| 371 | return d->fileEngine->atEnd(); never executed: return d->fileEngine->atEnd(); | 0 | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | // if it looks like we are at the end, or if size is not cached, | - | ||||||||||||||||||
| 375 | // fall through to bytesAvailable() to make sure. | - | ||||||||||||||||||
| 376 | if (pos() < d->cachedSize)
| 382-4206 | ||||||||||||||||||
| 377 | return false; executed 382 times by 7 tests: return false;Executed by:
| 382 | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | // Fall back to checking how much is available (will stat files). | - | ||||||||||||||||||
| 380 | return bytesAvailable() == 0; executed 4206 times by 28 tests: return bytesAvailable() == 0;Executed by:
| 4206 | ||||||||||||||||||
| 381 | } | - | ||||||||||||||||||
| 382 | - | |||||||||||||||||||
| 383 | /*! | - | ||||||||||||||||||
| 384 | \fn bool QFileDevice::seek(qint64 pos) | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | For random-access devices, this function sets the current position | - | ||||||||||||||||||
| 387 | to \a pos, returning true on success, or false if an error occurred. | - | ||||||||||||||||||
| 388 | For sequential devices, the default behavior is to do nothing and | - | ||||||||||||||||||
| 389 | return false. | - | ||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | Seeking beyond the end of a file: | - | ||||||||||||||||||
| 392 | If the position is beyond the end of a file, then seek() will not | - | ||||||||||||||||||
| 393 | immediately extend the file. If a write is performed at this position, | - | ||||||||||||||||||
| 394 | then the file will be extended. The content of the file between the | - | ||||||||||||||||||
| 395 | previous end of file and the newly written data is UNDEFINED and | - | ||||||||||||||||||
| 396 | varies between platforms and file systems. | - | ||||||||||||||||||
| 397 | */ | - | ||||||||||||||||||
| 398 | bool QFileDevice::seek(qint64 off) | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 401 | if (!isOpen()) {
| 0-230331 | ||||||||||||||||||
| 402 | qWarning("QFileDevice::seek: IODevice is not open"); | - | ||||||||||||||||||
| 403 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 404 | } | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | if (!d->ensureFlushed())
| 0-230331 | ||||||||||||||||||
| 407 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | if (!d->fileEngine->seek(off) || !QIODevice::seek(off)) {
| 0-230331 | ||||||||||||||||||
| 410 | QFileDevice::FileError err = d->fileEngine->error(); | - | ||||||||||||||||||
| 411 | if (err == QFileDevice::UnspecifiedError)
| 0 | ||||||||||||||||||
| 412 | err = QFileDevice::PositionError; never executed: err = QFileDevice::PositionError; | 0 | ||||||||||||||||||
| 413 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 414 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 415 | } | - | ||||||||||||||||||
| 416 | unsetError(); | - | ||||||||||||||||||
| 417 | return true; executed 230331 times by 90 tests: return true;Executed by:
| 230331 | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | /*! | - | ||||||||||||||||||
| 421 | \reimp | - | ||||||||||||||||||
| 422 | */ | - | ||||||||||||||||||
| 423 | qint64 QFileDevice::readLineData(char *data, qint64 maxlen) | - | ||||||||||||||||||
| 424 | { | - | ||||||||||||||||||
| 425 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 426 | if (!d->ensureFlushed())
| 0-583 | ||||||||||||||||||
| 427 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | qint64 read; | - | ||||||||||||||||||
| 430 | if (d->fileEngine->supportsExtension(QAbstractFileEngine::FastReadLineExtension)) {
| 8-575 | ||||||||||||||||||
| 431 | read = d->fileEngine->readLine(data, maxlen); | - | ||||||||||||||||||
| 432 | } else { executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 433 | // Fall back to QIODevice's readLine implementation if the engine | - | ||||||||||||||||||
| 434 | // cannot do it faster. | - | ||||||||||||||||||
| 435 | read = QIODevice::readLineData(data, maxlen); | - | ||||||||||||||||||
| 436 | } executed 575 times by 15 tests: end of blockExecuted by:
| 575 | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | if (read < maxlen) {
| 1-582 | ||||||||||||||||||
| 439 | // failed to read all requested, may be at the end of file, stop caching size so that it's rechecked | - | ||||||||||||||||||
| 440 | d->cachedSize = 0; | - | ||||||||||||||||||
| 441 | } executed 582 times by 15 tests: end of blockExecuted by:
| 582 | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | return read; executed 583 times by 15 tests: return read;Executed by:
| 583 | ||||||||||||||||||
| 444 | } | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | /*! | - | ||||||||||||||||||
| 447 | \reimp | - | ||||||||||||||||||
| 448 | */ | - | ||||||||||||||||||
| 449 | qint64 QFileDevice::readData(char *data, qint64 len) | - | ||||||||||||||||||
| 450 | { | - | ||||||||||||||||||
| 451 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 452 | if (!len)
| 16998-109995 | ||||||||||||||||||
| 453 | return 0; executed 16998 times by 92 tests: return 0;Executed by:
| 16998 | ||||||||||||||||||
| 454 | unsetError(); | - | ||||||||||||||||||
| 455 | if (!d->ensureFlushed())
| 0-109995 | ||||||||||||||||||
| 456 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | const qint64 read = d->fileEngine->read(data, len); | - | ||||||||||||||||||
| 459 | if (read < 0) {
| 0-109995 | ||||||||||||||||||
| 460 | QFileDevice::FileError err = d->fileEngine->error(); | - | ||||||||||||||||||
| 461 | if (err == QFileDevice::UnspecifiedError)
| 0 | ||||||||||||||||||
| 462 | err = QFileDevice::ReadError; never executed: err = QFileDevice::ReadError; | 0 | ||||||||||||||||||
| 463 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 464 | } never executed: end of block | 0 | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | if (read < len) {
| 15561-94434 | ||||||||||||||||||
| 467 | // failed to read all requested, may be at the end of file, stop caching size so that it's rechecked | - | ||||||||||||||||||
| 468 | d->cachedSize = 0; | - | ||||||||||||||||||
| 469 | } executed 94434 times by 127 tests: end of blockExecuted by:
| 94434 | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | return read; executed 109995 times by 137 tests: return read;Executed by:
| 109995 | ||||||||||||||||||
| 472 | } | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | /*! | - | ||||||||||||||||||
| 475 | \internal | - | ||||||||||||||||||
| 476 | */ | - | ||||||||||||||||||
| 477 | bool QFileDevicePrivate::putCharHelper(char c) | - | ||||||||||||||||||
| 478 | { | - | ||||||||||||||||||
| 479 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||
| 480 | return QIODevicePrivate::putCharHelper(c); | - | ||||||||||||||||||
| 481 | #else | - | ||||||||||||||||||
| 482 | - | |||||||||||||||||||
| 483 | // Cutoff for code that doesn't only touch the buffer. | - | ||||||||||||||||||
| 484 | qint64 writeBufferSize = writeBuffer.size(); | - | ||||||||||||||||||
| 485 | if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QFILE_WRITEBUFFER_SIZE
| 0-2144 | ||||||||||||||||||
| 486 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
| 487 | || ((openMode & QIODevice::Text) && c == '\n' && writeBufferSize + 2 >= QFILE_WRITEBUFFER_SIZE) | - | ||||||||||||||||||
| 488 | #endif | - | ||||||||||||||||||
| 489 | ) { | - | ||||||||||||||||||
| 490 | return QIODevicePrivate::putCharHelper(c); never executed: return QIODevicePrivate::putCharHelper(c); | 0 | ||||||||||||||||||
| 491 | } | - | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | if (!(openMode & QIODevice::WriteOnly)) {
| 0-2144 | ||||||||||||||||||
| 494 | if (openMode == QIODevice::NotOpen)
| 0 | ||||||||||||||||||
| 495 | qWarning("QIODevice::putChar: Closed device"); never executed: QMessageLogger(__FILE__, 495, __PRETTY_FUNCTION__).warning("QIODevice::putChar: Closed device"); | 0 | ||||||||||||||||||
| 496 | else | - | ||||||||||||||||||
| 497 | qWarning("QIODevice::putChar: ReadOnly device"); never executed: QMessageLogger(__FILE__, 497, __PRETTY_FUNCTION__).warning("QIODevice::putChar: ReadOnly device"); | 0 | ||||||||||||||||||
| 498 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 499 | } | - | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | // Make sure the device is positioned correctly. | - | ||||||||||||||||||
| 502 | const bool sequential = isSequential(); | - | ||||||||||||||||||
| 503 | if (pos != devicePos && !sequential && !q_func()->seek(pos))
| 0-2144 | ||||||||||||||||||
| 504 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | lastWasWrite = true; | - | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | int len = 1; | - | ||||||||||||||||||
| 509 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
| 510 | if ((openMode & QIODevice::Text) && c == '\n') { | - | ||||||||||||||||||
| 511 | ++len; | - | ||||||||||||||||||
| 512 | *writeBuffer.reserve(1) = '\r'; | - | ||||||||||||||||||
| 513 | } | - | ||||||||||||||||||
| 514 | #endif | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | // Write to buffer. | - | ||||||||||||||||||
| 517 | *writeBuffer.reserve(1) = c; | - | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | if (!sequential) {
| 0-2144 | ||||||||||||||||||
| 520 | pos += len; | - | ||||||||||||||||||
| 521 | devicePos += len; | - | ||||||||||||||||||
| 522 | if (!buffer.isEmpty())
| 0-2144 | ||||||||||||||||||
| 523 | buffer.skip(len); never executed: buffer.skip(len); | 0 | ||||||||||||||||||
| 524 | } executed 2144 times by 6 tests: end of blockExecuted by:
| 2144 | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | return true; executed 2144 times by 6 tests: return true;Executed by:
| 2144 | ||||||||||||||||||
| 527 | #endif | - | ||||||||||||||||||
| 528 | } | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | /*! | - | ||||||||||||||||||
| 531 | \reimp | - | ||||||||||||||||||
| 532 | */ | - | ||||||||||||||||||
| 533 | qint64 QFileDevice::writeData(const char *data, qint64 len) | - | ||||||||||||||||||
| 534 | { | - | ||||||||||||||||||
| 535 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 536 | unsetError(); | - | ||||||||||||||||||
| 537 | d->lastWasWrite = true; | - | ||||||||||||||||||
| 538 | bool buffered = !(d->openMode & Unbuffered); | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | // Flush buffered data if this read will overflow. | - | ||||||||||||||||||
| 541 | if (buffered && (d->writeBuffer.size() + len) > QFILE_WRITEBUFFER_SIZE) {
| 542-128820 | ||||||||||||||||||
| 542 | if (!flush())
| 0-542 | ||||||||||||||||||
| 543 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 544 | } executed 542 times by 12 tests: end of blockExecuted by:
| 542 | ||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | // Write directly to the engine if the block size is larger than | - | ||||||||||||||||||
| 547 | // the write buffer size. | - | ||||||||||||||||||
| 548 | if (!buffered || len > QFILE_WRITEBUFFER_SIZE) {
| 53-128820 | ||||||||||||||||||
| 549 | const qint64 ret = d->fileEngine->write(data, len); | - | ||||||||||||||||||
| 550 | if (ret < 0) {
| 0-704 | ||||||||||||||||||
| 551 | QFileDevice::FileError err = d->fileEngine->error(); | - | ||||||||||||||||||
| 552 | if (err == QFileDevice::UnspecifiedError)
| 0 | ||||||||||||||||||
| 553 | err = QFileDevice::WriteError; never executed: err = QFileDevice::WriteError; | 0 | ||||||||||||||||||
| 554 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 555 | } never executed: end of block | 0 | ||||||||||||||||||
| 556 | return ret; executed 704 times by 11 tests: return ret;Executed by:
| 704 | ||||||||||||||||||
| 557 | } | - | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | // Write to the buffer. | - | ||||||||||||||||||
| 560 | char *writePointer = d->writeBuffer.reserve(len); | - | ||||||||||||||||||
| 561 | if (len == 1)
| 59006-69761 | ||||||||||||||||||
| 562 | *writePointer = *data; executed 69761 times by 7 tests: *writePointer = *data;Executed by:
| 69761 | ||||||||||||||||||
| 563 | else if (len)
| 10-58996 | ||||||||||||||||||
| 564 | ::memcpy(writePointer, data, len); executed 58996 times by 42 tests: ::memcpy(writePointer, data, len);Executed by:
| 58996 | ||||||||||||||||||
| 565 | return len; executed 128767 times by 42 tests: return len;Executed by:
| 128767 | ||||||||||||||||||
| 566 | } | - | ||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | /*! | - | ||||||||||||||||||
| 569 | Returns the file error status. | - | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | The I/O device status returns an error code. For example, if open() | - | ||||||||||||||||||
| 572 | returns \c false, or a read/write operation returns -1, this function can | - | ||||||||||||||||||
| 573 | be called to find out the reason why the operation failed. | - | ||||||||||||||||||
| 574 | - | |||||||||||||||||||
| 575 | \sa unsetError() | - | ||||||||||||||||||
| 576 | */ | - | ||||||||||||||||||
| 577 | QFileDevice::FileError QFileDevice::error() const | - | ||||||||||||||||||
| 578 | { | - | ||||||||||||||||||
| 579 | Q_D(const QFileDevice); | - | ||||||||||||||||||
| 580 | return d->error; executed 13373 times by 75 tests: return d->error;Executed by:
| 13373 | ||||||||||||||||||
| 581 | } | - | ||||||||||||||||||
| 582 | - | |||||||||||||||||||
| 583 | /*! | - | ||||||||||||||||||
| 584 | Sets the file's error to QFileDevice::NoError. | - | ||||||||||||||||||
| 585 | - | |||||||||||||||||||
| 586 | \sa error() | - | ||||||||||||||||||
| 587 | */ | - | ||||||||||||||||||
| 588 | void QFileDevice::unsetError() | - | ||||||||||||||||||
| 589 | { | - | ||||||||||||||||||
| 590 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 591 | d->setError(QFileDevice::NoError); | - | ||||||||||||||||||
| 592 | } executed 649116 times by 216 tests: end of blockExecuted by:
| 649116 | ||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | /*! | - | ||||||||||||||||||
| 595 | Returns the size of the file. | - | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | For regular empty files on Unix (e.g. those in \c /proc), this function | - | ||||||||||||||||||
| 598 | returns 0; the contents of such a file are generated on demand in response | - | ||||||||||||||||||
| 599 | to you calling read(). | - | ||||||||||||||||||
| 600 | */ | - | ||||||||||||||||||
| 601 | qint64 QFileDevice::size() const | - | ||||||||||||||||||
| 602 | { | - | ||||||||||||||||||
| 603 | Q_D(const QFileDevice); | - | ||||||||||||||||||
| 604 | if (!d->ensureFlushed())
| 0-164647 | ||||||||||||||||||
| 605 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 606 | d->cachedSize = d->engine()->size(); | - | ||||||||||||||||||
| 607 | return d->cachedSize; executed 164647 times by 162 tests: return d->cachedSize;Executed by:
| 164647 | ||||||||||||||||||
| 608 | } | - | ||||||||||||||||||
| 609 | - | |||||||||||||||||||
| 610 | /*! | - | ||||||||||||||||||
| 611 | Sets the file size (in bytes) \a sz. Returns \c true if the | - | ||||||||||||||||||
| 612 | resize succeeds; false otherwise. If \a sz is larger than the file | - | ||||||||||||||||||
| 613 | currently is, the new bytes will be set to 0; if \a sz is smaller, the | - | ||||||||||||||||||
| 614 | file is simply truncated. | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | \sa size() | - | ||||||||||||||||||
| 617 | */ | - | ||||||||||||||||||
| 618 | bool QFileDevice::resize(qint64 sz) | - | ||||||||||||||||||
| 619 | { | - | ||||||||||||||||||
| 620 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 621 | if (!d->ensureFlushed())
| 0-295 | ||||||||||||||||||
| 622 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 623 | d->engine(); | - | ||||||||||||||||||
| 624 | if (isOpen() && d->fileEngine->pos() > sz)
| 5-284 | ||||||||||||||||||
| 625 | seek(sz); executed 5 times by 2 tests: seek(sz);Executed by:
| 5 | ||||||||||||||||||
| 626 | if (d->fileEngine->setSize(sz)) {
| 0-295 | ||||||||||||||||||
| 627 | unsetError(); | - | ||||||||||||||||||
| 628 | d->cachedSize = sz; | - | ||||||||||||||||||
| 629 | return true; executed 295 times by 7 tests: return true;Executed by:
| 295 | ||||||||||||||||||
| 630 | } | - | ||||||||||||||||||
| 631 | d->cachedSize = 0; | - | ||||||||||||||||||
| 632 | d->setError(QFile::ResizeError, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 633 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 634 | } | - | ||||||||||||||||||
| 635 | - | |||||||||||||||||||
| 636 | /*! | - | ||||||||||||||||||
| 637 | Returns the complete OR-ed together combination of | - | ||||||||||||||||||
| 638 | QFile::Permission for the file. | - | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | \sa setPermissions() | - | ||||||||||||||||||
| 641 | */ | - | ||||||||||||||||||
| 642 | QFile::Permissions QFileDevice::permissions() const | - | ||||||||||||||||||
| 643 | { | - | ||||||||||||||||||
| 644 | Q_D(const QFileDevice); | - | ||||||||||||||||||
| 645 | QAbstractFileEngine::FileFlags perms = d->engine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask; | - | ||||||||||||||||||
| 646 | return QFile::Permissions((int)perms); //ewww executed 198 times by 11 tests: return QFile::Permissions((int)perms);Executed by:
| 198 | ||||||||||||||||||
| 647 | } | - | ||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | /*! | - | ||||||||||||||||||
| 650 | Sets the permissions for the file to the \a permissions specified. | - | ||||||||||||||||||
| 651 | Returns \c true if successful, or \c false if the permissions cannot be | - | ||||||||||||||||||
| 652 | modified. | - | ||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | \warning This function does not manipulate ACLs, which may limit its | - | ||||||||||||||||||
| 655 | effectiveness. | - | ||||||||||||||||||
| 656 | - | |||||||||||||||||||
| 657 | \sa permissions() | - | ||||||||||||||||||
| 658 | */ | - | ||||||||||||||||||
| 659 | bool QFileDevice::setPermissions(Permissions permissions) | - | ||||||||||||||||||
| 660 | { | - | ||||||||||||||||||
| 661 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 662 | if (d->engine()->setPermissions(permissions)) {
| 1-1070 | ||||||||||||||||||
| 663 | unsetError(); | - | ||||||||||||||||||
| 664 | return true; executed 1070 times by 21 tests: return true;Executed by:
| 1070 | ||||||||||||||||||
| 665 | } | - | ||||||||||||||||||
| 666 | d->setError(QFile::PermissionsError, d->fileEngine->errorString()); | - | ||||||||||||||||||
| 667 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 668 | } | - | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | /*! | - | ||||||||||||||||||
| 671 | \enum QFileDevice::MemoryMapFlags | - | ||||||||||||||||||
| 672 | \since 4.4 | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | This enum describes special options that may be used by the map() | - | ||||||||||||||||||
| 675 | function. | - | ||||||||||||||||||
| 676 | - | |||||||||||||||||||
| 677 | \value NoOptions No options. | - | ||||||||||||||||||
| 678 | \value MapPrivateOption The mapped memory will be private, so any | - | ||||||||||||||||||
| 679 | modifications will not be visible to other processes and will not | - | ||||||||||||||||||
| 680 | be written to disk. Any such modifications will be lost when the | - | ||||||||||||||||||
| 681 | memory is unmapped. It is unspecified whether modifications made | - | ||||||||||||||||||
| 682 | to the file made after the mapping is created will be visible through | - | ||||||||||||||||||
| 683 | the mapped memory. This flag is not supported on Windows CE. | - | ||||||||||||||||||
| 684 | This enum value was introduced in Qt 5.4. | - | ||||||||||||||||||
| 685 | */ | - | ||||||||||||||||||
| 686 | - | |||||||||||||||||||
| 687 | /*! | - | ||||||||||||||||||
| 688 | Maps \a size bytes of the file into memory starting at \a offset. A file | - | ||||||||||||||||||
| 689 | should be open for a map to succeed but the file does not need to stay | - | ||||||||||||||||||
| 690 | open after the memory has been mapped. When the QFile is destroyed | - | ||||||||||||||||||
| 691 | or a new file is opened with this object, any maps that have not been | - | ||||||||||||||||||
| 692 | unmapped will automatically be unmapped. | - | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | The mapping will have the same open mode as the file (read and/or write), | - | ||||||||||||||||||
| 695 | except when using MapPrivateOption, in which case it is always possible | - | ||||||||||||||||||
| 696 | to write to the mapped memory. | - | ||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | Any mapping options can be passed through \a flags. | - | ||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | Returns a pointer to the memory or 0 if there is an error. | - | ||||||||||||||||||
| 701 | - | |||||||||||||||||||
| 702 | \note On Windows CE 5.0 the file will be closed before mapping occurs. | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | \sa unmap() | - | ||||||||||||||||||
| 705 | */ | - | ||||||||||||||||||
| 706 | uchar *QFileDevice::map(qint64 offset, qint64 size, MemoryMapFlags flags) | - | ||||||||||||||||||
| 707 | { | - | ||||||||||||||||||
| 708 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 709 | if (d->engine()
| 0-34289 | ||||||||||||||||||
| 710 | && d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
| 0-34289 | ||||||||||||||||||
| 711 | unsetError(); | - | ||||||||||||||||||
| 712 | uchar *address = d->fileEngine->map(offset, size, flags); | - | ||||||||||||||||||
| 713 | if (address == 0)
| 24-34265 | ||||||||||||||||||
| 714 | d->setError(d->fileEngine->error(), d->fileEngine->errorString()); executed 24 times by 1 test: d->setError(d->fileEngine->error(), d->fileEngine->errorString());Executed by:
| 24 | ||||||||||||||||||
| 715 | return address; executed 34289 times by 119 tests: return address;Executed by:
| 34289 | ||||||||||||||||||
| 716 | } | - | ||||||||||||||||||
| 717 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 718 | } | - | ||||||||||||||||||
| 719 | - | |||||||||||||||||||
| 720 | /*! | - | ||||||||||||||||||
| 721 | Unmaps the memory \a address. | - | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | Returns \c true if the unmap succeeds; false otherwise. | - | ||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | \sa map() | - | ||||||||||||||||||
| 726 | */ | - | ||||||||||||||||||
| 727 | bool QFileDevice::unmap(uchar *address) | - | ||||||||||||||||||
| 728 | { | - | ||||||||||||||||||
| 729 | Q_D(QFileDevice); | - | ||||||||||||||||||
| 730 | if (d->engine()
| 0-32814 | ||||||||||||||||||
| 731 | && d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
| 0-32814 | ||||||||||||||||||
| 732 | unsetError(); | - | ||||||||||||||||||
| 733 | bool success = d->fileEngine->unmap(address); | - | ||||||||||||||||||
| 734 | if (!success)
| 8-32806 | ||||||||||||||||||
| 735 | d->setError(d->fileEngine->error(), d->fileEngine->errorString()); executed 8 times by 1 test: d->setError(d->fileEngine->error(), d->fileEngine->errorString());Executed by:
| 8 | ||||||||||||||||||
| 736 | return success; executed 32814 times by 2 tests: return success;Executed by:
| 32814 | ||||||||||||||||||
| 737 | } | - | ||||||||||||||||||
| 738 | d->setError(PermissionsError, tr("No file engine available or engine does not support UnMapExtension")); | - | ||||||||||||||||||
| 739 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 740 | } | - | ||||||||||||||||||
| 741 | - | |||||||||||||||||||
| 742 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |