Line | Source Code | Coverage |
---|
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 "qfsfileengine_p.h" | - |
43 | #include "qfsfileengine_iterator_p.h" | - |
44 | #include "qfilesystemengine_p.h" | - |
45 | #include "qdatetime.h" | - |
46 | #include "qdiriterator.h" | - |
47 | #include "qset.h" | - |
48 | #include <QtCore/qdebug.h> | - |
49 | | - |
50 | #ifndef QT_NO_FSFILEENGINE | - |
51 | | - |
52 | #if !defined(Q_OS_WINCE) | - |
53 | #include <errno.h> | - |
54 | #endif | - |
55 | #if defined(Q_OS_UNIX) | - |
56 | #include "private/qcore_unix_p.h" | - |
57 | #endif | - |
58 | #include <stdio.h> | - |
59 | #include <stdlib.h> | - |
60 | #if defined(Q_OS_MAC) | - |
61 | # include <private/qcore_mac_p.h> | - |
62 | #endif | - |
63 | | - |
64 | QT_BEGIN_NAMESPACE | - |
65 | | - |
66 | #ifdef Q_OS_WIN | - |
67 | # ifndef S_ISREG | - |
68 | # define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) | - |
69 | # endif | - |
70 | # ifndef S_ISCHR | - |
71 | # define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR) | - |
72 | # endif | - |
73 | # ifndef S_ISFIFO | - |
74 | # define S_ISFIFO(x) false | - |
75 | # endif | - |
76 | # ifndef S_ISSOCK | - |
77 | # define S_ISSOCK(x) false | - |
78 | # endif | - |
79 | # ifndef INVALID_FILE_ATTRIBUTES | - |
80 | # define INVALID_FILE_ATTRIBUTES (DWORD (-1)) | - |
81 | # endif | - |
82 | #endif | - |
83 | | - |
84 | /*! \class QFSFileEngine | - |
85 | \inmodule QtCore | - |
86 | \brief The QFSFileEngine class implements Qt's default file engine. | - |
87 | \since 4.1 | - |
88 | \internal | - |
89 | | - |
90 | This class is part of the file engine framework in Qt. If you only want to | - |
91 | access files or directories, use QFile, QFileInfo or QDir instead. | - |
92 | | - |
93 | QFSFileEngine is the default file engine for accessing regular files. It | - |
94 | is provided for convenience; by subclassing this class, you can alter its | - |
95 | behavior slightly, without having to write a complete QAbstractFileEngine | - |
96 | subclass. To install your custom file engine, you must also subclass | - |
97 | QAbstractFileEngineHandler and create an instance of your handler. | - |
98 | | - |
99 | It can also be useful to create a QFSFileEngine object directly if you | - |
100 | need to use the local file system inside QAbstractFileEngine::create(), in | - |
101 | order to avoid recursion (as higher-level classes tend to call | - |
102 | QAbstractFileEngine::create()). | - |
103 | */ | - |
104 | | - |
105 | //**************** QFSFileEnginePrivate | - |
106 | QFSFileEnginePrivate::QFSFileEnginePrivate() : QAbstractFileEnginePrivate() | - |
107 | { | - |
108 | init(); executed (the execution status of this line is deduced): init(); | - |
109 | } executed: } Execution Count:26532 | 26532 |
110 | | - |
111 | /*! | - |
112 | \internal | - |
113 | */ | - |
114 | void QFSFileEnginePrivate::init() | - |
115 | { | - |
116 | is_sequential = 0; executed (the execution status of this line is deduced): is_sequential = 0; | - |
117 | tried_stat = 0; executed (the execution status of this line is deduced): tried_stat = 0; | - |
118 | #if !defined(Q_OS_WINCE) | - |
119 | need_lstat = 1; executed (the execution status of this line is deduced): need_lstat = 1; | - |
120 | is_link = 0; executed (the execution status of this line is deduced): is_link = 0; | - |
121 | #endif | - |
122 | openMode = QIODevice::NotOpen; executed (the execution status of this line is deduced): openMode = QIODevice::NotOpen; | - |
123 | fd = -1; executed (the execution status of this line is deduced): fd = -1; | - |
124 | fh = 0; executed (the execution status of this line is deduced): fh = 0; | - |
125 | lastIOCommand = IOFlushCommand; executed (the execution status of this line is deduced): lastIOCommand = IOFlushCommand; | - |
126 | lastFlushFailed = false; executed (the execution status of this line is deduced): lastFlushFailed = false; | - |
127 | closeFileHandle = false; executed (the execution status of this line is deduced): closeFileHandle = false; | - |
128 | #ifdef Q_OS_WIN | - |
129 | fileAttrib = INVALID_FILE_ATTRIBUTES; | - |
130 | fileHandle = INVALID_HANDLE_VALUE; | - |
131 | mapHandle = INVALID_HANDLE_VALUE; | - |
132 | #ifndef Q_OS_WINCE | - |
133 | cachedFd = -1; | - |
134 | #endif | - |
135 | #endif | - |
136 | } executed: } Execution Count:26732 | 26732 |
137 | | - |
138 | /*! | - |
139 | Constructs a QFSFileEngine for the file name \a file. | - |
140 | */ | - |
141 | QFSFileEngine::QFSFileEngine(const QString &file) | - |
142 | : QAbstractFileEngine(*new QFSFileEnginePrivate) | - |
143 | { | - |
144 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
145 | d->fileEntry = QFileSystemEntry(file); executed (the execution status of this line is deduced): d->fileEntry = QFileSystemEntry(file); | - |
146 | } executed: } Execution Count:24994 | 24994 |
147 | | - |
148 | /*! | - |
149 | Constructs a QFSFileEngine. | - |
150 | */ | - |
151 | QFSFileEngine::QFSFileEngine() : QAbstractFileEngine(*new QFSFileEnginePrivate) | - |
152 | { | - |
153 | } executed: } Execution Count:1539 | 1539 |
154 | | - |
155 | /*! | - |
156 | \internal | - |
157 | */ | - |
158 | QFSFileEngine::QFSFileEngine(QFSFileEnginePrivate &dd) | - |
159 | : QAbstractFileEngine(dd) | - |
160 | { | - |
161 | } | 0 |
162 | | - |
163 | /*! | - |
164 | Destructs the QFSFileEngine. | - |
165 | */ | - |
166 | QFSFileEngine::~QFSFileEngine() | - |
167 | { | - |
168 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
169 | if (d->closeFileHandle) { evaluated: d->closeFileHandle yes Evaluation Count:16052 | yes Evaluation Count:10472 |
| 10472-16052 |
170 | if (d->fh) { partially evaluated: d->fh no Evaluation Count:0 | yes Evaluation Count:16052 |
| 0-16052 |
171 | int ret; never executed (the execution status of this line is deduced): int ret; | - |
172 | do { | - |
173 | ret = fclose(d->fh); never executed (the execution status of this line is deduced): ret = fclose(d->fh); | - |
174 | } while (ret == EOF && errno == EINTR); never executed: } never evaluated: ret == (-1) never evaluated: (*__errno_location ()) == 4 | 0 |
175 | } else if (d->fd != -1) { never executed: } partially evaluated: d->fd != -1 no Evaluation Count:0 | yes Evaluation Count:16052 |
| 0-16052 |
176 | int ret; never executed (the execution status of this line is deduced): int ret; | - |
177 | do { | - |
178 | ret = QT_CLOSE(d->fd); never executed (the execution status of this line is deduced): ret = qt_safe_close(d->fd); | - |
179 | } while (ret == -1 && errno == EINTR); never executed: } never evaluated: ret == -1 never evaluated: (*__errno_location ()) == 4 | 0 |
180 | } | 0 |
181 | } | - |
182 | QList<uchar*> keys = d->maps.keys(); executed (the execution status of this line is deduced): QList<uchar*> keys = d->maps.keys(); | - |
183 | for (int i = 0; i < keys.count(); ++i) evaluated: i < keys.count() yes Evaluation Count:523 | yes Evaluation Count:26524 |
| 523-26524 |
184 | unmap(keys.at(i)); executed: unmap(keys.at(i)); Execution Count:523 | 523 |
185 | } executed: } Execution Count:26524 | 26524 |
186 | | - |
187 | /*! | - |
188 | \reimp | - |
189 | */ | - |
190 | void QFSFileEngine::setFileName(const QString &file) | - |
191 | { | - |
192 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
193 | d->init(); executed (the execution status of this line is deduced): d->init(); | - |
194 | d->fileEntry = QFileSystemEntry(file); executed (the execution status of this line is deduced): d->fileEntry = QFileSystemEntry(file); | - |
195 | } executed: } Execution Count:200 | 200 |
196 | | - |
197 | /*! | - |
198 | \reimp | - |
199 | */ | - |
200 | bool QFSFileEngine::open(QIODevice::OpenMode openMode) | - |
201 | { | - |
202 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
203 | if (d->fileEntry.isEmpty()) { evaluated: d->fileEntry.isEmpty() yes Evaluation Count:3 | yes Evaluation Count:18120 |
| 3-18120 |
204 | qWarning("QFSFileEngine::open: No file name specified"); executed (the execution status of this line is deduced): QMessageLogger("io/qfsfileengine.cpp", 204, __PRETTY_FUNCTION__).warning("QFSFileEngine::open: No file name specified"); | - |
205 | setError(QFile::OpenError, QLatin1String("No file name specified")); executed (the execution status of this line is deduced): setError(QFile::OpenError, QLatin1String("No file name specified")); | - |
206 | return false; executed: return false; Execution Count:3 | 3 |
207 | } | - |
208 | | - |
209 | // Append implies WriteOnly. | - |
210 | if (openMode & QFile::Append) evaluated: openMode & QFile::Append yes Evaluation Count:248 | yes Evaluation Count:17872 |
| 248-17872 |
211 | openMode |= QFile::WriteOnly; executed: openMode |= QFile::WriteOnly; Execution Count:248 | 248 |
212 | | - |
213 | // WriteOnly implies Truncate if neither ReadOnly nor Append are sent. | - |
214 | if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append))) evaluated: (openMode & QFile::WriteOnly) yes Evaluation Count:2571 | yes Evaluation Count:15549 |
evaluated: !(openMode & (QFile::ReadOnly | QFile::Append)) yes Evaluation Count:1273 | yes Evaluation Count:1298 |
| 1273-15549 |
215 | openMode |= QFile::Truncate; executed: openMode |= QFile::Truncate; Execution Count:1273 | 1273 |
216 | | - |
217 | d->openMode = openMode; executed (the execution status of this line is deduced): d->openMode = openMode; | - |
218 | d->lastFlushFailed = false; executed (the execution status of this line is deduced): d->lastFlushFailed = false; | - |
219 | d->tried_stat = 0; executed (the execution status of this line is deduced): d->tried_stat = 0; | - |
220 | d->fh = 0; executed (the execution status of this line is deduced): d->fh = 0; | - |
221 | d->fd = -1; executed (the execution status of this line is deduced): d->fd = -1; | - |
222 | | - |
223 | return d->nativeOpen(openMode); executed: return d->nativeOpen(openMode); Execution Count:18120 | 18120 |
224 | } | - |
225 | | - |
226 | /*! | - |
227 | Opens the file handle \a fh in \a openMode mode. Returns true on | - |
228 | success; otherwise returns false. | - |
229 | */ | - |
230 | bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh) | - |
231 | { | - |
232 | return open(openMode, fh, QFile::DontCloseHandle); never executed: return open(openMode, fh, QFile::DontCloseHandle); | 0 |
233 | } | - |
234 | | - |
235 | bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh, QFile::FileHandleFlags handleFlags) | - |
236 | { | - |
237 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
238 | | - |
239 | // Append implies WriteOnly. | - |
240 | if (openMode & QFile::Append) partially evaluated: openMode & QFile::Append no Evaluation Count:0 | yes Evaluation Count:31 |
| 0-31 |
241 | openMode |= QFile::WriteOnly; never executed: openMode |= QFile::WriteOnly; | 0 |
242 | | - |
243 | // WriteOnly implies Truncate if neither ReadOnly nor Append are sent. | - |
244 | if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append))) evaluated: (openMode & QFile::WriteOnly) yes Evaluation Count:8 | yes Evaluation Count:23 |
evaluated: !(openMode & (QFile::ReadOnly | QFile::Append)) yes Evaluation Count:6 | yes Evaluation Count:2 |
| 2-23 |
245 | openMode |= QFile::Truncate; executed: openMode |= QFile::Truncate; Execution Count:6 | 6 |
246 | | - |
247 | d->openMode = openMode; executed (the execution status of this line is deduced): d->openMode = openMode; | - |
248 | d->lastFlushFailed = false; executed (the execution status of this line is deduced): d->lastFlushFailed = false; | - |
249 | d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle); executed (the execution status of this line is deduced): d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle); | - |
250 | d->fileEntry.clear(); executed (the execution status of this line is deduced): d->fileEntry.clear(); | - |
251 | d->tried_stat = 0; executed (the execution status of this line is deduced): d->tried_stat = 0; | - |
252 | d->fd = -1; executed (the execution status of this line is deduced): d->fd = -1; | - |
253 | | - |
254 | return d->openFh(openMode, fh); executed: return d->openFh(openMode, fh); Execution Count:31 | 31 |
255 | } | - |
256 | | - |
257 | /*! | - |
258 | Opens the file handle \a fh using the open mode \a flags. | - |
259 | */ | - |
260 | bool QFSFileEnginePrivate::openFh(QIODevice::OpenMode openMode, FILE *fh) | - |
261 | { | - |
262 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
263 | this->fh = fh; executed (the execution status of this line is deduced): this->fh = fh; | - |
264 | fd = -1; executed (the execution status of this line is deduced): fd = -1; | - |
265 | | - |
266 | // Seek to the end when in Append mode. | - |
267 | if (openMode & QIODevice::Append) { partially evaluated: openMode & QIODevice::Append no Evaluation Count:0 | yes Evaluation Count:31 |
| 0-31 |
268 | int ret; never executed (the execution status of this line is deduced): int ret; | - |
269 | do { | - |
270 | ret = QT_FSEEK(fh, 0, SEEK_END); never executed (the execution status of this line is deduced): ret = ::fseeko64(fh, 0, 2); | - |
271 | } while (ret != 0 && errno == EINTR); never executed: } never evaluated: ret != 0 never evaluated: (*__errno_location ()) == 4 | 0 |
272 | | - |
273 | if (ret != 0) { never evaluated: ret != 0 | 0 |
274 | q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, never executed (the execution status of this line is deduced): q->setError((*__errno_location ()) == 24 ? QFile::ResourceError : QFile::OpenError, | - |
275 | qt_error_string(int(errno))); never executed (the execution status of this line is deduced): qt_error_string(int((*__errno_location ())))); | - |
276 | | - |
277 | this->openMode = QIODevice::NotOpen; never executed (the execution status of this line is deduced): this->openMode = QIODevice::NotOpen; | - |
278 | this->fh = 0; never executed (the execution status of this line is deduced): this->fh = 0; | - |
279 | | - |
280 | return false; never executed: return false; | 0 |
281 | } | - |
282 | } | 0 |
283 | | - |
284 | return true; executed: return true; Execution Count:31 | 31 |
285 | } | - |
286 | | - |
287 | /*! | - |
288 | Opens the file descriptor \a fd in \a openMode mode. Returns true | - |
289 | on success; otherwise returns false. | - |
290 | */ | - |
291 | bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd) | - |
292 | { | - |
293 | return open(openMode, fd, QFile::DontCloseHandle); never executed: return open(openMode, fd, QFile::DontCloseHandle); | 0 |
294 | } | - |
295 | | - |
296 | bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd, QFile::FileHandleFlags handleFlags) | - |
297 | { | - |
298 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
299 | | - |
300 | // Append implies WriteOnly. | - |
301 | if (openMode & QFile::Append) partially evaluated: openMode & QFile::Append no Evaluation Count:0 | yes Evaluation Count:30 |
| 0-30 |
302 | openMode |= QFile::WriteOnly; never executed: openMode |= QFile::WriteOnly; | 0 |
303 | | - |
304 | // WriteOnly implies Truncate if neither ReadOnly nor Append are sent. | - |
305 | if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append))) evaluated: (openMode & QFile::WriteOnly) yes Evaluation Count:5 | yes Evaluation Count:25 |
evaluated: !(openMode & (QFile::ReadOnly | QFile::Append)) yes Evaluation Count:4 | yes Evaluation Count:1 |
| 1-25 |
306 | openMode |= QFile::Truncate; executed: openMode |= QFile::Truncate; Execution Count:4 | 4 |
307 | | - |
308 | d->openMode = openMode; executed (the execution status of this line is deduced): d->openMode = openMode; | - |
309 | d->lastFlushFailed = false; executed (the execution status of this line is deduced): d->lastFlushFailed = false; | - |
310 | d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle); executed (the execution status of this line is deduced): d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle); | - |
311 | d->fileEntry.clear(); executed (the execution status of this line is deduced): d->fileEntry.clear(); | - |
312 | d->fh = 0; executed (the execution status of this line is deduced): d->fh = 0; | - |
313 | d->fd = -1; executed (the execution status of this line is deduced): d->fd = -1; | - |
314 | d->tried_stat = 0; executed (the execution status of this line is deduced): d->tried_stat = 0; | - |
315 | | - |
316 | return d->openFd(openMode, fd); executed: return d->openFd(openMode, fd); Execution Count:30 | 30 |
317 | } | - |
318 | | - |
319 | | - |
320 | /*! | - |
321 | Opens the file descriptor \a fd to the file engine, using the open mode \a | - |
322 | flags. | - |
323 | */ | - |
324 | bool QFSFileEnginePrivate::openFd(QIODevice::OpenMode openMode, int fd) | - |
325 | { | - |
326 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
327 | this->fd = fd; executed (the execution status of this line is deduced): this->fd = fd; | - |
328 | fh = 0; executed (the execution status of this line is deduced): fh = 0; | - |
329 | | - |
330 | // Seek to the end when in Append mode. | - |
331 | if (openMode & QFile::Append) { partially evaluated: openMode & QFile::Append no Evaluation Count:0 | yes Evaluation Count:30 |
| 0-30 |
332 | int ret; never executed (the execution status of this line is deduced): int ret; | - |
333 | do { | - |
334 | ret = QT_LSEEK(fd, 0, SEEK_END); never executed (the execution status of this line is deduced): ret = ::lseek64(fd, 0, 2); | - |
335 | } while (ret == -1 && errno == EINTR); never executed: } never evaluated: ret == -1 never evaluated: (*__errno_location ()) == 4 | 0 |
336 | | - |
337 | if (ret == -1) { never evaluated: ret == -1 | 0 |
338 | q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, never executed (the execution status of this line is deduced): q->setError((*__errno_location ()) == 24 ? QFile::ResourceError : QFile::OpenError, | - |
339 | qt_error_string(int(errno))); never executed (the execution status of this line is deduced): qt_error_string(int((*__errno_location ())))); | - |
340 | | - |
341 | this->openMode = QIODevice::NotOpen; never executed (the execution status of this line is deduced): this->openMode = QIODevice::NotOpen; | - |
342 | this->fd = -1; never executed (the execution status of this line is deduced): this->fd = -1; | - |
343 | | - |
344 | return false; never executed: return false; | 0 |
345 | } | - |
346 | } | 0 |
347 | | - |
348 | return true; executed: return true; Execution Count:30 | 30 |
349 | } | - |
350 | | - |
351 | /*! | - |
352 | \reimp | - |
353 | */ | - |
354 | bool QFSFileEngine::close() | - |
355 | { | - |
356 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
357 | d->openMode = QIODevice::NotOpen; executed (the execution status of this line is deduced): d->openMode = QIODevice::NotOpen; | - |
358 | return d->nativeClose(); executed: return d->nativeClose(); Execution Count:17226 | 17226 |
359 | } | - |
360 | | - |
361 | /*! | - |
362 | \internal | - |
363 | */ | - |
364 | bool QFSFileEnginePrivate::closeFdFh() | - |
365 | { | - |
366 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
367 | if (fd == -1 && !fh) evaluated: fd == -1 yes Evaluation Count:691 | yes Evaluation Count:16535 |
evaluated: !fh yes Evaluation Count:660 | yes Evaluation Count:31 |
| 31-16535 |
368 | return false; executed: return false; Execution Count:660 | 660 |
369 | | - |
370 | // Flush the file if it's buffered, and if the last flush didn't fail. | - |
371 | bool flushed = !fh || (!lastFlushFailed && q->flush()); evaluated: !fh yes Evaluation Count:16535 | yes Evaluation Count:31 |
partially evaluated: !lastFlushFailed yes Evaluation Count:31 | no Evaluation Count:0 |
partially evaluated: q->flush() yes Evaluation Count:31 | no Evaluation Count:0 |
| 0-16535 |
372 | bool closed = true; executed (the execution status of this line is deduced): bool closed = true; | - |
373 | tried_stat = 0; executed (the execution status of this line is deduced): tried_stat = 0; | - |
374 | | - |
375 | // Close the file if we created the handle. | - |
376 | if (closeFileHandle) { evaluated: closeFileHandle yes Evaluation Count:16507 | yes Evaluation Count:59 |
| 59-16507 |
377 | int ret; executed (the execution status of this line is deduced): int ret; | - |
378 | do { | - |
379 | if (fh) { evaluated: fh yes Evaluation Count:1 | yes Evaluation Count:16506 |
| 1-16506 |
380 | // Close buffered file. | - |
381 | ret = fclose(fh) != 0 ? -1 : 0; partially evaluated: fclose(fh) != 0 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
382 | } else { executed: } Execution Count:1 | 1 |
383 | // Close unbuffered file. | - |
384 | ret = QT_CLOSE(fd); executed (the execution status of this line is deduced): ret = qt_safe_close(fd); | - |
385 | } executed: } Execution Count:16506 | 16506 |
386 | } while (ret == -1 && errno == EINTR); partially evaluated: ret == -1 no Evaluation Count:0 | yes Evaluation Count:16507 |
never evaluated: (*__errno_location ()) == 4 | 0-16507 |
387 | | - |
388 | // We must reset these guys regardless; calling close again after a | - |
389 | // failed close causes crashes on some systems. | - |
390 | fh = 0; executed (the execution status of this line is deduced): fh = 0; | - |
391 | fd = -1; executed (the execution status of this line is deduced): fd = -1; | - |
392 | closed = (ret == 0); executed (the execution status of this line is deduced): closed = (ret == 0); | - |
393 | } executed: } Execution Count:16507 | 16507 |
394 | | - |
395 | // Report errors. | - |
396 | if (!flushed || !closed) { partially evaluated: !flushed no Evaluation Count:0 | yes Evaluation Count:16566 |
partially evaluated: !closed no Evaluation Count:0 | yes Evaluation Count:16566 |
| 0-16566 |
397 | if (flushed) { | 0 |
398 | // If not flushed, we want the flush error to fall through. | - |
399 | q->setError(QFile::UnspecifiedError, qt_error_string(errno)); never executed (the execution status of this line is deduced): q->setError(QFile::UnspecifiedError, qt_error_string((*__errno_location ()))); | - |
400 | } | 0 |
401 | return false; never executed: return false; | 0 |
402 | } | - |
403 | | - |
404 | return true; executed: return true; Execution Count:16566 | 16566 |
405 | } | - |
406 | | - |
407 | /*! | - |
408 | \reimp | - |
409 | */ | - |
410 | bool QFSFileEngine::flush() | - |
411 | { | - |
412 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
413 | if ((d->openMode & QIODevice::WriteOnly) == 0) { evaluated: (d->openMode & QIODevice::WriteOnly) == 0 yes Evaluation Count:149489 | yes Evaluation Count:23302 |
| 23302-149489 |
414 | // Nothing in the write buffers, so flush succeeds in doing | - |
415 | // nothing. | - |
416 | return true; executed: return true; Execution Count:149489 | 149489 |
417 | } | - |
418 | return d->nativeFlush(); executed: return d->nativeFlush(); Execution Count:23302 | 23302 |
419 | } | - |
420 | | - |
421 | /*! | - |
422 | \internal | - |
423 | */ | - |
424 | bool QFSFileEnginePrivate::flushFh() | - |
425 | { | - |
426 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
427 | | - |
428 | // Never try to flush again if the last flush failed. Otherwise you can | - |
429 | // get crashes on some systems (AIX). | - |
430 | if (lastFlushFailed) partially evaluated: lastFlushFailed no Evaluation Count:0 | yes Evaluation Count:32 |
| 0-32 |
431 | return false; never executed: return false; | 0 |
432 | | - |
433 | int ret = fflush(fh); executed (the execution status of this line is deduced): int ret = fflush(fh); | - |
434 | | - |
435 | lastFlushFailed = (ret != 0); executed (the execution status of this line is deduced): lastFlushFailed = (ret != 0); | - |
436 | lastIOCommand = QFSFileEnginePrivate::IOFlushCommand; executed (the execution status of this line is deduced): lastIOCommand = QFSFileEnginePrivate::IOFlushCommand; | - |
437 | | - |
438 | if (ret != 0) { partially evaluated: ret != 0 no Evaluation Count:0 | yes Evaluation Count:32 |
| 0-32 |
439 | q->setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError, never executed (the execution status of this line is deduced): q->setError((*__errno_location ()) == 28 ? QFile::ResourceError : QFile::WriteError, | - |
440 | qt_error_string(errno)); never executed (the execution status of this line is deduced): qt_error_string((*__errno_location ()))); | - |
441 | return false; never executed: return false; | 0 |
442 | } | - |
443 | return true; executed: return true; Execution Count:32 | 32 |
444 | } | - |
445 | | - |
446 | /*! | - |
447 | \reimp | - |
448 | */ | - |
449 | qint64 QFSFileEngine::size() const | - |
450 | { | - |
451 | Q_D(const QFSFileEngine); executed (the execution status of this line is deduced): const QFSFileEnginePrivate * const d = d_func(); | - |
452 | return d->nativeSize(); executed: return d->nativeSize(); Execution Count:122314 | 122314 |
453 | } | - |
454 | | - |
455 | #ifndef Q_OS_WIN | - |
456 | /*! | - |
457 | \internal | - |
458 | */ | - |
459 | qint64 QFSFileEnginePrivate::sizeFdFh() const | - |
460 | { | - |
461 | Q_Q(const QFSFileEngine); executed (the execution status of this line is deduced): const QFSFileEngine * const q = q_func(); | - |
462 | const_cast<QFSFileEngine *>(q)->flush(); executed (the execution status of this line is deduced): const_cast<QFSFileEngine *>(q)->flush(); | - |
463 | | - |
464 | tried_stat = 0; executed (the execution status of this line is deduced): tried_stat = 0; | - |
465 | metaData.clearFlags(QFileSystemMetaData::SizeAttribute); executed (the execution status of this line is deduced): metaData.clearFlags(QFileSystemMetaData::SizeAttribute); | - |
466 | if (!doStat(QFileSystemMetaData::SizeAttribute)) evaluated: !doStat(QFileSystemMetaData::SizeAttribute) yes Evaluation Count:2 | yes Evaluation Count:122312 |
| 2-122312 |
467 | return 0; executed: return 0; Execution Count:2 | 2 |
468 | return metaData.size(); executed: return metaData.size(); Execution Count:122312 | 122312 |
469 | } | - |
470 | #endif | - |
471 | | - |
472 | /*! | - |
473 | \reimp | - |
474 | */ | - |
475 | qint64 QFSFileEngine::pos() const | - |
476 | { | - |
477 | Q_D(const QFSFileEngine); executed (the execution status of this line is deduced): const QFSFileEnginePrivate * const d = d_func(); | - |
478 | return d->nativePos(); executed: return d->nativePos(); Execution Count:768 | 768 |
479 | } | - |
480 | | - |
481 | /*! | - |
482 | \internal | - |
483 | */ | - |
484 | qint64 QFSFileEnginePrivate::posFdFh() const | - |
485 | { | - |
486 | if (fh) evaluated: fh yes Evaluation Count:1 | yes Evaluation Count:767 |
| 1-767 |
487 | return qint64(QT_FTELL(fh)); executed: return qint64(::ftello64(fh)); Execution Count:1 | 1 |
488 | return QT_LSEEK(fd, 0, SEEK_CUR); executed: return ::lseek64(fd, 0, 1); Execution Count:767 | 767 |
489 | } | - |
490 | | - |
491 | /*! | - |
492 | \reimp | - |
493 | */ | - |
494 | bool QFSFileEngine::seek(qint64 pos) | - |
495 | { | - |
496 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
497 | return d->nativeSeek(pos); executed: return d->nativeSeek(pos); Execution Count:221320 | 221320 |
498 | } | - |
499 | | - |
500 | /*! | - |
501 | \internal | - |
502 | */ | - |
503 | bool QFSFileEnginePrivate::seekFdFh(qint64 pos) | - |
504 | { | - |
505 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
506 | | - |
507 | // On Windows' stdlib implementation, the results of calling fread and | - |
508 | // fwrite are undefined if not called either in sequence, or if preceded | - |
509 | // with a call to fflush(). | - |
510 | if (lastIOCommand != QFSFileEnginePrivate::IOFlushCommand && !q->flush()) evaluated: lastIOCommand != QFSFileEnginePrivate::IOFlushCommand yes Evaluation Count:4587 | yes Evaluation Count:216733 |
partially evaluated: !q->flush() no Evaluation Count:0 | yes Evaluation Count:4587 |
| 0-216733 |
511 | return false; never executed: return false; | 0 |
512 | | - |
513 | if (pos < 0 || pos != qint64(QT_OFF_T(pos))) partially evaluated: pos < 0 no Evaluation Count:0 | yes Evaluation Count:221320 |
partially evaluated: pos != qint64(off64_t(pos)) no Evaluation Count:0 | yes Evaluation Count:221320 |
| 0-221320 |
514 | return false; never executed: return false; | 0 |
515 | | - |
516 | if (fh) { evaluated: fh yes Evaluation Count:19 | yes Evaluation Count:221301 |
| 19-221301 |
517 | // Buffered stdlib mode. | - |
518 | int ret; executed (the execution status of this line is deduced): int ret; | - |
519 | do { | - |
520 | ret = QT_FSEEK(fh, QT_OFF_T(pos), SEEK_SET); executed (the execution status of this line is deduced): ret = ::fseeko64(fh, off64_t(pos), 0); | - |
521 | } while (ret != 0 && errno == EINTR); executed: } Execution Count:19 partially evaluated: ret != 0 no Evaluation Count:0 | yes Evaluation Count:19 |
never evaluated: (*__errno_location ()) == 4 | 0-19 |
522 | | - |
523 | if (ret != 0) { partially evaluated: ret != 0 no Evaluation Count:0 | yes Evaluation Count:19 |
| 0-19 |
524 | q->setError(QFile::ReadError, qt_error_string(int(errno))); never executed (the execution status of this line is deduced): q->setError(QFile::ReadError, qt_error_string(int((*__errno_location ())))); | - |
525 | return false; never executed: return false; | 0 |
526 | } | - |
527 | } else { executed: } Execution Count:19 | 19 |
528 | // Unbuffered stdio mode. | - |
529 | if (QT_LSEEK(fd, QT_OFF_T(pos), SEEK_SET) == -1) { partially evaluated: ::lseek64(fd, off64_t(pos), 0) == -1 no Evaluation Count:0 | yes Evaluation Count:221301 |
| 0-221301 |
530 | qWarning() << "QFile::at: Cannot set file position" << pos; never executed (the execution status of this line is deduced): QMessageLogger("io/qfsfileengine.cpp", 530, __PRETTY_FUNCTION__).warning() << "QFile::at: Cannot set file position" << pos; | - |
531 | q->setError(QFile::PositionError, qt_error_string(errno)); never executed (the execution status of this line is deduced): q->setError(QFile::PositionError, qt_error_string((*__errno_location ()))); | - |
532 | return false; never executed: return false; | 0 |
533 | } | - |
534 | } executed: } Execution Count:221301 | 221301 |
535 | return true; executed: return true; Execution Count:221320 | 221320 |
536 | } | - |
537 | | - |
538 | /*! | - |
539 | \reimp | - |
540 | */ | - |
541 | int QFSFileEngine::handle() const | - |
542 | { | - |
543 | Q_D(const QFSFileEngine); executed (the execution status of this line is deduced): const QFSFileEnginePrivate * const d = d_func(); | - |
544 | return d->nativeHandle(); executed: return d->nativeHandle(); Execution Count:969 | 969 |
545 | } | - |
546 | | - |
547 | /*! | - |
548 | \reimp | - |
549 | */ | - |
550 | qint64 QFSFileEngine::read(char *data, qint64 maxlen) | - |
551 | { | - |
552 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
553 | | - |
554 | // On Windows' stdlib implementation, the results of calling fread and | - |
555 | // fwrite are undefined if not called either in sequence, or if preceded | - |
556 | // with a call to fflush(). | - |
557 | if (d->lastIOCommand != QFSFileEnginePrivate::IOReadCommand) { evaluated: d->lastIOCommand != QFSFileEnginePrivate::IOReadCommand yes Evaluation Count:11402 | yes Evaluation Count:104251 |
| 11402-104251 |
558 | flush(); executed (the execution status of this line is deduced): flush(); | - |
559 | d->lastIOCommand = QFSFileEnginePrivate::IOReadCommand; executed (the execution status of this line is deduced): d->lastIOCommand = QFSFileEnginePrivate::IOReadCommand; | - |
560 | } executed: } Execution Count:11402 | 11402 |
561 | | - |
562 | return d->nativeRead(data, maxlen); executed: return d->nativeRead(data, maxlen); Execution Count:115654 | 115654 |
563 | } | - |
564 | | - |
565 | /*! | - |
566 | \internal | - |
567 | */ | - |
568 | qint64 QFSFileEnginePrivate::readFdFh(char *data, qint64 len) | - |
569 | { | - |
570 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
571 | | - |
572 | if (len < 0 || len != qint64(size_t(len))) { partially evaluated: len < 0 no Evaluation Count:0 | yes Evaluation Count:115653 |
partially evaluated: len != qint64(size_t(len)) no Evaluation Count:0 | yes Evaluation Count:115653 |
| 0-115653 |
573 | q->setError(QFile::ReadError, qt_error_string(EINVAL)); never executed (the execution status of this line is deduced): q->setError(QFile::ReadError, qt_error_string(22)); | - |
574 | return -1; never executed: return -1; | 0 |
575 | } | - |
576 | | - |
577 | qint64 readBytes = 0; executed (the execution status of this line is deduced): qint64 readBytes = 0; | - |
578 | bool eof = false; executed (the execution status of this line is deduced): bool eof = false; | - |
579 | | - |
580 | if (fh) { evaluated: fh yes Evaluation Count:5 | yes Evaluation Count:115648 |
| 5-115648 |
581 | // Buffered stdlib mode. | - |
582 | | - |
583 | size_t result; executed (the execution status of this line is deduced): size_t result; | - |
584 | bool retry = true; executed (the execution status of this line is deduced): bool retry = true; | - |
585 | do { | - |
586 | result = fread(data + readBytes, 1, size_t(len - readBytes), fh); executed (the execution status of this line is deduced): result = fread(data + readBytes, 1, size_t(len - readBytes), fh); | - |
587 | eof = feof(fh); executed (the execution status of this line is deduced): eof = feof(fh); | - |
588 | if (retry && eof && result == 0) { partially evaluated: retry yes Evaluation Count:5 | no Evaluation Count:0 |
evaluated: eof yes Evaluation Count:4 | yes Evaluation Count:1 |
partially evaluated: result == 0 no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-5 |
589 | // On Mac OS, this is needed, e.g., if a file was written to | - |
590 | // through another stream since our last read. See test | - |
591 | // tst_QFile::appendAndRead | - |
592 | QT_FSEEK(fh, QT_FTELL(fh), SEEK_SET); // re-sync stream. never executed (the execution status of this line is deduced): ::fseeko64(fh, ::ftello64(fh), 0); | - |
593 | retry = false; never executed (the execution status of this line is deduced): retry = false; | - |
594 | continue; never executed: continue; | 0 |
595 | } | - |
596 | readBytes += result; executed (the execution status of this line is deduced): readBytes += result; | - |
597 | } while (!eof && (result == 0 ? errno == EINTR : readBytes < len)); executed: } Execution Count:5 evaluated: !eof yes Evaluation Count:1 | yes Evaluation Count:4 |
partially evaluated: result == 0 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-5 |
598 | | - |
599 | } else if (fd != -1) { executed: } Execution Count:5 partially evaluated: fd != -1 yes Evaluation Count:115648 | no Evaluation Count:0 |
| 0-115648 |
600 | // Unbuffered stdio mode. | - |
601 | | - |
602 | #ifdef Q_OS_WIN | - |
603 | int result; | - |
604 | #else | - |
605 | ssize_t result; executed (the execution status of this line is deduced): ssize_t result; | - |
606 | #endif | - |
607 | do { | - |
608 | result = QT_READ(fd, data + readBytes, size_t(len - readBytes)); executed (the execution status of this line is deduced): result = qt_safe_read(fd, data + readBytes, size_t(len - readBytes)); | - |
609 | } while ((result == -1 && errno == EINTR) executed: } Execution Count:126403 partially evaluated: result == -1 no Evaluation Count:0 | yes Evaluation Count:126403 |
never evaluated: (*__errno_location ()) == 4 | 0-126403 |
610 | || (result > 0 && (readBytes += result) < len)); evaluated: result > 0 yes Evaluation Count:26523 | yes Evaluation Count:99880 |
evaluated: (readBytes += result) < len yes Evaluation Count:10754 | yes Evaluation Count:15769 |
| 10754-99880 |
611 | | - |
612 | eof = !(result == -1); executed (the execution status of this line is deduced): eof = !(result == -1); | - |
613 | } executed: } Execution Count:115649 | 115649 |
614 | | - |
615 | if (!eof && readBytes == 0) { evaluated: !eof yes Evaluation Count:1 | yes Evaluation Count:115653 |
partially evaluated: readBytes == 0 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-115653 |
616 | readBytes = -1; never executed (the execution status of this line is deduced): readBytes = -1; | - |
617 | q->setError(QFile::ReadError, qt_error_string(errno)); never executed (the execution status of this line is deduced): q->setError(QFile::ReadError, qt_error_string((*__errno_location ()))); | - |
618 | } | 0 |
619 | | - |
620 | return readBytes; executed: return readBytes; Execution Count:115654 | 115654 |
621 | } | - |
622 | | - |
623 | /*! | - |
624 | \reimp | - |
625 | */ | - |
626 | qint64 QFSFileEngine::readLine(char *data, qint64 maxlen) | - |
627 | { | - |
628 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
629 | | - |
630 | // On Windows' stdlib implementation, the results of calling fread and | - |
631 | // fwrite are undefined if not called either in sequence, or if preceded | - |
632 | // with a call to fflush(). | - |
633 | if (d->lastIOCommand != QFSFileEnginePrivate::IOReadCommand) { evaluated: d->lastIOCommand != QFSFileEnginePrivate::IOReadCommand yes Evaluation Count:4 | yes Evaluation Count:4 |
| 4 |
634 | flush(); executed (the execution status of this line is deduced): flush(); | - |
635 | d->lastIOCommand = QFSFileEnginePrivate::IOReadCommand; executed (the execution status of this line is deduced): d->lastIOCommand = QFSFileEnginePrivate::IOReadCommand; | - |
636 | } executed: } Execution Count:4 | 4 |
637 | | - |
638 | return d->nativeReadLine(data, maxlen); executed: return d->nativeReadLine(data, maxlen); Execution Count:8 | 8 |
639 | } | - |
640 | | - |
641 | /*! | - |
642 | \internal | - |
643 | */ | - |
644 | qint64 QFSFileEnginePrivate::readLineFdFh(char *data, qint64 maxlen) | - |
645 | { | - |
646 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
647 | if (!fh) partially evaluated: !fh yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-8 |
648 | return q->QAbstractFileEngine::readLine(data, maxlen); executed: return q->QAbstractFileEngine::readLine(data, maxlen); Execution Count:8 | 8 |
649 | | - |
650 | QT_OFF_T oldPos = 0; never executed (the execution status of this line is deduced): off64_t oldPos = 0; | - |
651 | #ifdef Q_OS_WIN | - |
652 | bool seq = q->isSequential(); | - |
653 | if (!seq) | - |
654 | #endif | - |
655 | oldPos = QT_FTELL(fh); never executed (the execution status of this line is deduced): oldPos = ::ftello64(fh); | - |
656 | | - |
657 | // QIODevice::readLine() passes maxlen - 1 to QFile::readLineData() | - |
658 | // because it has made space for the '\0' at the end of data. But fgets | - |
659 | // does the same, so we'd get two '\0' at the end - passing maxlen + 1 | - |
660 | // solves this. | - |
661 | if (!fgets(data, int(maxlen + 1), fh)) { never evaluated: !fgets(data, int(maxlen + 1), fh) | 0 |
662 | if (!feof(fh)) never evaluated: !feof(fh) | 0 |
663 | q->setError(QFile::ReadError, qt_error_string(int(errno))); never executed: q->setError(QFile::ReadError, qt_error_string(int((*__errno_location ())))); | 0 |
664 | return -1; // error never executed: return -1; | 0 |
665 | } | - |
666 | | - |
667 | #ifdef Q_OS_WIN | - |
668 | if (seq) | - |
669 | return qstrlen(data); | - |
670 | #endif | - |
671 | | - |
672 | qint64 lineLength = QT_FTELL(fh) - oldPos; never executed (the execution status of this line is deduced): qint64 lineLength = ::ftello64(fh) - oldPos; | - |
673 | return lineLength > 0 ? lineLength : qstrlen(data); never executed: return lineLength > 0 ? lineLength : qstrlen(data); | 0 |
674 | } | - |
675 | | - |
676 | /*! | - |
677 | \reimp | - |
678 | */ | - |
679 | qint64 QFSFileEngine::write(const char *data, qint64 len) | - |
680 | { | - |
681 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
682 | | - |
683 | // On Windows' stdlib implementation, the results of calling fread and | - |
684 | // fwrite are undefined if not called either in sequence, or if preceded | - |
685 | // with a call to fflush(). | - |
686 | if (d->lastIOCommand != QFSFileEnginePrivate::IOWriteCommand) { evaluated: d->lastIOCommand != QFSFileEnginePrivate::IOWriteCommand yes Evaluation Count:1931 | yes Evaluation Count:14770 |
| 1931-14770 |
687 | flush(); executed (the execution status of this line is deduced): flush(); | - |
688 | d->lastIOCommand = QFSFileEnginePrivate::IOWriteCommand; executed (the execution status of this line is deduced): d->lastIOCommand = QFSFileEnginePrivate::IOWriteCommand; | - |
689 | } executed: } Execution Count:1931 | 1931 |
690 | | - |
691 | return d->nativeWrite(data, len); executed: return d->nativeWrite(data, len); Execution Count:16701 | 16701 |
692 | } | - |
693 | | - |
694 | /*! | - |
695 | \internal | - |
696 | */ | - |
697 | qint64 QFSFileEnginePrivate::writeFdFh(const char *data, qint64 len) | - |
698 | { | - |
699 | Q_Q(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEngine * const q = q_func(); | - |
700 | | - |
701 | if (len < 0 || len != qint64(size_t(len))) { partially evaluated: len < 0 no Evaluation Count:0 | yes Evaluation Count:16701 |
partially evaluated: len != qint64(size_t(len)) no Evaluation Count:0 | yes Evaluation Count:16701 |
| 0-16701 |
702 | q->setError(QFile::WriteError, qt_error_string(EINVAL)); never executed (the execution status of this line is deduced): q->setError(QFile::WriteError, qt_error_string(22)); | - |
703 | return -1; never executed: return -1; | 0 |
704 | } | - |
705 | | - |
706 | qint64 writtenBytes = 0; executed (the execution status of this line is deduced): qint64 writtenBytes = 0; | - |
707 | | - |
708 | if (fh) { evaluated: fh yes Evaluation Count:6 | yes Evaluation Count:16695 |
| 6-16695 |
709 | // Buffered stdlib mode. | - |
710 | | - |
711 | size_t result; executed (the execution status of this line is deduced): size_t result; | - |
712 | do { | - |
713 | result = fwrite(data + writtenBytes, 1, size_t(len - writtenBytes), fh); executed (the execution status of this line is deduced): result = fwrite(data + writtenBytes, 1, size_t(len - writtenBytes), fh); | - |
714 | writtenBytes += result; executed (the execution status of this line is deduced): writtenBytes += result; | - |
715 | } while (result == 0 ? errno == EINTR : writtenBytes < len); executed: } Execution Count:6 evaluated: result == 0 yes Evaluation Count:1 | yes Evaluation Count:5 |
| 1-6 |
716 | | - |
717 | } else if (fd != -1) { executed: } Execution Count:6 partially evaluated: fd != -1 yes Evaluation Count:16695 | no Evaluation Count:0 |
| 0-16695 |
718 | // Unbuffered stdio mode. | - |
719 | | - |
720 | #ifdef Q_OS_WIN | - |
721 | int result; | - |
722 | #else | - |
723 | ssize_t result; executed (the execution status of this line is deduced): ssize_t result; | - |
724 | #endif | - |
725 | do { | - |
726 | result = QT_WRITE(fd, data + writtenBytes, size_t(len - writtenBytes)); executed (the execution status of this line is deduced): result = qt_safe_write(fd, data + writtenBytes, size_t(len - writtenBytes)); | - |
727 | } while ((result == -1 && errno == EINTR) executed: } Execution Count:16695 evaluated: result == -1 yes Evaluation Count:6 | yes Evaluation Count:16689 |
partially evaluated: (*__errno_location ()) == 4 no Evaluation Count:0 | yes Evaluation Count:6 |
| 0-16695 |
728 | || (result > 0 && (writtenBytes += result) < len)); evaluated: result > 0 yes Evaluation Count:16687 | yes Evaluation Count:8 |
partially evaluated: (writtenBytes += result) < len no Evaluation Count:0 | yes Evaluation Count:16687 |
| 0-16687 |
729 | } executed: } Execution Count:16695 | 16695 |
730 | | - |
731 | if (len && writtenBytes == 0) { evaluated: len yes Evaluation Count:16698 | yes Evaluation Count:3 |
evaluated: writtenBytes == 0 yes Evaluation Count:6 | yes Evaluation Count:16692 |
| 3-16698 |
732 | writtenBytes = -1; executed (the execution status of this line is deduced): writtenBytes = -1; | - |
733 | q->setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError, qt_error_string(errno)); executed (the execution status of this line is deduced): q->setError((*__errno_location ()) == 28 ? QFile::ResourceError : QFile::WriteError, qt_error_string((*__errno_location ()))); | - |
734 | } executed: } Execution Count:6 | 6 |
735 | | - |
736 | return writtenBytes; executed: return writtenBytes; Execution Count:16701 | 16701 |
737 | } | - |
738 | | - |
739 | #ifndef QT_NO_FILESYSTEMITERATOR | - |
740 | /*! | - |
741 | \internal | - |
742 | */ | - |
743 | QAbstractFileEngine::Iterator *QFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) | - |
744 | { | - |
745 | return new QFSFileEngineIterator(filters, filterNames); never executed: return new QFSFileEngineIterator(filters, filterNames); | 0 |
746 | } | - |
747 | | - |
748 | /*! | - |
749 | \internal | - |
750 | */ | - |
751 | QAbstractFileEngine::Iterator *QFSFileEngine::endEntryList() | - |
752 | { | - |
753 | return 0; never executed: return 0; | 0 |
754 | } | - |
755 | #endif // QT_NO_FILESYSTEMITERATOR | - |
756 | | - |
757 | /*! | - |
758 | \internal | - |
759 | */ | - |
760 | QStringList QFSFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const | - |
761 | { | - |
762 | return QAbstractFileEngine::entryList(filters, filterNames); never executed: return QAbstractFileEngine::entryList(filters, filterNames); | 0 |
763 | } | - |
764 | | - |
765 | /*! | - |
766 | \reimp | - |
767 | */ | - |
768 | bool QFSFileEngine::isSequential() const | - |
769 | { | - |
770 | Q_D(const QFSFileEngine); executed (the execution status of this line is deduced): const QFSFileEnginePrivate * const d = d_func(); | - |
771 | if (d->is_sequential == 0) evaluated: d->is_sequential == 0 yes Evaluation Count:13526 | yes Evaluation Count:12757 |
| 12757-13526 |
772 | d->is_sequential = d->nativeIsSequential() ? 1 : 2; executed: d->is_sequential = d->nativeIsSequential() ? 1 : 2; Execution Count:13526 evaluated: d->nativeIsSequential() yes Evaluation Count:32 | yes Evaluation Count:13495 |
| 32-13526 |
773 | return d->is_sequential == 1; executed: return d->is_sequential == 1; Execution Count:26284 | 26284 |
774 | } | - |
775 | | - |
776 | /*! | - |
777 | \internal | - |
778 | */ | - |
779 | #ifdef Q_OS_UNIX | - |
780 | bool QFSFileEnginePrivate::isSequentialFdFh() const | - |
781 | { | - |
782 | if (doStat(QFileSystemMetaData::SequentialType)) partially evaluated: doStat(QFileSystemMetaData::SequentialType) yes Evaluation Count:13532 | no Evaluation Count:0 |
| 0-13532 |
783 | return metaData.isSequential(); executed: return metaData.isSequential(); Execution Count:13532 | 13532 |
784 | return true; never executed: return true; | 0 |
785 | } | - |
786 | #endif | - |
787 | | - |
788 | /*! | - |
789 | \reimp | - |
790 | */ | - |
791 | bool QFSFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) | - |
792 | { | - |
793 | Q_D(QFSFileEngine); executed (the execution status of this line is deduced): QFSFileEnginePrivate * const d = d_func(); | - |
794 | if (extension == AtEndExtension && d->fh && isSequential()) partially evaluated: extension == AtEndExtension no Evaluation Count:0 | yes Evaluation Count:66660 |
never evaluated: d->fh never evaluated: isSequential() | 0-66660 |
795 | return feof(d->fh); never executed: return feof(d->fh); | 0 |
796 | | - |
797 | if (extension == MapExtension) { evaluated: extension == MapExtension yes Evaluation Count:33334 | yes Evaluation Count:33326 |
| 33326-33334 |
798 | const MapExtensionOption *options = (MapExtensionOption*)(option); executed (the execution status of this line is deduced): const MapExtensionOption *options = (MapExtensionOption*)(option); | - |
799 | MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); executed (the execution status of this line is deduced): MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); | - |
800 | returnValue->address = d->map(options->offset, options->size, options->flags); executed (the execution status of this line is deduced): returnValue->address = d->map(options->offset, options->size, options->flags); | - |
801 | return (returnValue->address != 0); executed: return (returnValue->address != 0); Execution Count:33334 | 33334 |
802 | } | - |
803 | if (extension == UnMapExtension) { partially evaluated: extension == UnMapExtension yes Evaluation Count:33326 | no Evaluation Count:0 |
| 0-33326 |
804 | UnMapExtensionOption *options = (UnMapExtensionOption*)option; executed (the execution status of this line is deduced): UnMapExtensionOption *options = (UnMapExtensionOption*)option; | - |
805 | return d->unmap(options->address); executed: return d->unmap(options->address); Execution Count:33326 | 33326 |
806 | } | - |
807 | | - |
808 | return false; never executed: return false; | 0 |
809 | } | - |
810 | | - |
811 | /*! | - |
812 | \reimp | - |
813 | */ | - |
814 | bool QFSFileEngine::supportsExtension(Extension extension) const | - |
815 | { | - |
816 | Q_D(const QFSFileEngine); executed (the execution status of this line is deduced): const QFSFileEnginePrivate * const d = d_func(); | - |
817 | if (extension == AtEndExtension && d->fh && isSequential()) evaluated: extension == AtEndExtension yes Evaluation Count:4251 | yes Evaluation Count:66486 |
evaluated: d->fh yes Evaluation Count:4 | yes Evaluation Count:4247 |
partially evaluated: isSequential() no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-66486 |
818 | return true; never executed: return true; | 0 |
819 | if (extension == FastReadLineExtension && d->fh) evaluated: extension == FastReadLineExtension yes Evaluation Count:349 | yes Evaluation Count:70388 |
partially evaluated: d->fh no Evaluation Count:0 | yes Evaluation Count:349 |
| 0-70388 |
820 | return true; never executed: return true; | 0 |
821 | if (extension == FastReadLineExtension && d->fd != -1 && isSequential()) evaluated: extension == FastReadLineExtension yes Evaluation Count:349 | yes Evaluation Count:70388 |
partially evaluated: d->fd != -1 yes Evaluation Count:349 | no Evaluation Count:0 |
evaluated: isSequential() yes Evaluation Count:8 | yes Evaluation Count:341 |
| 0-70388 |
822 | return true; executed: return true; Execution Count:8 | 8 |
823 | if (extension == UnMapExtension || extension == MapExtension) evaluated: extension == UnMapExtension yes Evaluation Count:32803 | yes Evaluation Count:37926 |
evaluated: extension == MapExtension yes Evaluation Count:33334 | yes Evaluation Count:4592 |
| 4592-37926 |
824 | return true; executed: return true; Execution Count:66137 | 66137 |
825 | return false; executed: return false; Execution Count:4592 | 4592 |
826 | } | - |
827 | | - |
828 | /*! \fn bool QFSFileEngine::caseSensitive() const | - |
829 | Returns true for Windows, false for Unix. | - |
830 | */ | - |
831 | | - |
832 | /*! \fn bool QFSFileEngine::copy(const QString ©Name) | - |
833 | | - |
834 | For windows, copy the file to file \a copyName. | - |
835 | | - |
836 | Not implemented for Unix. | - |
837 | */ | - |
838 | | - |
839 | /*! \fn QString QFSFileEngine::currentPath(const QString &fileName) | - |
840 | For Unix, returns the current working directory for the file | - |
841 | engine. | - |
842 | | - |
843 | For Windows, returns the canonicalized form of the current path used | - |
844 | by the file engine for the drive specified by \a fileName. On | - |
845 | Windows, each drive has its own current directory, so a different | - |
846 | path is returned for file names that include different drive names | - |
847 | (e.g. A: or C:). | - |
848 | | - |
849 | \sa setCurrentPath() | - |
850 | */ | - |
851 | | - |
852 | /*! \fn QFileInfoList QFSFileEngine::drives() | - |
853 | For Windows, returns the list of drives in the file system as a list | - |
854 | of QFileInfo objects. On unix, Mac OS X and Windows CE, only the | - |
855 | root path is returned. On Windows, this function returns all drives | - |
856 | (A:\, C:\, D:\, etc.). | - |
857 | | - |
858 | For Unix, the list contains just the root path "/". | - |
859 | */ | - |
860 | | - |
861 | /*! \fn QString QFSFileEngine::fileName(FileName file) const | - |
862 | \reimp | - |
863 | */ | - |
864 | | - |
865 | /*! \fn QDateTime QFSFileEngine::fileTime(FileTime time) const | - |
866 | \reimp | - |
867 | */ | - |
868 | | - |
869 | /*! \fn QString QFSFileEngine::homePath() | - |
870 | Returns the home path of the current user. | - |
871 | | - |
872 | \sa rootPath() | - |
873 | */ | - |
874 | | - |
875 | /*! \fn bool QFSFileEngine::isRelativePath() const | - |
876 | \reimp | - |
877 | */ | - |
878 | | - |
879 | /*! \fn bool QFSFileEngine::link(const QString &newName) | - |
880 | | - |
881 | Creates a link from the file currently specified by fileName() to | - |
882 | \a newName. What a link is depends on the underlying filesystem | - |
883 | (be it a shortcut on Windows or a symbolic link on Unix). Returns | - |
884 | true if successful; otherwise returns false. | - |
885 | */ | - |
886 | | - |
887 | /*! \fn bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const | - |
888 | \reimp | - |
889 | */ | - |
890 | | - |
891 | /*! \fn uint QFSFileEngine::ownerId(FileOwner own) const | - |
892 | In Unix, if stat() is successful, the \c uid is returned if | - |
893 | \a own is the owner. Otherwise the \c gid is returned. If stat() | - |
894 | is unsuccessful, -2 is reuturned. | - |
895 | | - |
896 | For Windows, -2 is always returned. | - |
897 | */ | - |
898 | | - |
899 | /*! \fn QString QFSFileEngine::owner(FileOwner own) const | - |
900 | \reimp | - |
901 | */ | - |
902 | | - |
903 | /*! \fn bool QFSFileEngine::remove() | - |
904 | \reimp | - |
905 | */ | - |
906 | | - |
907 | /*! \fn bool QFSFileEngine::rename(const QString &newName) | - |
908 | \reimp | - |
909 | */ | - |
910 | | - |
911 | /*! \fn bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const | - |
912 | \reimp | - |
913 | */ | - |
914 | | - |
915 | /*! \fn QString QFSFileEngine::rootPath() | - |
916 | Returns the root path. | - |
917 | | - |
918 | \sa homePath() | - |
919 | */ | - |
920 | | - |
921 | /*! \fn bool QFSFileEngine::setCurrentPath(const QString &path) | - |
922 | Sets the current path (e.g., for QDir), to \a path. Returns true if the | - |
923 | new path exists; otherwise this function does nothing, and returns false. | - |
924 | | - |
925 | \sa currentPath() | - |
926 | */ | - |
927 | | - |
928 | /*! \fn bool QFSFileEngine::setPermissions(uint perms) | - |
929 | \reimp | - |
930 | */ | - |
931 | | - |
932 | /*! \fn bool QFSFileEngine::setSize(qint64 size) | - |
933 | \reimp | - |
934 | */ | - |
935 | | - |
936 | /*! \fn QString QFSFileEngine::tempPath() | - |
937 | Returns the temporary path (i.e., a path in which it is safe | - |
938 | to store temporary files). | - |
939 | */ | - |
940 | | - |
941 | /*! \fn QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const | - |
942 | \internal | - |
943 | */ | - |
944 | | - |
945 | QT_END_NAMESPACE | - |
946 | | - |
947 | #endif // QT_NO_FSFILEENGINE | - |
948 | | - |
| | |