io/qfile.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qplatformdefs.h" -
43#include "qdebug.h" -
44#include "qfile.h" -
45#include "qfsfileengine_p.h" -
46#include "qtemporaryfile.h" -
47#include "qlist.h" -
48#include "qfileinfo.h" -
49#include "private/qiodevice_p.h" -
50#include "private/qfile_p.h" -
51#include "private/qfilesystemengine_p.h" -
52#include "private/qsystemerror_p.h" -
53#if defined(QT_BUILD_CORE_LIB) -
54# include "qcoreapplication.h" -
55#endif -
56 -
57#ifdef QT_NO_QOBJECT -
58#define tr(X) QString::fromLatin1(X) -
59#endif -
60 -
61QT_BEGIN_NAMESPACE -
62 -
63//************* QFilePrivate -
64QFilePrivate::QFilePrivate() -
65{ -
66} -
67 -
68QFilePrivate::~QFilePrivate() -
69{ -
70} -
71 -
72bool -
73QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags) -
74{ -
75#ifdef QT_NO_FSFILEENGINE -
76 Q_UNUSED(flags); -
77 Q_UNUSED(fd); -
78 return false; -
79#else -
80 delete fileEngine;
executed (the execution status of this line is deduced): delete fileEngine;
-
81 fileEngine = 0;
executed (the execution status of this line is deduced): fileEngine = 0;
-
82 QFSFileEngine *fe = new QFSFileEngine;
executed (the execution status of this line is deduced): QFSFileEngine *fe = new QFSFileEngine;
-
83 fileEngine = fe;
executed (the execution status of this line is deduced): fileEngine = fe;
-
84 return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
executed: return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
Execution Count:30
30
85#endif -
86} -
87 -
88bool -
89QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags) -
90{ -
91#ifdef QT_NO_FSFILEENGINE -
92 Q_UNUSED(flags); -
93 Q_UNUSED(fh); -
94 return false; -
95#else -
96 delete fileEngine;
executed (the execution status of this line is deduced): delete fileEngine;
-
97 fileEngine = 0;
executed (the execution status of this line is deduced): fileEngine = 0;
-
98 QFSFileEngine *fe = new QFSFileEngine;
executed (the execution status of this line is deduced): QFSFileEngine *fe = new QFSFileEngine;
-
99 fileEngine = fe;
executed (the execution status of this line is deduced): fileEngine = fe;
-
100 return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);
executed: return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);
Execution Count:31
31
101#endif -
102} -
103 -
104QAbstractFileEngine *QFilePrivate::engine() const -
105{ -
106 if (!fileEngine)
evaluated: !fileEngine
TRUEFALSE
yes
Evaluation Count:26726
yes
Evaluation Count:197807
26726-197807
107 fileEngine = QAbstractFileEngine::create(fileName);
executed: fileEngine = QAbstractFileEngine::create(fileName);
Execution Count:26726
26726
108 return fileEngine;
executed: return fileEngine;
Execution Count:224533
224533
109} -
110 -
111//************* QFile -
112 -
113/*! -
114 \class QFile -
115 \inmodule QtCore -
116 \brief The QFile class provides an interface for reading from and writing to files. -
117 -
118 \ingroup io -
119 -
120 \reentrant -
121 -
122 QFile is an I/O device for reading and writing text and binary -
123 files and \l{The Qt Resource System}{resources}. A QFile may be -
124 used by itself or, more conveniently, with a QTextStream or -
125 QDataStream. -
126 -
127 The file name is usually passed in the constructor, but it can be -
128 set at any time using setFileName(). QFile expects the file -
129 separator to be '/' regardless of operating system. The use of -
130 other separators (e.g., '\\') is not supported. -
131 -
132 You can check for a file's existence using exists(), and remove a -
133 file using remove(). (More advanced file system related operations -
134 are provided by QFileInfo and QDir.) -
135 -
136 The file is opened with open(), closed with close(), and flushed -
137 with flush(). Data is usually read and written using QDataStream -
138 or QTextStream, but you can also call the QIODevice-inherited -
139 functions read(), readLine(), readAll(), write(). QFile also -
140 inherits getChar(), putChar(), and ungetChar(), which work one -
141 character at a time. -
142 -
143 The size of the file is returned by size(). You can get the -
144 current file position using pos(), or move to a new file position -
145 using seek(). If you've reached the end of the file, atEnd() -
146 returns true. -
147 -
148 \section1 Reading Files Directly -
149 -
150 The following example reads a text file line by line: -
151 -
152 \snippet file/file.cpp 0 -
153 -
154 The QIODevice::Text flag passed to open() tells Qt to convert -
155 Windows-style line terminators ("\\r\\n") into C++-style -
156 terminators ("\\n"). By default, QFile assumes binary, i.e. it -
157 doesn't perform any conversion on the bytes stored in the file. -
158 -
159 \section1 Using Streams to Read Files -
160 -
161 The next example uses QTextStream to read a text file -
162 line by line: -
163 -
164 \snippet file/file.cpp 1 -
165 -
166 QTextStream takes care of converting the 8-bit data stored on -
167 disk into a 16-bit Unicode QString. By default, it assumes that -
168 the user system's local 8-bit encoding is used (e.g., UTF-8 -
169 on most unix based operating systems; see QTextCodec::codecForLocale() for -
170 details). This can be changed using setCodec(). -
171 -
172 To write text, we can use operator<<(), which is overloaded to -
173 take a QTextStream on the left and various data types (including -
174 QString) on the right: -
175 -
176 \snippet file/file.cpp 2 -
177 -
178 QDataStream is similar, in that you can use operator<<() to write -
179 data and operator>>() to read it back. See the class -
180 documentation for details. -
181 -
182 When you use QFile, QFileInfo, and QDir to access the file system -
183 with Qt, you can use Unicode file names. On Unix, these file -
184 names are converted to an 8-bit encoding. If you want to use -
185 standard C++ APIs (\c <cstdio> or \c <iostream>) or -
186 platform-specific APIs to access files instead of QFile, you can -
187 use the encodeName() and decodeName() functions to convert -
188 between Unicode file names and 8-bit file names. -
189 -
190 On Unix, there are some special system files (e.g. in \c /proc) for which -
191 size() will always return 0, yet you may still be able to read more data -
192 from such a file; the data is generated in direct response to you calling -
193 read(). In this case, however, you cannot use atEnd() to determine if -
194 there is more data to read (since atEnd() will return true for a file that -
195 claims to have size 0). Instead, you should either call readAll(), or call -
196 read() or readLine() repeatedly until no more data can be read. The next -
197 example uses QTextStream to read \c /proc/modules line by line: -
198 -
199 \snippet file/file.cpp 3 -
200 -
201 \section1 Signals -
202 -
203 Unlike other QIODevice implementations, such as QTcpSocket, QFile does not -
204 emit the aboutToClose(), bytesWritten(), or readyRead() signals. This -
205 implementation detail means that QFile is not suitable for reading and -
206 writing certain types of files, such as device files on Unix platforms. -
207 -
208 \section1 Platform Specific Issues -
209 -
210 File permissions are handled differently on Linux/Mac OS X and -
211 Windows. In a non \l{QIODevice::isWritable()}{writable} -
212 directory on Linux, files cannot be created. This is not always -
213 the case on Windows, where, for instance, the 'My Documents' -
214 directory usually is not writable, but it is still possible to -
215 create files in it. -
216 -
217 \sa QTextStream, QDataStream, QFileInfo, QDir, {The Qt Resource System} -
218*/ -
219 -
220#ifdef QT_NO_QOBJECT -
221QFile::QFile() -
222 : QFileDevice(*new QFilePrivate) -
223{ -
224} -
225QFile::QFile(const QString &name) -
226 : QFileDevice(*new QFilePrivate) -
227{ -
228 d_func()->fileName = name; -
229} -
230QFile::QFile(QFilePrivate &dd) -
231 : QFileDevice(dd) -
232{ -
233} -
234#else -
235/*! -
236 \internal -
237*/ -
238QFile::QFile() -
239 : QFileDevice(*new QFilePrivate, 0) -
240{ -
241}
executed: }
Execution Count:157
157
242/*! -
243 Constructs a new file object with the given \a parent. -
244*/ -
245QFile::QFile(QObject *parent) -
246 : QFileDevice(*new QFilePrivate, parent) -
247{ -
248}
executed: }
Execution Count:1
1
249/*! -
250 Constructs a new file object to represent the file with the given \a name. -
251*/ -
252QFile::QFile(const QString &name) -
253 : QFileDevice(*new QFilePrivate, 0) -
254{ -
255 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
256 d->fileName = name;
executed (the execution status of this line is deduced): d->fileName = name;
-
257}
executed: }
Execution Count:25376
25376
258/*! -
259 Constructs a new file object with the given \a parent to represent the -
260 file with the specified \a name. -
261*/ -
262QFile::QFile(const QString &name, QObject *parent) -
263 : QFileDevice(*new QFilePrivate, parent) -
264{ -
265 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
266 d->fileName = name;
executed (the execution status of this line is deduced): d->fileName = name;
-
267}
executed: }
Execution Count:1
1
268/*! -
269 \internal -
270*/ -
271QFile::QFile(QFilePrivate &dd, QObject *parent) -
272 : QFileDevice(dd, parent) -
273{ -
274}
executed: }
Execution Count:1485
1485
275#endif -
276 -
277/*! -
278 Destroys the file object, closing it if necessary. -
279*/ -
280QFile::~QFile() -
281{ -
282} -
283 -
284/*! -
285 Returns the name set by setFileName() or to the QFile -
286 constructors. -
287 -
288 \sa setFileName(), QFileInfo::fileName() -
289*/ -
290QString QFile::fileName() const -
291{ -
292 Q_D(const QFile);
executed (the execution status of this line is deduced): const QFilePrivate * const d = d_func();
-
293 return d->engine()->fileName(QAbstractFileEngine::DefaultName);
executed: return d->engine()->fileName(QAbstractFileEngine::DefaultName);
Execution Count:3159
3159
294} -
295 -
296/*! -
297 Sets the \a name of the file. The name can have no path, a -
298 relative path, or an absolute path. -
299 -
300 Do not call this function if the file has already been opened. -
301 -
302 If the file name has no path or a relative path, the path used -
303 will be the application's current directory path -
304 \e{at the time of the open()} call. -
305 -
306 Example: -
307 \snippet code/src_corelib_io_qfile.cpp 0 -
308 -
309 Note that the directory separator "/" works for all operating -
310 systems supported by Qt. -
311 -
312 \sa fileName(), QFileInfo, QDir -
313*/ -
314void -
315QFile::setFileName(const QString &name) -
316{ -
317 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
318 if (isOpen()) {
partially evaluated: isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1399
0-1399
319 qWarning("QFile::setFileName: File (%s) is already opened",
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 319, __PRETTY_FUNCTION__).warning("QFile::setFileName: File (%s) is already opened",
-
320 qPrintable(fileName()));
never executed (the execution status of this line is deduced): QString(fileName()).toLocal8Bit().constData());
-
321 close();
never executed (the execution status of this line is deduced): close();
-
322 }
never executed: }
0
323 if(d->fileEngine) { //get a new file engine later
evaluated: d->fileEngine
TRUEFALSE
yes
Evaluation Count:1291
yes
Evaluation Count:108
108-1291
324 delete d->fileEngine;
executed (the execution status of this line is deduced): delete d->fileEngine;
-
325 d->fileEngine = 0;
executed (the execution status of this line is deduced): d->fileEngine = 0;
-
326 }
executed: }
Execution Count:1291
1291
327 d->fileName = name;
executed (the execution status of this line is deduced): d->fileName = name;
-
328}
executed: }
Execution Count:1399
1399
329 -
330/*! -
331 \fn QString QFile::decodeName(const char *localFileName) -
332 -
333 \overload -
334 -
335 Returns the Unicode version of the given \a localFileName. See -
336 encodeName() for details. -
337*/ -
338 -
339/*! -
340 \fn QByteArray QFile::encodeName(const QString &fileName) -
341 -
342 Converts \a fileName to the local 8-bit -
343 encoding determined by the user's locale. This is sufficient for -
344 file names that the user chooses. File names hard-coded into the -
345 application should only use 7-bit ASCII filename characters. -
346 -
347 \sa decodeName() -
348*/ -
349 -
350/*! -
351 \typedef QFile::EncoderFn -
352 \obsolete -
353 -
354 This is a typedef for a pointer to a function with the following -
355 signature: -
356 -
357 \snippet code/src_corelib_io_qfile.cpp 1 -
358 -
359 \sa setEncodingFunction(), encodeName() -
360*/ -
361 -
362/*! -
363 \fn QString QFile::decodeName(const QByteArray &localFileName) -
364 -
365 This does the reverse of QFile::encodeName() using \a localFileName. -
366 -
367 \sa encodeName() -
368*/ -
369 -
370/*! -
371 \fn void QFile::setEncodingFunction(EncoderFn function) -
372 \obsolete -
373 -
374 This function does nothing. It is provided for compatibility with Qt 4 code -
375 that attempted to set a different encoding function for file names. That -
376 feature is flawed and no longer supported in Qt 5. -
377 -
378 \sa encodeName(), setDecodingFunction() -
379*/ -
380 -
381/*! -
382 \typedef QFile::DecoderFn -
383 -
384 This is a typedef for a pointer to a function with the following -
385 signature: -
386 -
387 \snippet code/src_corelib_io_qfile.cpp 2 -
388 -
389 \sa setDecodingFunction() -
390*/ -
391 -
392/*! -
393 \fn void QFile::setDecodingFunction(DecoderFn function) -
394 \obsolete -
395 -
396 This function does nothing. It is provided for compatibility with Qt 4 code -
397 that attempted to set a different decoding function for file names. That -
398 feature is flawed and no longer supported in Qt 5. -
399 -
400 \sa setEncodingFunction(), decodeName() -
401*/ -
402 -
403/*! -
404 \overload -
405 -
406 Returns true if the file specified by fileName() exists; otherwise -
407 returns false. -
408 -
409 \sa fileName(), setFileName() -
410*/ -
411 -
412bool -
413QFile::exists() const -
414{ -
415 Q_D(const QFile);
executed (the execution status of this line is deduced): const QFilePrivate * const d = d_func();
-
416 // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update -
417 return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask
executed: return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
Execution Count:4952
4952
418 | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
executed: return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
Execution Count:4952
4952
419} -
420 -
421/*! -
422 Returns true if the file specified by \a fileName exists; otherwise -
423 returns false. -
424*/ -
425 -
426bool -
427QFile::exists(const QString &fileName) -
428{ -
429 return QFileInfo(fileName).exists();
executed: return QFileInfo(fileName).exists();
Execution Count:3184
3184
430} -
431 -
432/*! -
433 \fn QString QFile::symLinkTarget() const -
434 \since 4.2 -
435 \overload -
436 -
437 Returns the absolute path of the file or directory a symlink (or shortcut -
438 on Windows) points to, or a an empty string if the object isn't a symbolic -
439 link. -
440 -
441 This name may not represent an existing file; it is only a string. -
442 QFile::exists() returns true if the symlink points to an existing file. -
443 -
444 \sa fileName(), setFileName() -
445*/ -
446 -
447/*! -
448 \obsolete -
449 -
450 Use symLinkTarget() instead. -
451*/ -
452QString -
453QFile::readLink() const -
454{ -
455 Q_D(const QFile);
executed (the execution status of this line is deduced): const QFilePrivate * const d = d_func();
-
456 return d->engine()->fileName(QAbstractFileEngine::LinkName);
executed: return d->engine()->fileName(QAbstractFileEngine::LinkName);
Execution Count:2
2
457} -
458 -
459/*! -
460 \fn static QString QFile::symLinkTarget(const QString &fileName) -
461 \since 4.2 -
462 -
463 Returns the absolute path of the file or directory referred to by the -
464 symlink (or shortcut on Windows) specified by \a fileName, or returns an -
465 empty string if the \a fileName does not correspond to a symbolic link. -
466 -
467 This name may not represent an existing file; it is only a string. -
468 QFile::exists() returns true if the symlink points to an existing file. -
469*/ -
470 -
471/*! -
472 \obsolete -
473 -
474 Use symLinkTarget() instead. -
475*/ -
476QString -
477QFile::readLink(const QString &fileName) -
478{ -
479 return QFileInfo(fileName).readLink();
executed: return QFileInfo(fileName).readLink();
Execution Count:1
1
480} -
481 -
482/*! -
483 Removes the file specified by fileName(). Returns true if successful; -
484 otherwise returns false. -
485 -
486 The file is closed before it is removed. -
487 -
488 \sa setFileName() -
489*/ -
490 -
491bool -
492QFile::remove() -
493{ -
494 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
495 if (d->fileName.isEmpty()) {
partially evaluated: d->fileName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5495
0-5495
496 qWarning("QFile::remove: Empty or null file name");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 496, __PRETTY_FUNCTION__).warning("QFile::remove: Empty or null file name");
-
497 return false;
never executed: return false;
0
498 } -
499 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
500 close();
executed (the execution status of this line is deduced): close();
-
501 if(error() == QFile::NoError) {
partially evaluated: error() == QFile::NoError
TRUEFALSE
yes
Evaluation Count:5495
no
Evaluation Count:0
0-5495
502 if (d->engine()->remove()) {
evaluated: d->engine()->remove()
TRUEFALSE
yes
Evaluation Count:4879
yes
Evaluation Count:616
616-4879
503 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
504 return true;
executed: return true;
Execution Count:4879
4879
505 } -
506 d->setError(QFile::RemoveError, d->fileEngine->errorString());
executed (the execution status of this line is deduced): d->setError(QFile::RemoveError, d->fileEngine->errorString());
-
507 }
executed: }
Execution Count:616
616
508 return false;
executed: return false;
Execution Count:616
616
509} -
510 -
511/*! -
512 \overload -
513 -
514 Removes the file specified by the \a fileName given. -
515 -
516 Returns true if successful; otherwise returns false. -
517 -
518 \sa remove() -
519*/ -
520 -
521bool -
522QFile::remove(const QString &fileName) -
523{ -
524 return QFile(fileName).remove();
executed: return QFile(fileName).remove();
Execution Count:4325
4325
525} -
526 -
527/*! -
528 Renames the file currently specified by fileName() to \a newName. -
529 Returns true if successful; otherwise returns false. -
530 -
531 If a file with the name \a newName already exists, rename() returns false -
532 (i.e., QFile will not overwrite it). -
533 -
534 The file is closed before it is renamed. -
535 -
536 If the rename operation fails, Qt will attempt to copy this file's -
537 contents to \a newName, and then remove this file, keeping only -
538 \a newName. If that copy operation fails or this file can't be removed, -
539 the destination file \a newName is removed to restore the old state. -
540 -
541 \sa setFileName() -
542*/ -
543 -
544bool -
545QFile::rename(const QString &newName) -
546{ -
547 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
548 if (d->fileName.isEmpty()) {
partially evaluated: d->fileName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:211
0-211
549 qWarning("QFile::rename: Empty or null file name");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 549, __PRETTY_FUNCTION__).warning("QFile::rename: Empty or null file name");
-
550 return false;
never executed: return false;
0
551 } -
552 if (d->fileName == newName) {
evaluated: d->fileName == newName
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:210
1-210
553 d->setError(QFile::RenameError, tr("Destination file is the same file."));
executed (the execution status of this line is deduced): d->setError(QFile::RenameError, tr("Destination file is the same file."));
-
554 return false;
executed: return false;
Execution Count:1
1
555 } -
556 if (!exists()) {
evaluated: !exists()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:208
2-208
557 d->setError(QFile::RenameError, tr("Source file does not exist."));
executed (the execution status of this line is deduced): d->setError(QFile::RenameError, tr("Source file does not exist."));
-
558 return false;
executed: return false;
Execution Count:2
2
559 } -
560 // If the file exists and it is a case-changing rename ("foo" -> "Foo"), -
561 // compare Ids to make sure it really is a different file. -
562 if (QFile::exists(newName)
evaluated: QFile::exists(newName)
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:204
4-204
563 && (d->fileName.compare(newName, Qt::CaseInsensitive)
partially evaluated: d->fileName.compare(newName, Qt::CaseInsensitive)
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
564 || QFileSystemEngine::id(QFileSystemEntry(d->fileName)) != QFileSystemEngine::id(QFileSystemEntry(newName)))) {
never evaluated: QFileSystemEngine::id(QFileSystemEntry(d->fileName)) != QFileSystemEngine::id(QFileSystemEntry(newName))
0
565 // ### Race condition. If a file is moved in after this, it /will/ be -
566 // overwritten. On Unix, the proper solution is to use hardlinks: -
567 // return ::link(old, new) && ::remove(old); -
568 d->setError(QFile::RenameError, tr("Destination file exists"));
executed (the execution status of this line is deduced): d->setError(QFile::RenameError, tr("Destination file exists"));
-
569 return false;
executed: return false;
Execution Count:4
4
570 } -
571 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
572 close();
executed (the execution status of this line is deduced): close();
-
573 if(error() == QFile::NoError) {
partially evaluated: error() == QFile::NoError
TRUEFALSE
yes
Evaluation Count:204
no
Evaluation Count:0
0-204
574 if (d->engine()->rename(newName)) {
evaluated: d->engine()->rename(newName)
TRUEFALSE
yes
Evaluation Count:200
yes
Evaluation Count:4
4-200
575 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
576 // engine was able to handle the new name so we just reset it -
577 d->fileEngine->setFileName(newName);
executed (the execution status of this line is deduced): d->fileEngine->setFileName(newName);
-
578 d->fileName = newName;
executed (the execution status of this line is deduced): d->fileName = newName;
-
579 return true;
executed: return true;
Execution Count:200
200
580 } -
581 -
582 if (isSequential()) {
partially evaluated: isSequential()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
583 d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy"));
never executed (the execution status of this line is deduced): d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy"));
-
584 return false;
never executed: return false;
0
585 } -
586 -
587 QFile out(newName);
executed (the execution status of this line is deduced): QFile out(newName);
-
588 if (open(QIODevice::ReadOnly)) {
partially evaluated: open(QIODevice::ReadOnly)
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
589 if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
evaluated: out.open(QIODevice::WriteOnly | QIODevice::Truncate)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
590 bool error = false;
executed (the execution status of this line is deduced): bool error = false;
-
591 char block[4096];
executed (the execution status of this line is deduced): char block[4096];
-
592 qint64 bytes;
executed (the execution status of this line is deduced): qint64 bytes;
-
593 while ((bytes = read(block, sizeof(block))) > 0) {
evaluated: (bytes = read(block, sizeof(block))) > 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
594 if (bytes != out.write(block, bytes)) {
partially evaluated: bytes != out.write(block, bytes)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
595 d->setError(QFile::RenameError, out.errorString());
never executed (the execution status of this line is deduced): d->setError(QFile::RenameError, out.errorString());
-
596 error = true;
never executed (the execution status of this line is deduced): error = true;
-
597 break;
never executed: break;
0
598 } -
599 }
executed: }
Execution Count:1
1
600 if (bytes == -1) {
partially evaluated: bytes == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
601 d->setError(QFile::RenameError, errorString());
never executed (the execution status of this line is deduced): d->setError(QFile::RenameError, errorString());
-
602 error = true;
never executed (the execution status of this line is deduced): error = true;
-
603 }
never executed: }
0
604 if(!error) {
partially evaluated: !error
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
605 if (!remove()) {
partially evaluated: !remove()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
606 d->setError(QFile::RenameError, tr("Cannot remove source file"));
executed (the execution status of this line is deduced): d->setError(QFile::RenameError, tr("Cannot remove source file"));
-
607 error = true;
executed (the execution status of this line is deduced): error = true;
-
608 }
executed: }
Execution Count:1
1
609 }
executed: }
Execution Count:1
1
610 if (error) {
partially evaluated: error
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
611 out.remove();
executed (the execution status of this line is deduced): out.remove();
-
612 } else {
executed: }
Execution Count:1
1
613 d->fileEngine->setFileName(newName);
never executed (the execution status of this line is deduced): d->fileEngine->setFileName(newName);
-
614 setPermissions(permissions());
never executed (the execution status of this line is deduced): setPermissions(permissions());
-
615 unsetError();
never executed (the execution status of this line is deduced): unsetError();
-
616 setFileName(newName);
never executed (the execution status of this line is deduced): setFileName(newName);
-
617 }
never executed: }
0
618 close();
executed (the execution status of this line is deduced): close();
-
619 return !error;
executed: return !error;
Execution Count:1
1
620 } -
621 close();
executed (the execution status of this line is deduced): close();
-
622 }
executed: }
Execution Count:3
3
623 d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString());
executed (the execution status of this line is deduced): d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString());
-
624 }
executed: }
Execution Count:3
3
625 return false;
executed: return false;
Execution Count:3
3
626} -
627 -
628/*! -
629 \overload -
630 -
631 Renames the file \a oldName to \a newName. Returns true if -
632 successful; otherwise returns false. -
633 -
634 If a file with the name \a newName already exists, rename() returns false -
635 (i.e., QFile will not overwrite it). -
636 -
637 \sa rename() -
638*/ -
639 -
640bool -
641QFile::rename(const QString &oldName, const QString &newName) -
642{ -
643 return QFile(oldName).rename(newName);
executed: return QFile(oldName).rename(newName);
Execution Count:7
7
644} -
645 -
646/*! -
647 -
648 Creates a link named \a linkName that points to the file currently specified by -
649 fileName(). What a link is depends on the underlying filesystem (be it a -
650 shortcut on Windows or a symbolic link on Unix). Returns true if successful; -
651 otherwise returns false. -
652 -
653 This function will not overwrite an already existing entity in the file system; -
654 in this case, \c link() will return false and set \l{QFile::}{error()} to -
655 return \l{QFile::}{RenameError}. -
656 -
657 \note To create a valid link on Windows, \a linkName must have a \c{.lnk} file extension. -
658 -
659 \sa setFileName() -
660*/ -
661 -
662bool -
663QFile::link(const QString &linkName) -
664{ -
665 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
666 if (d->fileName.isEmpty()) {
partially evaluated: d->fileName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:145
0-145
667 qWarning("QFile::link: Empty or null file name");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 667, __PRETTY_FUNCTION__).warning("QFile::link: Empty or null file name");
-
668 return false;
never executed: return false;
0
669 } -
670 QFileInfo fi(linkName);
executed (the execution status of this line is deduced): QFileInfo fi(linkName);
-
671 if (d->engine()->link(fi.absoluteFilePath())) {
partially evaluated: d->engine()->link(fi.absoluteFilePath())
TRUEFALSE
yes
Evaluation Count:145
no
Evaluation Count:0
0-145
672 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
673 return true;
executed: return true;
Execution Count:145
145
674 } -
675 d->setError(QFile::RenameError, d->fileEngine->errorString());
never executed (the execution status of this line is deduced): d->setError(QFile::RenameError, d->fileEngine->errorString());
-
676 return false;
never executed: return false;
0
677} -
678 -
679/*! -
680 \overload -
681 -
682 Creates a link named \a linkName that points to the file \a fileName. What a link is -
683 depends on the underlying filesystem (be it a shortcut on Windows -
684 or a symbolic link on Unix). Returns true if successful; otherwise -
685 returns false. -
686 -
687 \sa link() -
688*/ -
689 -
690bool -
691QFile::link(const QString &fileName, const QString &linkName) -
692{ -
693 return QFile(fileName).link(linkName);
executed: return QFile(fileName).link(linkName);
Execution Count:143
143
694} -
695 -
696/*! -
697 Copies the file currently specified by fileName() to a file called -
698 \a newName. Returns true if successful; otherwise returns false. -
699 -
700 Note that if a file with the name \a newName already exists, -
701 copy() returns false (i.e. QFile will not overwrite it). -
702 -
703 The source file is closed before it is copied. -
704 -
705 \sa setFileName() -
706*/ -
707 -
708bool -
709QFile::copy(const QString &newName) -
710{ -
711 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
712 if (d->fileName.isEmpty()) {
partially evaluated: d->fileName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:101
0-101
713 qWarning("QFile::copy: Empty or null file name");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 713, __PRETTY_FUNCTION__).warning("QFile::copy: Empty or null file name");
-
714 return false;
never executed: return false;
0
715 } -
716 if (QFile(newName).exists()) {
evaluated: QFile(newName).exists()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:98
3-98
717 // ### Race condition. If a file is moved in after this, it /will/ be -
718 // overwritten. On Unix, the proper solution is to use hardlinks: -
719 // return ::link(old, new) && ::remove(old); See also rename(). -
720 d->setError(QFile::CopyError, tr("Destination file exists"));
executed (the execution status of this line is deduced): d->setError(QFile::CopyError, tr("Destination file exists"));
-
721 return false;
executed: return false;
Execution Count:3
3
722 } -
723 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
724 close();
executed (the execution status of this line is deduced): close();
-
725 if(error() == QFile::NoError) {
partially evaluated: error() == QFile::NoError
TRUEFALSE
yes
Evaluation Count:98
no
Evaluation Count:0
0-98
726 if (d->engine()->copy(newName)) {
partially evaluated: d->engine()->copy(newName)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:98
0-98
727 unsetError();
never executed (the execution status of this line is deduced): unsetError();
-
728 return true;
never executed: return true;
0
729 } else { -
730 bool error = false;
executed (the execution status of this line is deduced): bool error = false;
-
731 if(!open(QFile::ReadOnly)) {
evaluated: !open(QFile::ReadOnly)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:97
1-97
732 error = true;
executed (the execution status of this line is deduced): error = true;
-
733 d->setError(QFile::CopyError, tr("Cannot open %1 for input").arg(d->fileName));
executed (the execution status of this line is deduced): d->setError(QFile::CopyError, tr("Cannot open %1 for input").arg(d->fileName));
-
734 } else {
executed: }
Execution Count:1
1
735 QString fileTemplate = QLatin1String("%1/qt_temp.XXXXXX");
executed (the execution status of this line is deduced): QString fileTemplate = QLatin1String("%1/qt_temp.XXXXXX");
-
736#ifdef QT_NO_TEMPORARYFILE -
737 QFile out(fileTemplate.arg(QFileInfo(newName).path())); -
738 if (!out.open(QIODevice::ReadWrite)) -
739 error = true; -
740#else -
741 QTemporaryFile out(fileTemplate.arg(QFileInfo(newName).path()));
executed (the execution status of this line is deduced): QTemporaryFile out(fileTemplate.arg(QFileInfo(newName).path()));
-
742 if (!out.open()) {
partially evaluated: !out.open()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:97
0-97
743 out.setFileTemplate(fileTemplate.arg(QDir::tempPath()));
never executed (the execution status of this line is deduced): out.setFileTemplate(fileTemplate.arg(QDir::tempPath()));
-
744 if (!out.open())
never evaluated: !out.open()
0
745 error = true;
never executed: error = true;
0
746 }
never executed: }
0
747#endif -
748 if (error) {
partially evaluated: error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:97
0-97
749 out.close();
never executed (the execution status of this line is deduced): out.close();
-
750 close();
never executed (the execution status of this line is deduced): close();
-
751 d->setError(QFile::CopyError, tr("Cannot open for output"));
never executed (the execution status of this line is deduced): d->setError(QFile::CopyError, tr("Cannot open for output"));
-
752 } else {
never executed: }
0
753 char block[4096];
executed (the execution status of this line is deduced): char block[4096];
-
754 qint64 totalRead = 0;
executed (the execution status of this line is deduced): qint64 totalRead = 0;
-
755 while(!atEnd()) {
evaluated: !atEnd()
TRUEFALSE
yes
Evaluation Count:771
yes
Evaluation Count:97
97-771
756 qint64 in = read(block, sizeof(block));
executed (the execution status of this line is deduced): qint64 in = read(block, sizeof(block));
-
757 if (in <= 0)
partially evaluated: in <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:771
0-771
758 break;
never executed: break;
0
759 totalRead += in;
executed (the execution status of this line is deduced): totalRead += in;
-
760 if(in != out.write(block, in)) {
partially evaluated: in != out.write(block, in)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:771
0-771
761 close();
never executed (the execution status of this line is deduced): close();
-
762 d->setError(QFile::CopyError, tr("Failure to write block"));
never executed (the execution status of this line is deduced): d->setError(QFile::CopyError, tr("Failure to write block"));
-
763 error = true;
never executed (the execution status of this line is deduced): error = true;
-
764 break;
never executed: break;
0
765 } -
766 }
executed: }
Execution Count:771
771
767 -
768 if (totalRead != size()) {
partially evaluated: totalRead != size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:97
0-97
769 // Unable to read from the source. The error string is -
770 // already set from read(). -
771 error = true;
never executed (the execution status of this line is deduced): error = true;
-
772 }
never executed: }
0
773 if (!error && !out.rename(newName)) {
partially evaluated: !error
TRUEFALSE
yes
Evaluation Count:97
no
Evaluation Count:0
partially evaluated: !out.rename(newName)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:97
0-97
774 error = true;
never executed (the execution status of this line is deduced): error = true;
-
775 close();
never executed (the execution status of this line is deduced): close();
-
776 d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName));
never executed (the execution status of this line is deduced): d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName));
-
777 }
never executed: }
0
778#ifdef QT_NO_TEMPORARYFILE -
779 if (error) -
780 out.remove(); -
781#else -
782 if (!error)
partially evaluated: !error
TRUEFALSE
yes
Evaluation Count:97
no
Evaluation Count:0
0-97
783 out.setAutoRemove(false);
executed: out.setAutoRemove(false);
Execution Count:97
97
784#endif -
785 }
executed: }
Execution Count:97
97
786 } -
787 if(!error) {
evaluated: !error
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:1
1-97
788 QFile::setPermissions(newName, permissions());
executed (the execution status of this line is deduced): QFile::setPermissions(newName, permissions());
-
789 close();
executed (the execution status of this line is deduced): close();
-
790 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
791 return true;
executed: return true;
Execution Count:97
97
792 } -
793 }
executed: }
Execution Count:1
1
794 } -
795 return false;
executed: return false;
Execution Count:1
1
796} -
797 -
798/*! -
799 \overload -
800 -
801 Copies the file \a fileName to \a newName. Returns true if successful; -
802 otherwise returns false. -
803 -
804 If a file with the name \a newName already exists, copy() returns false -
805 (i.e., QFile will not overwrite it). -
806 -
807 \sa rename() -
808*/ -
809 -
810bool -
811QFile::copy(const QString &fileName, const QString &newName) -
812{ -
813 return QFile(fileName).copy(newName);
executed: return QFile(fileName).copy(newName);
Execution Count:92
92
814} -
815 -
816/*! -
817 Opens the file using OpenMode \a mode, returning true if successful; -
818 otherwise false. -
819 -
820 The \a mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or -
821 QIODevice::ReadWrite. It may also have additional flags, such as -
822 QIODevice::Text and QIODevice::Unbuffered. -
823 -
824 \note In \l{QIODevice::}{WriteOnly} or \l{QIODevice::}{ReadWrite} -
825 mode, if the relevant file does not already exist, this function -
826 will try to create a new file before opening it. -
827 -
828 \sa QIODevice::OpenMode, setFileName() -
829*/ -
830bool QFile::open(OpenMode mode) -
831{ -
832 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
833 if (isOpen()) {
partially evaluated: isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21302
0-21302
834 qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 834, __PRETTY_FUNCTION__).warning("QFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData());
-
835 return false;
never executed: return false;
0
836 } -
837 if (mode & Append)
evaluated: mode & Append
TRUEFALSE
yes
Evaluation Count:248
yes
Evaluation Count:21054
248-21054
838 mode |= WriteOnly;
executed: mode |= WriteOnly;
Execution Count:248
248
839 -
840 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
841 if ((mode & (ReadOnly | WriteOnly)) == 0) {
partially evaluated: (mode & (ReadOnly | WriteOnly)) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21302
0-21302
842 qWarning("QIODevice::open: File access not specified");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 842, __PRETTY_FUNCTION__).warning("QIODevice::open: File access not specified");
-
843 return false;
never executed: return false;
0
844 } -
845 -
846 // QIODevice provides the buffering, so there's no need to request it from the file engine. -
847 if (d->engine()->open(mode | QIODevice::Unbuffered)) {
evaluated: d->engine()->open(mode | QIODevice::Unbuffered)
TRUEFALSE
yes
Evaluation Count:18007
yes
Evaluation Count:3296
3296-18007
848 QIODevice::open(mode);
executed (the execution status of this line is deduced): QIODevice::open(mode);
-
849 if (mode & Append)
evaluated: mode & Append
TRUEFALSE
yes
Evaluation Count:247
yes
Evaluation Count:17759
247-17759
850 seek(size());
executed: seek(size());
Execution Count:247
247
851 return true;
executed: return true;
Execution Count:18006
18006
852 } -
853 QFile::FileError err = d->fileEngine->error();
executed (the execution status of this line is deduced): QFile::FileError err = d->fileEngine->error();
-
854 if(err == QFile::UnspecifiedError)
evaluated: err == QFile::UnspecifiedError
TRUEFALSE
yes
Evaluation Count:204
yes
Evaluation Count:3092
204-3092
855 err = QFile::OpenError;
executed: err = QFile::OpenError;
Execution Count:204
204
856 d->setError(err, d->fileEngine->errorString());
executed (the execution status of this line is deduced): d->setError(err, d->fileEngine->errorString());
-
857 return false;
executed: return false;
Execution Count:3296
3296
858} -
859 -
860/*! -
861 \overload -
862 -
863 Opens the existing file handle \a fh in the given \a mode. -
864 \a handleFlags may be used to specify additional options. -
865 Returns true if successful; otherwise returns false. -
866 -
867 Example: -
868 \snippet code/src_corelib_io_qfile.cpp 3 -
869 -
870 When a QFile is opened using this function, behaviour of close() is -
871 controlled by the AutoCloseHandle flag. -
872 If AutoCloseHandle is specified, and this function succeeds, -
873 then calling close() closes the adopted handle. -
874 Otherwise, close() does not actually close the file, but only flushes it. -
875 -
876 \b{Warning:} -
877 \list 1 -
878 \li If \a fh does not refer to a regular file, e.g., it is \c stdin, -
879 \c stdout, or \c stderr, you may not be able to seek(). size() -
880 returns \c 0 in those cases. See QIODevice::isSequential() for -
881 more information. -
882 \li Since this function opens the file without specifying the file name, -
883 you cannot use this QFile with a QFileInfo. -
884 \endlist -
885 -
886 \note For Windows CE you may not be able to call resize(). -
887 -
888 \sa close() -
889 -
890 \b{Note for the Windows Platform} -
891 -
892 \a fh must be opened in binary mode (i.e., the mode string must contain -
893 'b', as in "rb" or "wb") when accessing files and other random-access -
894 devices. Qt will translate the end-of-line characters if you pass -
895 QIODevice::Text to \a mode. Sequential devices, such as stdin and stdout, -
896 are unaffected by this limitation. -
897 -
898 You need to enable support for console applications in order to use the -
899 stdin, stdout and stderr streams at the console. To do this, add the -
900 following declaration to your application's project file: -
901 -
902 \snippet code/src_corelib_io_qfile.cpp 4 -
903*/ -
904bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags) -
905{ -
906 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
907 if (isOpen()) {
partially evaluated: isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
0-31
908 qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 908, __PRETTY_FUNCTION__).warning("QFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData());
-
909 return false;
never executed: return false;
0
910 } -
911 if (mode & Append)
partially evaluated: mode & Append
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
0-31
912 mode |= WriteOnly;
never executed: mode |= WriteOnly;
0
913 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
914 if ((mode & (ReadOnly | WriteOnly)) == 0) {
partially evaluated: (mode & (ReadOnly | WriteOnly)) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
0-31
915 qWarning("QFile::open: File access not specified");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 915, __PRETTY_FUNCTION__).warning("QFile::open: File access not specified");
-
916 return false;
never executed: return false;
0
917 } -
918 if (d->openExternalFile(mode, fh, handleFlags)) {
partially evaluated: d->openExternalFile(mode, fh, handleFlags)
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
0-31
919 QIODevice::open(mode);
executed (the execution status of this line is deduced): QIODevice::open(mode);
-
920 if (!(mode & Append) && !isSequential()) {
partially evaluated: !(mode & Append)
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
evaluated: !isSequential()
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:4
0-31
921 qint64 pos = (qint64)QT_FTELL(fh);
executed (the execution status of this line is deduced): qint64 pos = (qint64)::ftello64(fh);
-
922 if (pos != -1) {
partially evaluated: pos != -1
TRUEFALSE
yes
Evaluation Count:27
no
Evaluation Count:0
0-27
923 // Skip redundant checks in QFileDevice::seek(). -
924 QIODevice::seek(pos);
executed (the execution status of this line is deduced): QIODevice::seek(pos);
-
925 }
executed: }
Execution Count:27
27
926 }
executed: }
Execution Count:27
27
927 return true;
executed: return true;
Execution Count:31
31
928 } -
929 return false;
never executed: return false;
0
930} -
931 -
932/*! -
933 \overload -
934 -
935 Opens the existing file descriptor \a fd in the given \a mode. -
936 \a handleFlags may be used to specify additional options. -
937 Returns true if successful; otherwise returns false. -
938 -
939 When a QFile is opened using this function, behaviour of close() is -
940 controlled by the AutoCloseHandle flag. -
941 If AutoCloseHandle is specified, and this function succeeds, -
942 then calling close() closes the adopted handle. -
943 Otherwise, close() does not actually close the file, but only flushes it. -
944 -
945 The QFile that is opened using this function is automatically set -
946 to be in raw mode; this means that the file input/output functions -
947 are slow. If you run into performance issues, you should try to -
948 use one of the other open functions. -
949 -
950 \warning If \a fd is not a regular file, e.g, it is 0 (\c stdin), -
951 1 (\c stdout), or 2 (\c stderr), you may not be able to seek(). In -
952 those cases, size() returns \c 0. See QIODevice::isSequential() -
953 for more information. -
954 -
955 \warning For Windows CE you may not be able to call seek(), setSize(), -
956 fileTime(). size() returns \c 0. -
957 -
958 \warning Since this function opens the file without specifying the file name, -
959 you cannot use this QFile with a QFileInfo. -
960 -
961 \sa close() -
962*/ -
963bool QFile::open(int fd, OpenMode mode, FileHandleFlags handleFlags) -
964{ -
965 Q_D(QFile);
executed (the execution status of this line is deduced): QFilePrivate * const d = d_func();
-
966 if (isOpen()) {
partially evaluated: isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:30
0-30
967 qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 967, __PRETTY_FUNCTION__).warning("QFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData());
-
968 return false;
never executed: return false;
0
969 } -
970 if (mode & Append)
partially evaluated: mode & Append
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:30
0-30
971 mode |= WriteOnly;
never executed: mode |= WriteOnly;
0
972 unsetError();
executed (the execution status of this line is deduced): unsetError();
-
973 if ((mode & (ReadOnly | WriteOnly)) == 0) {
partially evaluated: (mode & (ReadOnly | WriteOnly)) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:30
0-30
974 qWarning("QFile::open: File access not specified");
never executed (the execution status of this line is deduced): QMessageLogger("io/qfile.cpp", 974, __PRETTY_FUNCTION__).warning("QFile::open: File access not specified");
-
975 return false;
never executed: return false;
0
976 } -
977 if (d->openExternalFile(mode, fd, handleFlags)) {
partially evaluated: d->openExternalFile(mode, fd, handleFlags)
TRUEFALSE
yes
Evaluation Count:30
no
Evaluation Count:0
0-30
978 QIODevice::open(mode);
executed (the execution status of this line is deduced): QIODevice::open(mode);
-
979 if (!(mode & Append) && !isSequential()) {
partially evaluated: !(mode & Append)
TRUEFALSE
yes
Evaluation Count:30
no
Evaluation Count:0
evaluated: !isSequential()
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:6
0-30
980 qint64 pos = (qint64)QT_LSEEK(fd, QT_OFF_T(0), SEEK_CUR);
executed (the execution status of this line is deduced): qint64 pos = (qint64)::lseek64(fd, off64_t(0), 1);
-
981 if (pos != -1) {
partially evaluated: pos != -1
TRUEFALSE
yes
Evaluation Count:24
no
Evaluation Count:0
0-24
982 // Skip redundant checks in QFileDevice::seek(). -
983 QIODevice::seek(pos);
executed (the execution status of this line is deduced): QIODevice::seek(pos);
-
984 }
executed: }
Execution Count:24
24
985 }
executed: }
Execution Count:24
24
986 return true;
executed: return true;
Execution Count:30
30
987 } -
988 return false;
never executed: return false;
0
989} -
990 -
991/*! -
992 \reimp -
993*/ -
994bool QFile::resize(qint64 sz) -
995{ -
996 return QFileDevice::resize(sz); // for now
executed: return QFileDevice::resize(sz);
Execution Count:773
773
997} -
998 -
999/*! -
1000 \overload -
1001 -
1002 Sets \a fileName to size (in bytes) \a sz. Returns true if the file if -
1003 the resize succeeds; false otherwise. If \a sz is larger than \a -
1004 fileName currently is the new bytes will be set to 0, if \a sz is -
1005 smaller the file is simply truncated. -
1006 -
1007 \sa resize() -
1008*/ -
1009 -
1010bool -
1011QFile::resize(const QString &fileName, qint64 sz) -
1012{ -
1013 return QFile(fileName).resize(sz);
executed: return QFile(fileName).resize(sz);
Execution Count:3
3
1014} -
1015 -
1016/*! -
1017 \reimp -
1018*/ -
1019QFile::Permissions QFile::permissions() const -
1020{ -
1021 return QFileDevice::permissions(); // for now
executed: return QFileDevice::permissions();
Execution Count:226
226
1022} -
1023 -
1024/*! -
1025 \overload -
1026 -
1027 Returns the complete OR-ed together combination of -
1028 QFile::Permission for \a fileName. -
1029*/ -
1030 -
1031QFile::Permissions -
1032QFile::permissions(const QString &fileName) -
1033{ -
1034 return QFile(fileName).permissions();
executed: return QFile(fileName).permissions();
Execution Count:9
9
1035} -
1036 -
1037/*! -
1038 Sets the permissions for the file to the \a permissions specified. -
1039 Returns true if successful, or false if the permissions cannot be -
1040 modified. -
1041 -
1042 \sa permissions(), setFileName() -
1043*/ -
1044 -
1045bool QFile::setPermissions(Permissions permissions) -
1046{ -
1047 return QFileDevice::setPermissions(permissions); // for now
executed: return QFileDevice::setPermissions(permissions);
Execution Count:515
515
1048} -
1049 -
1050/*! -
1051 \overload -
1052 -
1053 Sets the permissions for \a fileName file to \a permissions. -
1054*/ -
1055 -
1056bool -
1057QFile::setPermissions(const QString &fileName, Permissions permissions) -
1058{ -
1059 return QFile(fileName).setPermissions(permissions);
executed: return QFile(fileName).setPermissions(permissions);
Execution Count:119
119
1060} -
1061 -
1062/*! -
1063 \reimp -
1064*/ -
1065qint64 QFile::size() const -
1066{ -
1067 return QFileDevice::size(); // for now
executed: return QFileDevice::size();
Execution Count:123885
123885
1068} -
1069 -
1070QT_END_NAMESPACE -
1071 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial