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