io/qiodevice.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//#define QIODEVICE_DEBUG -
43 -
44#include "qbytearray.h" -
45#include "qdebug.h" -
46#include "qiodevice_p.h" -
47#include "qfile.h" -
48#include "qstringlist.h" -
49#include <limits.h> -
50 -
51#ifdef QIODEVICE_DEBUG -
52# include <ctype.h> -
53#endif -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57#ifdef QIODEVICE_DEBUG -
58void debugBinaryString(const QByteArray &input) -
59{ -
60 QByteArray tmp; -
61 int startOffset = 0; -
62 for (int i = 0; i < input.size(); ++i) { -
63 tmp += input[i]; -
64 -
65 if ((i % 16) == 15 || i == (input.size() - 1)) { -
66 printf("\n%15d:", startOffset); -
67 startOffset += tmp.size(); -
68 -
69 for (int j = 0; j < tmp.size(); ++j) -
70 printf(" %02x", int(uchar(tmp[j]))); -
71 for (int j = tmp.size(); j < 16 + 1; ++j) -
72 printf(" "); -
73 for (int j = 0; j < tmp.size(); ++j) -
74 printf("%c", isprint(int(uchar(tmp[j]))) ? tmp[j] : '.'); -
75 tmp.clear(); -
76 } -
77 } -
78 printf("\n\n"); -
79} -
80 -
81void debugBinaryString(const char *data, qint64 maxlen) -
82{ -
83 debugBinaryString(QByteArray(data, maxlen)); -
84} -
85#endif -
86 -
87#define Q_VOID -
88 -
89#define CHECK_MAXLEN(function, returnType) \ -
90 do { \ -
91 if (maxSize < 0) { \ -
92 qWarning("QIODevice::"#function": Called with maxSize < 0"); \ -
93 return returnType; \ -
94 } \ -
95 } while (0) -
96 -
97#define CHECK_WRITABLE(function, returnType) \ -
98 do { \ -
99 if ((d->openMode & WriteOnly) == 0) { \ -
100 if (d->openMode == NotOpen) \ -
101 return returnType; \ -
102 qWarning("QIODevice::"#function": ReadOnly device"); \ -
103 return returnType; \ -
104 } \ -
105 } while (0) -
106 -
107#define CHECK_READABLE(function, returnType) \ -
108 do { \ -
109 if ((d->openMode & ReadOnly) == 0) { \ -
110 if (d->openMode == NotOpen) \ -
111 return returnType; \ -
112 qWarning("QIODevice::"#function": WriteOnly device"); \ -
113 return returnType; \ -
114 } \ -
115 } while (0) -
116 -
117/*! -
118 \internal -
119 */ -
120QIODevicePrivate::QIODevicePrivate() -
121 : openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE), -
122 pos(0), devicePos(0), seqDumpPos(0) -
123 , pPos(&pos), pDevicePos(&devicePos) -
124 , baseReadLineDataCalled(false) -
125 , firstRead(true) -
126 , accessMode(Unset) -
127#ifdef QT_NO_QOBJECT -
128 , q_ptr(0) -
129#endif -
130{ -
131}
executed: }
Execution Count:39960
39960
132 -
133/*! -
134 \internal -
135 */ -
136QIODevicePrivate::~QIODevicePrivate() -
137{ -
138} -
139 -
140/*! -
141 \class QIODevice -
142 \inmodule QtCore -
143 \reentrant -
144 -
145 \brief The QIODevice class is the base interface class of all I/O -
146 devices in Qt. -
147 -
148 \ingroup io -
149 -
150 QIODevice provides both a common implementation and an abstract -
151 interface for devices that support reading and writing of blocks -
152 of data, such as QFile, QBuffer and QTcpSocket. QIODevice is -
153 abstract and can not be instantiated, but it is common to use the -
154 interface it defines to provide device-independent I/O features. -
155 For example, Qt's XML classes operate on a QIODevice pointer, -
156 allowing them to be used with various devices (such as files and -
157 buffers). -
158 -
159 Before accessing the device, open() must be called to set the -
160 correct OpenMode (such as ReadOnly or ReadWrite). You can then -
161 write to the device with write() or putChar(), and read by calling -
162 either read(), readLine(), or readAll(). Call close() when you are -
163 done with the device. -
164 -
165 QIODevice distinguishes between two types of devices: -
166 random-access devices and sequential devices. -
167 -
168 \list -
169 \li Random-access devices support seeking to arbitrary -
170 positions using seek(). The current position in the file is -
171 available by calling pos(). QFile and QBuffer are examples of -
172 random-access devices. -
173 -
174 \li Sequential devices don't support seeking to arbitrary -
175 positions. The data must be read in one pass. The functions -
176 pos() and size() don't work for sequential devices. -
177 QTcpSocket and QProcess are examples of sequential devices. -
178 \endlist -
179 -
180 You can use isSequential() to determine the type of device. -
181 -
182 QIODevice emits readyRead() when new data is available for -
183 reading; for example, if new data has arrived on the network or if -
184 additional data is appended to a file that you are reading -
185 from. You can call bytesAvailable() to determine the number of -
186 bytes that are currently available for reading. It's common to use -
187 bytesAvailable() together with the readyRead() signal when -
188 programming with asynchronous devices such as QTcpSocket, where -
189 fragments of data can arrive at arbitrary points in -
190 time. QIODevice emits the bytesWritten() signal every time a -
191 payload of data has been written to the device. Use bytesToWrite() -
192 to determine the current amount of data waiting to be written. -
193 -
194 Certain subclasses of QIODevice, such as QTcpSocket and QProcess, -
195 are asynchronous. This means that I/O functions such as write() -
196 or read() always return immediately, while communication with the -
197 device itself may happen when control goes back to the event loop. -
198 QIODevice provides functions that allow you to force these -
199 operations to be performed immediately, while blocking the -
200 calling thread and without entering the event loop. This allows -
201 QIODevice subclasses to be used without an event loop, or in -
202 a separate thread: -
203 -
204 \list -
205 \li waitForReadyRead() - This function suspends operation in the -
206 calling thread until new data is available for reading. -
207 -
208 \li waitForBytesWritten() - This function suspends operation in the -
209 calling thread until one payload of data has been written to the -
210 device. -
211 -
212 \li waitFor....() - Subclasses of QIODevice implement blocking -
213 functions for device-specific operations. For example, QProcess -
214 has a function called waitForStarted() which suspends operation in -
215 the calling thread until the process has started. -
216 \endlist -
217 -
218 Calling these functions from the main, GUI thread, may cause your -
219 user interface to freeze. Example: -
220 -
221 \snippet code/src_corelib_io_qiodevice.cpp 0 -
222 -
223 By subclassing QIODevice, you can provide the same interface to -
224 your own I/O devices. Subclasses of QIODevice are only required to -
225 implement the protected readData() and writeData() functions. -
226 QIODevice uses these functions to implement all its convenience -
227 functions, such as getChar(), readLine() and write(). QIODevice -
228 also handles access control for you, so you can safely assume that -
229 the device is opened in write mode if writeData() is called. -
230 -
231 Some subclasses, such as QFile and QTcpSocket, are implemented -
232 using a memory buffer for intermediate storing of data. This -
233 reduces the number of required device accessing calls, which are -
234 often very slow. Buffering makes functions like getChar() and -
235 putChar() fast, as they can operate on the memory buffer instead -
236 of directly on the device itself. Certain I/O operations, however, -
237 don't work well with a buffer. For example, if several users open -
238 the same device and read it character by character, they may end -
239 up reading the same data when they meant to read a separate chunk -
240 each. For this reason, QIODevice allows you to bypass any -
241 buffering by passing the Unbuffered flag to open(). When -
242 subclassing QIODevice, remember to bypass any buffer you may use -
243 when the device is open in Unbuffered mode. -
244 -
245 \sa QBuffer, QFile, QTcpSocket -
246*/ -
247 -
248/*! -
249 \enum QIODevice::OpenModeFlag -
250 -
251 This enum is used with open() to describe the mode in which a device -
252 is opened. It is also returned by openMode(). -
253 -
254 \value NotOpen The device is not open. -
255 \value ReadOnly The device is open for reading. -
256 \value WriteOnly The device is open for writing. -
257 \value ReadWrite The device is open for reading and writing. -
258 \value Append The device is opened in append mode, so that all data is -
259 written to the end of the file. -
260 \value Truncate If possible, the device is truncated before it is opened. -
261 All earlier contents of the device are lost. -
262 \value Text When reading, the end-of-line terminators are -
263 translated to '\\n'. When writing, the end-of-line -
264 terminators are translated to the local encoding, for -
265 example '\\r\\n' for Win32. -
266 \value Unbuffered Any buffer in the device is bypassed. -
267 -
268 Certain flags, such as \c Unbuffered and \c Truncate, are -
269 meaningless when used with some subclasses. Some of these -
270 restrictions are implied by the type of device that is represented -
271 by a subclass. In other cases, the restriction may be due to the -
272 implementation, or may be imposed by the underlying platform; for -
273 example, QTcpSocket does not support \c Unbuffered mode, and -
274 limitations in the native API prevent QFile from supporting \c -
275 Unbuffered on Windows. -
276*/ -
277 -
278/*! \fn QIODevice::bytesWritten(qint64 bytes) -
279 -
280 This signal is emitted every time a payload of data has been -
281 written to the device. The \a bytes argument is set to the number -
282 of bytes that were written in this payload. -
283 -
284 bytesWritten() is not emitted recursively; if you reenter the event loop -
285 or call waitForBytesWritten() inside a slot connected to the -
286 bytesWritten() signal, the signal will not be reemitted (although -
287 waitForBytesWritten() may still return true). -
288 -
289 \sa readyRead() -
290*/ -
291 -
292/*! -
293 \fn QIODevice::readyRead() -
294 -
295 This signal is emitted once every time new data is available for -
296 reading from the device. It will only be emitted again once new -
297 data is available, such as when a new payload of network data has -
298 arrived on your network socket, or when a new block of data has -
299 been appended to your device. -
300 -
301 readyRead() is not emitted recursively; if you reenter the event loop or -
302 call waitForReadyRead() inside a slot connected to the readyRead() signal, -
303 the signal will not be reemitted (although waitForReadyRead() may still -
304 return true). -
305 -
306 Note for developers implementing classes derived from QIODevice: -
307 you should always emit readyRead() when new data has arrived (do not -
308 emit it only because there's data still to be read in your -
309 buffers). Do not emit readyRead() in other conditions. -
310 -
311 \sa bytesWritten() -
312*/ -
313 -
314/*! \fn QIODevice::aboutToClose() -
315 -
316 This signal is emitted when the device is about to close. Connect -
317 this signal if you have operations that need to be performed -
318 before the device closes (e.g., if you have data in a separate -
319 buffer that needs to be written to the device). -
320*/ -
321 -
322/*! -
323 \fn QIODevice::readChannelFinished() -
324 \since 4.4 -
325 -
326 This signal is emitted when the input (reading) stream is closed -
327 in this device. It is emitted as soon as the closing is detected, -
328 which means that there might still be data available for reading -
329 with read(). -
330 -
331 \sa atEnd(), read() -
332*/ -
333 -
334#ifdef QT_NO_QOBJECT -
335QIODevice::QIODevice() -
336 : d_ptr(new QIODevicePrivate) -
337{ -
338 d_ptr->q_ptr = this; -
339} -
340 -
341/*! -
342 \internal -
343*/ -
344QIODevice::QIODevice(QIODevicePrivate &dd) -
345 : d_ptr(&dd) -
346{ -
347 d_ptr->q_ptr = this; -
348} -
349#else -
350 -
351/*! -
352 Constructs a QIODevice object. -
353*/ -
354 -
355QIODevice::QIODevice() -
356 : QObject(*new QIODevicePrivate, 0) -
357{ -
358#if defined QIODEVICE_DEBUG -
359 QFile *file = qobject_cast<QFile *>(this); -
360 printf("%p QIODevice::QIODevice(\"%s\") %s\n", this, metaObject()->className(), -
361 qPrintable(file ? file->fileName() : QString())); -
362#endif -
363}
executed: }
Execution Count:34
34
364 -
365/*! -
366 Constructs a QIODevice object with the given \a parent. -
367*/ -
368 -
369QIODevice::QIODevice(QObject *parent) -
370 : QObject(*new QIODevicePrivate, parent) -
371{ -
372#if defined QIODEVICE_DEBUG -
373 printf("%p QIODevice::QIODevice(%p \"%s\")\n", this, parent, metaObject()->className()); -
374#endif -
375}
executed: }
Execution Count:11
11
376 -
377/*! -
378 \internal -
379*/ -
380QIODevice::QIODevice(QIODevicePrivate &dd, QObject *parent) -
381 : QObject(dd, parent) -
382{ -
383}
executed: }
Execution Count:39915
39915
384#endif -
385 -
386 -
387/*! -
388 The destructor is virtual, and QIODevice is an abstract base -
389 class. This destructor does not call close(), but the subclass -
390 destructor might. If you are in doubt, call close() before -
391 destroying the QIODevice. -
392*/ -
393QIODevice::~QIODevice() -
394{ -
395#if defined QIODEVICE_DEBUG -
396 printf("%p QIODevice::~QIODevice()\n", this); -
397#endif -
398} -
399 -
400/*! -
401 Returns true if this device is sequential; otherwise returns -
402 false. -
403 -
404 Sequential devices, as opposed to a random-access devices, have no -
405 concept of a start, an end, a size, or a current position, and they -
406 do not support seeking. You can only read from the device when it -
407 reports that data is available. The most common example of a -
408 sequential device is a network socket. On Unix, special files such -
409 as /dev/zero and fifo pipes are sequential. -
410 -
411 Regular files, on the other hand, do support random access. They -
412 have both a size and a current position, and they also support -
413 seeking backwards and forwards in the data stream. Regular files -
414 are non-sequential. -
415 -
416 \sa bytesAvailable() -
417*/ -
418bool QIODevice::isSequential() const -
419{ -
420 return false;
executed: return false;
Execution Count:8352
8352
421} -
422 -
423/*! -
424 Returns the mode in which the device has been opened; -
425 i.e. ReadOnly or WriteOnly. -
426 -
427 \sa OpenMode -
428*/ -
429QIODevice::OpenMode QIODevice::openMode() const -
430{ -
431 return d_func()->openMode;
executed: return d_func()->openMode;
Execution Count:6601
6601
432} -
433 -
434/*! -
435 Sets the OpenMode of the device to \a openMode. Call this -
436 function to set the open mode if the flags change after the device -
437 has been opened. -
438 -
439 \sa openMode(), OpenMode -
440*/ -
441void QIODevice::setOpenMode(OpenMode openMode) -
442{ -
443 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
444#if defined QIODEVICE_DEBUG -
445 printf("%p QIODevice::setOpenMode(0x%x)\n", this, int(openMode)); -
446#endif -
447 d->openMode = openMode;
executed (the execution status of this line is deduced): d->openMode = openMode;
-
448 d->accessMode = QIODevicePrivate::Unset;
executed (the execution status of this line is deduced): d->accessMode = QIODevicePrivate::Unset;
-
449 d->firstRead = true;
executed (the execution status of this line is deduced): d->firstRead = true;
-
450 if (!isReadable())
evaluated: !isReadable()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:108
2-108
451 d->buffer.clear();
executed: d->buffer.clear();
Execution Count:2
2
452}
executed: }
Execution Count:110
110
453 -
454/*! -
455 If \a enabled is true, this function sets the \l Text flag on the device; -
456 otherwise the \l Text flag is removed. This feature is useful for classes -
457 that provide custom end-of-line handling on a QIODevice. -
458 -
459 The IO device should be opened before calling this function. -
460 -
461 \sa open(), setOpenMode() -
462 */ -
463void QIODevice::setTextModeEnabled(bool enabled) -
464{ -
465 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
466 if (!isOpen()) {
partially evaluated: !isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:82078611
0-82078611
467 qWarning("QIODevice::setTextModeEnabled: The device is not open");
never executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 467, __PRETTY_FUNCTION__).warning("QIODevice::setTextModeEnabled: The device is not open");
-
468 return;
never executed: return;
0
469 } -
470 if (enabled)
evaluated: enabled
TRUEFALSE
yes
Evaluation Count:41038132
yes
Evaluation Count:41040479
41038132-41040479
471 d->openMode |= Text;
executed: d->openMode |= Text;
Execution Count:41038132
41038132
472 else -
473 d->openMode &= ~Text;
executed: d->openMode &= ~Text;
Execution Count:41040479
41040479
474} -
475 -
476/*! -
477 Returns true if the \l Text flag is enabled; otherwise returns false. -
478 -
479 \sa setTextModeEnabled() -
480*/ -
481bool QIODevice::isTextModeEnabled() const -
482{ -
483 return d_func()->openMode & Text;
executed: return d_func()->openMode & Text;
Execution Count:41042456
41042456
484} -
485 -
486/*! -
487 Returns true if the device is open; otherwise returns false. A -
488 device is open if it can be read from and/or written to. By -
489 default, this function returns false if openMode() returns -
490 \c NotOpen. -
491 -
492 \sa openMode(), OpenMode -
493*/ -
494bool QIODevice::isOpen() const -
495{ -
496 return d_func()->openMode != NotOpen;
executed: return d_func()->openMode != NotOpen;
Execution Count:82403739
82403739
497} -
498 -
499/*! -
500 Returns true if data can be read from the device; otherwise returns -
501 false. Use bytesAvailable() to determine how many bytes can be read. -
502 -
503 This is a convenience function which checks if the OpenMode of the -
504 device contains the ReadOnly flag. -
505 -
506 \sa openMode(), OpenMode -
507*/ -
508bool QIODevice::isReadable() const -
509{ -
510 return (openMode() & ReadOnly) != 0;
executed: return (openMode() & ReadOnly) != 0;
Execution Count:4769
4769
511} -
512 -
513/*! -
514 Returns true if data can be written to the device; otherwise returns -
515 false. -
516 -
517 This is a convenience function which checks if the OpenMode of the -
518 device contains the WriteOnly flag. -
519 -
520 \sa openMode(), OpenMode -
521*/ -
522bool QIODevice::isWritable() const -
523{ -
524 return (openMode() & WriteOnly) != 0;
executed: return (openMode() & WriteOnly) != 0;
Execution Count:1806
1806
525} -
526 -
527/*! -
528 Opens the device and sets its OpenMode to \a mode. Returns true if successful; -
529 otherwise returns false. This function should be called from any -
530 reimplementations of open() or other functions that open the device. -
531 -
532 \sa openMode(), OpenMode -
533*/ -
534bool QIODevice::open(OpenMode mode) -
535{ -
536 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
537 d->openMode = mode;
executed (the execution status of this line is deduced): d->openMode = mode;
-
538 d->pos = (mode & Append) ? size() : qint64(0);
evaluated: (mode & Append)
TRUEFALSE
yes
Evaluation Count:274
yes
Evaluation Count:31302
274-31302
539 d->buffer.clear();
executed (the execution status of this line is deduced): d->buffer.clear();
-
540 d->accessMode = QIODevicePrivate::Unset;
executed (the execution status of this line is deduced): d->accessMode = QIODevicePrivate::Unset;
-
541 d->firstRead = true;
executed (the execution status of this line is deduced): d->firstRead = true;
-
542#if defined QIODEVICE_DEBUG -
543 printf("%p QIODevice::open(0x%x)\n", this, quint32(mode)); -
544#endif -
545 return true;
executed: return true;
Execution Count:31576
31576
546} -
547 -
548/*! -
549 First emits aboutToClose(), then closes the device and sets its -
550 OpenMode to NotOpen. The error string is also reset. -
551 -
552 \sa setOpenMode(), OpenMode -
553*/ -
554void QIODevice::close() -
555{ -
556 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
557 if (d->openMode == NotOpen)
evaluated: d->openMode == NotOpen
TRUEFALSE
yes
Evaluation Count:3627
yes
Evaluation Count:22074
3627-22074
558 return;
executed: return;
Execution Count:3627
3627
559 -
560#if defined QIODEVICE_DEBUG -
561 printf("%p QIODevice::close()\n", this); -
562#endif -
563 -
564#ifndef QT_NO_QOBJECT -
565 emit aboutToClose();
executed (the execution status of this line is deduced): aboutToClose();
-
566#endif -
567 d->openMode = NotOpen;
executed (the execution status of this line is deduced): d->openMode = NotOpen;
-
568 d->errorString.clear();
executed (the execution status of this line is deduced): d->errorString.clear();
-
569 d->pos = 0;
executed (the execution status of this line is deduced): d->pos = 0;
-
570 d->seqDumpPos = 0;
executed (the execution status of this line is deduced): d->seqDumpPos = 0;
-
571 d->buffer.clear();
executed (the execution status of this line is deduced): d->buffer.clear();
-
572 d->firstRead = true;
executed (the execution status of this line is deduced): d->firstRead = true;
-
573}
executed: }
Execution Count:22074
22074
574 -
575/*! -
576 For random-access devices, this function returns the position that -
577 data is written to or read from. For sequential devices or closed -
578 devices, where there is no concept of a "current position", 0 is -
579 returned. -
580 -
581 The current read/write position of the device is maintained internally by -
582 QIODevice, so reimplementing this function is not necessary. When -
583 subclassing QIODevice, use QIODevice::seek() to notify QIODevice about -
584 changes in the device position. -
585 -
586 \sa isSequential(), seek() -
587*/ -
588qint64 QIODevice::pos() const -
589{ -
590 Q_D(const QIODevice);
executed (the execution status of this line is deduced): const QIODevicePrivate * const d = d_func();
-
591#if defined QIODEVICE_DEBUG -
592 printf("%p QIODevice::pos() == %d\n", this, int(d->pos)); -
593#endif -
594 return d->pos;
executed: return d->pos;
Execution Count:460014
460014
595} -
596 -
597/*! -
598 For open random-access devices, this function returns the size of the -
599 device. For open sequential devices, bytesAvailable() is returned. -
600 -
601 If the device is closed, the size returned will not reflect the actual -
602 size of the device. -
603 -
604 \sa isSequential(), pos() -
605*/ -
606qint64 QIODevice::size() const -
607{ -
608 return d_func()->isSequential() ? bytesAvailable() : qint64(0);
executed: return d_func()->isSequential() ? bytesAvailable() : qint64(0);
Execution Count:69
69
609} -
610 -
611/*! -
612 For random-access devices, this function sets the current position -
613 to \a pos, returning true on success, or false if an error occurred. -
614 For sequential devices, the default behavior is to produce a warning -
615 and return false. -
616 -
617 When subclassing QIODevice, you must call QIODevice::seek() at the -
618 start of your function to ensure integrity with QIODevice's -
619 built-in buffer. -
620 -
621 \sa pos(), isSequential() -
622*/ -
623bool QIODevice::seek(qint64 pos) -
624{ -
625 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
626 if (d->isSequential()) {
evaluated: d->isSequential()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:262918
1-262918
627 qWarning("QIODevice::seek: Cannot call seek on a sequential device");
executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 627, __PRETTY_FUNCTION__).warning("QIODevice::seek: Cannot call seek on a sequential device");
-
628 return false;
executed: return false;
Execution Count:1
1
629 } -
630 if (d->openMode == NotOpen) {
partially evaluated: d->openMode == NotOpen
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:262918
0-262918
631 qWarning("QIODevice::seek: The device is not open");
never executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 631, __PRETTY_FUNCTION__).warning("QIODevice::seek: The device is not open");
-
632 return false;
never executed: return false;
0
633 } -
634 if (pos < 0) {
partially evaluated: pos < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:262918
0-262918
635 qWarning("QIODevice::seek: Invalid pos: %d", int(pos));
never executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 635, __PRETTY_FUNCTION__).warning("QIODevice::seek: Invalid pos: %d", int(pos));
-
636 return false;
never executed: return false;
0
637 } -
638 -
639#if defined QIODEVICE_DEBUG -
640 printf("%p QIODevice::seek(%d), before: d->pos = %d, d->buffer.size() = %d\n", -
641 this, int(pos), int(d->pos), d->buffer.size()); -
642#endif -
643 -
644 qint64 offset = pos - d->pos;
executed (the execution status of this line is deduced): qint64 offset = pos - d->pos;
-
645 d->pos = pos;
executed (the execution status of this line is deduced): d->pos = pos;
-
646 d->devicePos = pos;
executed (the execution status of this line is deduced): d->devicePos = pos;
-
647 -
648 if (offset < 0
evaluated: offset < 0
TRUEFALSE
yes
Evaluation Count:126245
yes
Evaluation Count:136673
126245-136673
649 || offset >= qint64(d->buffer.size()))
evaluated: offset >= qint64(d->buffer.size())
TRUEFALSE
yes
Evaluation Count:117886
yes
Evaluation Count:18787
18787-117886
650 // When seeking backwards, an operation that is only allowed for -
651 // random-access devices, the buffer is cleared. The next read -
652 // operation will then refill the buffer. We can optimize this, if we -
653 // find that seeking backwards becomes a significant performance hit. -
654 d->buffer.clear();
executed: d->buffer.clear();
Execution Count:244131
244131
655 else if (!d->buffer.isEmpty())
partially evaluated: !d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:18787
no
Evaluation Count:0
0-18787
656 d->buffer.skip(int(offset));
executed: d->buffer.skip(int(offset));
Execution Count:18787
18787
657 -
658#if defined QIODEVICE_DEBUG -
659 printf("%p \tafter: d->pos == %d, d->buffer.size() == %d\n", this, int(d->pos), -
660 d->buffer.size()); -
661#endif -
662 return true;
executed: return true;
Execution Count:262918
262918
663} -
664 -
665/*! -
666 Returns true if the current read and write position is at the end -
667 of the device (i.e. there is no more data available for reading on -
668 the device); otherwise returns false. -
669 -
670 For some devices, atEnd() can return true even though there is more data -
671 to read. This special case only applies to devices that generate data in -
672 direct response to you calling read() (e.g., \c /dev or \c /proc files on -
673 Unix and Mac OS X, or console input / \c stdin on all platforms). -
674 -
675 \sa bytesAvailable(), read(), isSequential() -
676*/ -
677bool QIODevice::atEnd() const -
678{ -
679 Q_D(const QIODevice);
executed (the execution status of this line is deduced): const QIODevicePrivate * const d = d_func();
-
680#if defined QIODEVICE_DEBUG -
681 printf("%p QIODevice::atEnd() returns %s, d->openMode == %d, d->pos == %d\n", this, (d->openMode == NotOpen || d->pos == size()) ? "true" : "false", -
682 int(d->openMode), int(d->pos)); -
683#endif -
684 return d->openMode == NotOpen || (d->buffer.isEmpty() && bytesAvailable() == 0);
executed: return d->openMode == NotOpen || (d->buffer.isEmpty() && bytesAvailable() == 0);
Execution Count:5530
5530
685} -
686 -
687/*! -
688 Seeks to the start of input for random-access devices. Returns -
689 true on success; otherwise returns false (for example, if the -
690 device is not open). -
691 -
692 Note that when using a QTextStream on a QFile, calling reset() on -
693 the QFile will not have the expected result because QTextStream -
694 buffers the file. Use the QTextStream::seek() function instead. -
695 -
696 \sa seek() -
697*/ -
698bool QIODevice::reset() -
699{ -
700#if defined QIODEVICE_DEBUG -
701 printf("%p QIODevice::reset()\n", this); -
702#endif -
703 return seek(0);
executed: return seek(0);
Execution Count:102
102
704} -
705 -
706/*! -
707 Returns the number of bytes that are available for reading. This -
708 function is commonly used with sequential devices to determine the -
709 number of bytes to allocate in a buffer before reading. -
710 -
711 Subclasses that reimplement this function must call the base -
712 implementation in order to include the size of QIODevices' buffer. Example: -
713 -
714 \snippet code/src_corelib_io_qiodevice.cpp 1 -
715 -
716 \sa bytesToWrite(), readyRead(), isSequential() -
717*/ -
718qint64 QIODevice::bytesAvailable() const -
719{ -
720 Q_D(const QIODevice);
executed (the execution status of this line is deduced): const QIODevicePrivate * const d = d_func();
-
721 if (!d->isSequential())
evaluated: !d->isSequential()
TRUEFALSE
yes
Evaluation Count:5587
yes
Evaluation Count:45931
5587-45931
722 return qMax(size() - d->pos, qint64(0));
executed: return qMax(size() - d->pos, qint64(0));
Execution Count:5587
5587
723 return d->buffer.size();
executed: return d->buffer.size();
Execution Count:45932
45932
724} -
725 -
726/*! -
727 For buffered devices, this function returns the number of bytes -
728 waiting to be written. For devices with no buffer, this function -
729 returns 0. -
730 -
731 \sa bytesAvailable(), bytesWritten(), isSequential() -
732*/ -
733qint64 QIODevice::bytesToWrite() const -
734{ -
735 return qint64(0);
never executed: return qint64(0);
0
736} -
737 -
738#ifdef Q_CC_RVCT -
739// arm mode makes the 64-bit integer operations much faster in RVCT 2.2 -
740#pragma push -
741#pragma arm -
742#endif -
743 -
744/*! -
745 Reads at most \a maxSize bytes from the device into \a data, and -
746 returns the number of bytes read. If an error occurs, such as when -
747 attempting to read from a device opened in WriteOnly mode, this -
748 function returns -1. -
749 -
750 0 is returned when no more data is available for reading. However, -
751 reading past the end of the stream is considered an error, so this -
752 function returns -1 in those cases (that is, reading on a closed -
753 socket or after a process has died). -
754 -
755 \sa readData(), readLine(), write() -
756*/ -
757qint64 QIODevice::read(char *data, qint64 maxSize) -
758{ -
759 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
760 -
761#if defined QIODEVICE_DEBUG -
762 printf("%p QIODevice::read(%p, %d), d->pos = %d, d->buffer.size() = %d\n", -
763 this, data, int(maxSize), int(d->pos), int(d->buffer.size())); -
764#endif -
765 -
766 // Short circuit for getChar() -
767 if (maxSize == 1) {
evaluated: maxSize == 1
TRUEFALSE
yes
Evaluation Count:43557679
yes
Evaluation Count:327886
327886-43557679
768 int chint;
executed (the execution status of this line is deduced): int chint;
-
769 while ((chint = d->buffer.getChar()) != -1) {
evaluated: (chint = d->buffer.getChar()) != -1
TRUEFALSE
yes
Evaluation Count:43410030
yes
Evaluation Count:147786
147786-43410030
770 ++(*d->pPos);
executed (the execution status of this line is deduced): ++(*d->pPos);
-
771 -
772 char c = char(uchar(chint));
executed (the execution status of this line is deduced): char c = char(uchar(chint));
-
773 if (c == '\r' && (d->openMode & Text))
evaluated: c == '\r'
TRUEFALSE
yes
Evaluation Count:16062
yes
Evaluation Count:43393968
evaluated: (d->openMode & Text)
TRUEFALSE
yes
Evaluation Count:137
yes
Evaluation Count:15925
137-43393968
774 continue;
executed: continue;
Execution Count:137
137
775 *data = c;
executed (the execution status of this line is deduced): *data = c;
-
776#if defined QIODEVICE_DEBUG -
777 printf("%p \tread 0x%hhx (%c) returning 1 (shortcut)\n", this, -
778 int(c), isprint(c) ? c : '?'); -
779#endif -
780 if (d->buffer.isEmpty())
evaluated: d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:2949
yes
Evaluation Count:43406944
2949-43406944
781 readData(data, 0);
executed: readData(data, 0);
Execution Count:2949
2949
782 return qint64(1);
executed: return qint64(1);
Execution Count:43409893
43409893
783 } -
784 }
executed: }
Execution Count:147786
147786
785 -
786 CHECK_MAXLEN(read, qint64(-1));
never executed: return qint64(-1);
executed: }
Execution Count:475672
partially evaluated: maxSize < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:475672
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:475672
0-475672
787 qint64 readSoFar = 0;
executed (the execution status of this line is deduced): qint64 readSoFar = 0;
-
788 bool moreToRead = true;
executed (the execution status of this line is deduced): bool moreToRead = true;
-
789 do { -
790 // Try reading from the buffer. -
791 int lastReadChunkSize = d->buffer.read(data, maxSize);
executed (the execution status of this line is deduced): int lastReadChunkSize = d->buffer.read(data, maxSize);
-
792 if (lastReadChunkSize > 0) {
evaluated: lastReadChunkSize > 0
TRUEFALSE
yes
Evaluation Count:216588
yes
Evaluation Count:259102
216588-259102
793 *d->pPos += lastReadChunkSize;
executed (the execution status of this line is deduced): *d->pPos += lastReadChunkSize;
-
794 readSoFar += lastReadChunkSize;
executed (the execution status of this line is deduced): readSoFar += lastReadChunkSize;
-
795 // fast exit when satisfied by buffer -
796 if (lastReadChunkSize == maxSize && !(d->openMode & Text)) {
evaluated: lastReadChunkSize == maxSize
TRUEFALSE
yes
Evaluation Count:197649
yes
Evaluation Count:18939
evaluated: !(d->openMode & Text)
TRUEFALSE
yes
Evaluation Count:197643
yes
Evaluation Count:6
6-197649
797 if (d->buffer.isEmpty()) {
evaluated: d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:6085
yes
Evaluation Count:191558
6085-191558
798 d->buffer.clear();
executed (the execution status of this line is deduced): d->buffer.clear();
-
799 readData(data, 0);
executed (the execution status of this line is deduced): readData(data, 0);
-
800 }
executed: }
Execution Count:6085
6085
801 return readSoFar;
executed: return readSoFar;
Execution Count:197643
197643
802 } -
803 -
804 data += lastReadChunkSize;
executed (the execution status of this line is deduced): data += lastReadChunkSize;
-
805 maxSize -= lastReadChunkSize;
executed (the execution status of this line is deduced): maxSize -= lastReadChunkSize;
-
806#if defined QIODEVICE_DEBUG -
807 printf("%p \treading %d bytes from buffer into position %d\n", this, lastReadChunkSize, -
808 int(readSoFar) - lastReadChunkSize); -
809#endif -
810 } else {
executed: }
Execution Count:18945
18945
811 if (d->firstRead) {
evaluated: d->firstRead
TRUEFALSE
yes
Evaluation Count:19231
yes
Evaluation Count:239871
19231-239871
812 // this is the first time the file has been read, check it's valid and set up pos pointers -
813 // for fast pos updates. -
814 CHECK_READABLE(read, qint64(-1));
executed: return qint64(-1);
Execution Count:25
executed: return qint64(-1);
Execution Count:2
executed: }
Execution Count:19205
evaluated: (d->openMode & ReadOnly) == 0
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:19204
evaluated: d->openMode == NotOpen
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:2
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19205
0-19205
815 d->firstRead = false;
executed (the execution status of this line is deduced): d->firstRead = false;
-
816 if (d->isSequential()) {
evaluated: d->isSequential()
TRUEFALSE
yes
Evaluation Count:2591
yes
Evaluation Count:16614
2591-16614
817 d->pPos = &d->seqDumpPos;
executed (the execution status of this line is deduced): d->pPos = &d->seqDumpPos;
-
818 d->pDevicePos = &d->seqDumpPos;
executed (the execution status of this line is deduced): d->pDevicePos = &d->seqDumpPos;
-
819 }
executed: }
Execution Count:2591
2591
820 }
executed: }
Execution Count:19205
19205
821 -
822 if (!maxSize)
evaluated: !maxSize
TRUEFALSE
yes
Evaluation Count:1961
yes
Evaluation Count:257115
1961-257115
823 return readSoFar;
executed: return readSoFar;
Execution Count:1961
1961
824 -
825 if ((d->openMode & Unbuffered) == 0 && maxSize < QIODEVICE_BUFFERSIZE) {
evaluated: (d->openMode & Unbuffered) == 0
TRUEFALSE
yes
Evaluation Count:118741
yes
Evaluation Count:138374
evaluated: maxSize < static_cast<long long>(16384LL)
TRUEFALSE
yes
Evaluation Count:103685
yes
Evaluation Count:15056
15056-138374
826 // In buffered mode, we try to fill up the QIODevice buffer before -
827 // we do anything else. -
828 // buffer is empty at this point, try to fill it -
829 int bytesToBuffer = QIODEVICE_BUFFERSIZE;
executed (the execution status of this line is deduced): int bytesToBuffer = static_cast<long long>(16384LL);
-
830 char *writePointer = d->buffer.reserve(bytesToBuffer);
executed (the execution status of this line is deduced): char *writePointer = d->buffer.reserve(bytesToBuffer);
-
831 -
832 // Make sure the device is positioned correctly. -
833 if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos))
evaluated: d->pos != d->devicePos
TRUEFALSE
yes
Evaluation Count:3357
yes
Evaluation Count:100328
evaluated: !d->isSequential()
TRUEFALSE
yes
Evaluation Count:420
yes
Evaluation Count:2937
partially evaluated: !seek(d->pos)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:420
0-100328
834 return readSoFar ? readSoFar : qint64(-1);
never executed: return readSoFar ? readSoFar : qint64(-1);
0
835 qint64 readFromDevice = readData(writePointer, bytesToBuffer);
executed (the execution status of this line is deduced): qint64 readFromDevice = readData(writePointer, bytesToBuffer);
-
836 d->buffer.chop(bytesToBuffer - (readFromDevice < 0 ? 0 : int(readFromDevice)));
executed (the execution status of this line is deduced): d->buffer.chop(bytesToBuffer - (readFromDevice < 0 ? 0 : int(readFromDevice)));
-
837 -
838 if (readFromDevice > 0) {
evaluated: readFromDevice > 0
TRUEFALSE
yes
Evaluation Count:39153
yes
Evaluation Count:64532
39153-64532
839 *d->pDevicePos += readFromDevice;
executed (the execution status of this line is deduced): *d->pDevicePos += readFromDevice;
-
840#if defined QIODEVICE_DEBUG -
841 printf("%p \treading %d from device into buffer\n", this, int(readFromDevice)); -
842#endif -
843 -
844 if (!d->buffer.isEmpty()) {
evaluated: !d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:39083
yes
Evaluation Count:70
70-39083
845 lastReadChunkSize = d->buffer.read(data, maxSize);
executed (the execution status of this line is deduced): lastReadChunkSize = d->buffer.read(data, maxSize);
-
846 readSoFar += lastReadChunkSize;
executed (the execution status of this line is deduced): readSoFar += lastReadChunkSize;
-
847 data += lastReadChunkSize;
executed (the execution status of this line is deduced): data += lastReadChunkSize;
-
848 maxSize -= lastReadChunkSize;
executed (the execution status of this line is deduced): maxSize -= lastReadChunkSize;
-
849 *d->pPos += lastReadChunkSize;
executed (the execution status of this line is deduced): *d->pPos += lastReadChunkSize;
-
850#if defined QIODEVICE_DEBUG -
851 printf("%p \treading %d bytes from buffer at position %d\n", this, -
852 lastReadChunkSize, int(readSoFar)); -
853#endif -
854 }
executed: }
Execution Count:39083
39083
855 }
executed: }
Execution Count:39153
39153
856 }
executed: }
Execution Count:103685
103685
857 }
executed: }
Execution Count:257115
257115
858 -
859 // If we need more, try reading from the device. -
860 if (maxSize > 0) {
evaluated: maxSize > 0
TRUEFALSE
yes
Evaluation Count:239414
yes
Evaluation Count:36646
36646-239414
861 // Make sure the device is positioned correctly. -
862 if (d->pos != d->devicePos && !d->isSequential() && !seek(d->pos))
evaluated: d->pos != d->devicePos
TRUEFALSE
yes
Evaluation Count:5340
yes
Evaluation Count:234073
evaluated: !d->isSequential()
TRUEFALSE
yes
Evaluation Count:491
yes
Evaluation Count:4849
partially evaluated: !seek(d->pos)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:491
0-234073
863 return readSoFar ? readSoFar : qint64(-1);
never executed: return readSoFar ? readSoFar : qint64(-1);
0
864 qint64 readFromDevice = readData(data, maxSize);
executed (the execution status of this line is deduced): qint64 readFromDevice = readData(data, maxSize);
-
865#if defined QIODEVICE_DEBUG -
866 printf("%p \treading %d bytes from device (total %d)\n", this, int(readFromDevice), int(readSoFar)); -
867#endif -
868 if (readFromDevice == -1 && readSoFar == 0) {
evaluated: readFromDevice == -1
TRUEFALSE
yes
Evaluation Count:4600
yes
Evaluation Count:234814
evaluated: readSoFar == 0
TRUEFALSE
yes
Evaluation Count:4590
yes
Evaluation Count:10
10-234814
869 // error and we haven't read anything: return immediately -
870 return -1;
executed: return -1;
Execution Count:4590
4590
871 } -
872 if (readFromDevice > 0) {
evaluated: readFromDevice > 0
TRUEFALSE
yes
Evaluation Count:149898
yes
Evaluation Count:84926
84926-149898
873 lastReadChunkSize += int(readFromDevice);
executed (the execution status of this line is deduced): lastReadChunkSize += int(readFromDevice);
-
874 readSoFar += readFromDevice;
executed (the execution status of this line is deduced): readSoFar += readFromDevice;
-
875 data += readFromDevice;
executed (the execution status of this line is deduced): data += readFromDevice;
-
876 maxSize -= readFromDevice;
executed (the execution status of this line is deduced): maxSize -= readFromDevice;
-
877 *d->pPos += readFromDevice;
executed (the execution status of this line is deduced): *d->pPos += readFromDevice;
-
878 *d->pDevicePos += readFromDevice;
executed (the execution status of this line is deduced): *d->pDevicePos += readFromDevice;
-
879 }
executed: }
Execution Count:149898
149898
880 }
executed: }
Execution Count:234824
234824
881 // Best attempt has been made to read data, don't try again except for text mode adjustment below -
882 moreToRead = false;
executed (the execution status of this line is deduced): moreToRead = false;
-
883 -
884 if (readSoFar && d->openMode & Text) {
evaluated: readSoFar
TRUEFALSE
yes
Evaluation Count:202502
yes
Evaluation Count:68968
evaluated: d->openMode & Text
TRUEFALSE
yes
Evaluation Count:824
yes
Evaluation Count:201678
824-202502
885 char *readPtr = data - lastReadChunkSize;
executed (the execution status of this line is deduced): char *readPtr = data - lastReadChunkSize;
-
886 const char *endPtr = data;
executed (the execution status of this line is deduced): const char *endPtr = data;
-
887 -
888 if (readPtr < endPtr) {
evaluated: readPtr < endPtr
TRUEFALSE
yes
Evaluation Count:808
yes
Evaluation Count:16
16-808
889 // optimization to avoid initial self-assignment -
890 while (*readPtr != '\r') {
evaluated: *readPtr != '\r'
TRUEFALSE
yes
Evaluation Count:2463955
yes
Evaluation Count:18
18-2463955
891 if (++readPtr == endPtr)
evaluated: ++readPtr == endPtr
TRUEFALSE
yes
Evaluation Count:790
yes
Evaluation Count:2463165
790-2463165
892 return readSoFar;
executed: return readSoFar;
Execution Count:790
790
893 }
executed: }
Execution Count:2463165
2463165
894 -
895 char *writePtr = readPtr;
executed (the execution status of this line is deduced): char *writePtr = readPtr;
-
896 -
897 while (readPtr < endPtr) {
evaluated: readPtr < endPtr
TRUEFALSE
yes
Evaluation Count:5253
yes
Evaluation Count:18
18-5253
898 char ch = *readPtr++;
executed (the execution status of this line is deduced): char ch = *readPtr++;
-
899 if (ch != '\r')
evaluated: ch != '\r'
TRUEFALSE
yes
Evaluation Count:5168
yes
Evaluation Count:85
85-5168
900 *writePtr++ = ch;
executed: *writePtr++ = ch;
Execution Count:5168
5168
901 else { -
902 --readSoFar;
executed (the execution status of this line is deduced): --readSoFar;
-
903 --data;
executed (the execution status of this line is deduced): --data;
-
904 ++maxSize;
executed (the execution status of this line is deduced): ++maxSize;
-
905 }
executed: }
Execution Count:85
85
906 } -
907 -
908 // Make sure we get more data if there is room for more. This -
909 // is very important for when someone seeks to the start of a -
910 // '\r\n' and reads one character - they should get the '\n'. -
911 moreToRead = (readPtr != writePtr);
executed (the execution status of this line is deduced): moreToRead = (readPtr != writePtr);
-
912 }
executed: }
Execution Count:18
18
913 }
executed: }
Execution Count:34
34
914 } while (moreToRead);
executed: }
Execution Count:270680
evaluated: moreToRead
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:270662
18-270680
915 -
916#if defined QIODEVICE_DEBUG -
917 printf("%p \treturning %d, d->pos == %d, d->buffer.size() == %d\n", this, -
918 int(readSoFar), int(d->pos), d->buffer.size()); -
919 debugBinaryString(data - readSoFar, readSoFar); -
920#endif -
921 -
922 if (d->buffer.isEmpty())
evaluated: d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:239931
yes
Evaluation Count:30731
30731-239931
923 readData(data, 0);
executed: readData(data, 0);
Execution Count:239931
239931
924 -
925 return readSoFar;
executed: return readSoFar;
Execution Count:270662
270662
926} -
927 -
928#ifdef Q_CC_RVCT -
929#pragma pop -
930#endif -
931 -
932/*! -
933 \overload -
934 -
935 Reads at most \a maxSize bytes from the device, and returns the -
936 data read as a QByteArray. -
937 -
938 This function has no way of reporting errors; returning an empty -
939 QByteArray() can mean either that no data was currently available -
940 for reading, or that an error occurred. -
941*/ -
942QByteArray QIODevice::read(qint64 maxSize) -
943{ -
944 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
945 QByteArray result;
executed (the execution status of this line is deduced): QByteArray result;
-
946 -
947 CHECK_MAXLEN(read, result);
never executed: return result;
executed: }
Execution Count:49464
partially evaluated: maxSize < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49464
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49464
0-49464
948 -
949#if defined QIODEVICE_DEBUG -
950 printf("%p QIODevice::read(%d), d->pos = %d, d->buffer.size() = %d\n", -
951 this, int(maxSize), int(d->pos), int(d->buffer.size())); -
952#else -
953 Q_UNUSED(d);
executed (the execution status of this line is deduced): (void)d;;
-
954#endif -
955 -
956 if (maxSize != qint64(int(maxSize))) {
partially evaluated: maxSize != qint64(int(maxSize))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49464
0-49464
957 qWarning("QIODevice::read: maxSize argument exceeds QByteArray size limit");
never executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 957, __PRETTY_FUNCTION__).warning("QIODevice::read: maxSize argument exceeds QByteArray size limit");
-
958 maxSize = INT_MAX;
never executed (the execution status of this line is deduced): maxSize = 2147483647;
-
959 }
never executed: }
0
960 -
961 qint64 readBytes = 0;
executed (the execution status of this line is deduced): qint64 readBytes = 0;
-
962 if (maxSize) {
evaluated: maxSize
TRUEFALSE
yes
Evaluation Count:49463
yes
Evaluation Count:1
1-49463
963 result.resize(int(maxSize));
executed (the execution status of this line is deduced): result.resize(int(maxSize));
-
964 if (!result.size()) {
partially evaluated: !result.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49463
0-49463
965 // If resize fails, read incrementally. -
966 qint64 readResult;
never executed (the execution status of this line is deduced): qint64 readResult;
-
967 do { -
968 result.resize(int(qMin(maxSize, result.size() + QIODEVICE_BUFFERSIZE)));
never executed (the execution status of this line is deduced): result.resize(int(qMin(maxSize, result.size() + static_cast<long long>(16384LL))));
-
969 readResult = read(result.data() + readBytes, result.size() - readBytes);
never executed (the execution status of this line is deduced): readResult = read(result.data() + readBytes, result.size() - readBytes);
-
970 if (readResult > 0 || readBytes == 0)
never evaluated: readResult > 0
never evaluated: readBytes == 0
0
971 readBytes += readResult;
never executed: readBytes += readResult;
0
972 } while (readResult == QIODEVICE_BUFFERSIZE);
never executed: }
never evaluated: readResult == static_cast<long long>(16384LL)
0
973 } else {
never executed: }
0
974 readBytes = read(result.data(), result.size());
executed (the execution status of this line is deduced): readBytes = read(result.data(), result.size());
-
975 }
executed: }
Execution Count:49463
49463
976 } -
977 -
978 if (readBytes <= 0)
evaluated: readBytes <= 0
TRUEFALSE
yes
Evaluation Count:93
yes
Evaluation Count:49371
93-49371
979 result.clear();
executed: result.clear();
Execution Count:93
93
980 else -
981 result.resize(int(readBytes));
executed: result.resize(int(readBytes));
Execution Count:49371
49371
982 -
983 return result;
executed: return result;
Execution Count:49464
49464
984} -
985 -
986/*! -
987 \overload -
988 -
989 Reads all available data from the device, and returns it as a -
990 QByteArray. -
991 -
992 This function has no way of reporting errors; returning an empty -
993 QByteArray() can mean either that no data was currently available -
994 for reading, or that an error occurred. -
995*/ -
996QByteArray QIODevice::readAll() -
997{ -
998 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
999#if defined QIODEVICE_DEBUG -
1000 printf("%p QIODevice::readAll(), d->pos = %d, d->buffer.size() = %d\n", -
1001 this, int(d->pos), int(d->buffer.size())); -
1002#endif -
1003 -
1004 QByteArray result;
executed (the execution status of this line is deduced): QByteArray result;
-
1005 qint64 readBytes = 0;
executed (the execution status of this line is deduced): qint64 readBytes = 0;
-
1006 -
1007 // flush internal read buffer -
1008 if (!(d->openMode & Text) && !d->buffer.isEmpty()) {
evaluated: !(d->openMode & Text)
TRUEFALSE
yes
Evaluation Count:9519
yes
Evaluation Count:606
evaluated: !d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:1373
yes
Evaluation Count:8146
606-9519
1009 result = d->buffer.readAll();
executed (the execution status of this line is deduced): result = d->buffer.readAll();
-
1010 readBytes = result.size();
executed (the execution status of this line is deduced): readBytes = result.size();
-
1011 d->pos += readBytes;
executed (the execution status of this line is deduced): d->pos += readBytes;
-
1012 }
executed: }
Execution Count:1373
1373
1013 -
1014 qint64 theSize;
executed (the execution status of this line is deduced): qint64 theSize;
-
1015 if (d->isSequential() || (theSize = size()) == 0) {
evaluated: d->isSequential()
TRUEFALSE
yes
Evaluation Count:3665
yes
Evaluation Count:6460
evaluated: (theSize = size()) == 0
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:6440
20-6460
1016 // Size is unknown, read incrementally. -
1017 qint64 readResult;
executed (the execution status of this line is deduced): qint64 readResult;
-
1018 do { -
1019 result.resize(result.size() + QIODEVICE_BUFFERSIZE);
executed (the execution status of this line is deduced): result.resize(result.size() + static_cast<long long>(16384LL));
-
1020 readResult = read(result.data() + readBytes, result.size() - readBytes);
executed (the execution status of this line is deduced): readResult = read(result.data() + readBytes, result.size() - readBytes);
-
1021 if (readResult > 0 || readBytes == 0)
evaluated: readResult > 0
TRUEFALSE
yes
Evaluation Count:1887
yes
Evaluation Count:3685
evaluated: readBytes == 0
TRUEFALSE
yes
Evaluation Count:923
yes
Evaluation Count:2762
923-3685
1022 readBytes += readResult;
executed: readBytes += readResult;
Execution Count:2810
2810
1023 } while (readResult > 0);
executed: }
Execution Count:5572
evaluated: readResult > 0
TRUEFALSE
yes
Evaluation Count:1887
yes
Evaluation Count:3685
1887-5572
1024 } else {
executed: }
Execution Count:3685
3685
1025 // Read it all in one go. -
1026 // If resize fails, don't read anything. -
1027 result.resize(int(readBytes + theSize - d->pos));
executed (the execution status of this line is deduced): result.resize(int(readBytes + theSize - d->pos));
-
1028 readBytes += read(result.data() + readBytes, result.size() - readBytes);
executed (the execution status of this line is deduced): readBytes += read(result.data() + readBytes, result.size() - readBytes);
-
1029 }
executed: }
Execution Count:6440
6440
1030 -
1031 if (readBytes <= 0)
evaluated: readBytes <= 0
TRUEFALSE
yes
Evaluation Count:2144
yes
Evaluation Count:7981
2144-7981
1032 result.clear();
executed: result.clear();
Execution Count:2144
2144
1033 else -
1034 result.resize(int(readBytes));
executed: result.resize(int(readBytes));
Execution Count:7981
7981
1035 -
1036 return result;
executed: return result;
Execution Count:10125
10125
1037} -
1038 -
1039#ifdef Q_CC_RVCT -
1040// arm mode makes the 64-bit integer operations much faster in RVCT 2.2 -
1041#pragma push -
1042#pragma arm -
1043#endif -
1044 -
1045/*! -
1046 This function reads a line of ASCII characters from the device, up -
1047 to a maximum of \a maxSize - 1 bytes, stores the characters in \a -
1048 data, and returns the number of bytes read. If a line could not be -
1049 read but no error ocurred, this function returns 0. If an error -
1050 occurs, this function returns the length of what could be read, or -
1051 -1 if nothing was read. -
1052 -
1053 A terminating '\\0' byte is always appended to \a data, so \a -
1054 maxSize must be larger than 1. -
1055 -
1056 Data is read until either of the following conditions are met: -
1057 -
1058 \list -
1059 \li The first '\\n' character is read. -
1060 \li \a maxSize - 1 bytes are read. -
1061 \li The end of the device data is detected. -
1062 \endlist -
1063 -
1064 For example, the following code reads a line of characters from a -
1065 file: -
1066 -
1067 \snippet code/src_corelib_io_qiodevice.cpp 2 -
1068 -
1069 The newline character ('\\n') is included in the buffer. If a -
1070 newline is not encountered before maxSize - 1 bytes are read, a -
1071 newline will not be inserted into the buffer. On windows newline -
1072 characters are replaced with '\\n'. -
1073 -
1074 This function calls readLineData(), which is implemented using -
1075 repeated calls to getChar(). You can provide a more efficient -
1076 implementation by reimplementing readLineData() in your own -
1077 subclass. -
1078 -
1079 \sa getChar(), read(), write() -
1080*/ -
1081qint64 QIODevice::readLine(char *data, qint64 maxSize) -
1082{ -
1083 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
1084 if (maxSize < 2) {
evaluated: maxSize < 2
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:77493
5-77493
1085 qWarning("QIODevice::readLine: Called with maxSize < 2");
executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 1085, __PRETTY_FUNCTION__).warning("QIODevice::readLine: Called with maxSize < 2");
-
1086 return qint64(-1);
executed: return qint64(-1);
Execution Count:5
5
1087 } -
1088 -
1089#if defined QIODEVICE_DEBUG -
1090 printf("%p QIODevice::readLine(%p, %d), d->pos = %d, d->buffer.size() = %d\n", -
1091 this, data, int(maxSize), int(d->pos), int(d->buffer.size())); -
1092#endif -
1093 -
1094 // Leave room for a '\0' -
1095 --maxSize;
executed (the execution status of this line is deduced): --maxSize;
-
1096 -
1097 const bool sequential = d->isSequential();
executed (the execution status of this line is deduced): const bool sequential = d->isSequential();
-
1098 -
1099 qint64 readSoFar = 0;
executed (the execution status of this line is deduced): qint64 readSoFar = 0;
-
1100 if (!d->buffer.isEmpty()) {
evaluated: !d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:77057
yes
Evaluation Count:436
436-77057
1101 readSoFar = d->buffer.readLine(data, maxSize);
executed (the execution status of this line is deduced): readSoFar = d->buffer.readLine(data, maxSize);
-
1102 if (d->buffer.isEmpty())
evaluated: d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:1223
yes
Evaluation Count:75834
1223-75834
1103 readData(data,0);
executed: readData(data,0);
Execution Count:1223
1223
1104 if (!sequential)
evaluated: !sequential
TRUEFALSE
yes
Evaluation Count:75882
yes
Evaluation Count:1175
1175-75882
1105 d->pos += readSoFar;
executed: d->pos += readSoFar;
Execution Count:75882
75882
1106#if defined QIODEVICE_DEBUG -
1107 printf("%p \tread from buffer: %d bytes, last character read: %hhx\n", this, -
1108 int(readSoFar), data[int(readSoFar) - 1]); -
1109 if (readSoFar) -
1110 debugBinaryString(data, int(readSoFar)); -
1111#endif -
1112 if (readSoFar && data[readSoFar - 1] == '\n') {
partially evaluated: readSoFar
TRUEFALSE
yes
Evaluation Count:77057
no
Evaluation Count:0
evaluated: data[readSoFar - 1] == '\n'
TRUEFALSE
yes
Evaluation Count:76407
yes
Evaluation Count:650
0-77057
1113 if (d->openMode & Text) {
evaluated: d->openMode & Text
TRUEFALSE
yes
Evaluation Count:163
yes
Evaluation Count:76244
163-76244
1114 // QRingBuffer::readLine() isn't Text aware. -
1115 if (readSoFar > 1 && data[readSoFar - 2] == '\r') {
partially evaluated: readSoFar > 1
TRUEFALSE
yes
Evaluation Count:163
no
Evaluation Count:0
evaluated: data[readSoFar - 2] == '\r'
TRUEFALSE
yes
Evaluation Count:161
yes
Evaluation Count:2
0-163
1116 --readSoFar;
executed (the execution status of this line is deduced): --readSoFar;
-
1117 data[readSoFar - 1] = '\n';
executed (the execution status of this line is deduced): data[readSoFar - 1] = '\n';
-
1118 }
executed: }
Execution Count:161
161
1119 }
executed: }
Execution Count:163
163
1120 data[readSoFar] = '\0';
executed (the execution status of this line is deduced): data[readSoFar] = '\0';
-
1121 return readSoFar;
executed: return readSoFar;
Execution Count:76407
76407
1122 } -
1123 }
executed: }
Execution Count:650
650
1124 -
1125 if (d->pos != d->devicePos && !sequential && !seek(d->pos))
evaluated: d->pos != d->devicePos
TRUEFALSE
yes
Evaluation Count:65
yes
Evaluation Count:1021
evaluated: !sequential
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:1
partially evaluated: !seek(d->pos)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:64
0-1021
1126 return qint64(-1);
never executed: return qint64(-1);
0
1127 d->baseReadLineDataCalled = false;
executed (the execution status of this line is deduced): d->baseReadLineDataCalled = false;
-
1128 qint64 readBytes = readLineData(data + readSoFar, maxSize - readSoFar);
executed (the execution status of this line is deduced): qint64 readBytes = readLineData(data + readSoFar, maxSize - readSoFar);
-
1129#if defined QIODEVICE_DEBUG -
1130 printf("%p \tread from readLineData: %d bytes, readSoFar = %d bytes\n", this, -
1131 int(readBytes), int(readSoFar)); -
1132 if (readBytes > 0) { -
1133 debugBinaryString(data, int(readSoFar + readBytes)); -
1134 } -
1135#endif -
1136 if (readBytes < 0) {
evaluated: readBytes < 0
TRUEFALSE
yes
Evaluation Count:355
yes
Evaluation Count:731
355-731
1137 data[readSoFar] = '\0';
executed (the execution status of this line is deduced): data[readSoFar] = '\0';
-
1138 return readSoFar ? readSoFar : -1;
executed: return readSoFar ? readSoFar : -1;
Execution Count:355
355
1139 } -
1140 readSoFar += readBytes;
executed (the execution status of this line is deduced): readSoFar += readBytes;
-
1141 if (!d->baseReadLineDataCalled && !sequential) {
partially evaluated: !d->baseReadLineDataCalled
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:731
never evaluated: !sequential
0-731
1142 d->pos += readBytes;
never executed (the execution status of this line is deduced): d->pos += readBytes;
-
1143 // If the base implementation was not called, then we must -
1144 // assume the device position is invalid and force a seek. -
1145 d->devicePos = qint64(-1);
never executed (the execution status of this line is deduced): d->devicePos = qint64(-1);
-
1146 }
never executed: }
0
1147 data[readSoFar] = '\0';
executed (the execution status of this line is deduced): data[readSoFar] = '\0';
-
1148 -
1149 if (d->openMode & Text) {
evaluated: d->openMode & Text
TRUEFALSE
yes
Evaluation Count:178
yes
Evaluation Count:553
178-553
1150 if (readSoFar > 1 && data[readSoFar - 1] == '\n' && data[readSoFar - 2] == '\r') {
partially evaluated: readSoFar > 1
TRUEFALSE
yes
Evaluation Count:178
no
Evaluation Count:0
evaluated: data[readSoFar - 1] == '\n'
TRUEFALSE
yes
Evaluation Count:146
yes
Evaluation Count:32
partially evaluated: data[readSoFar - 2] == '\r'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:146
0-178
1151 data[readSoFar - 2] = '\n';
never executed (the execution status of this line is deduced): data[readSoFar - 2] = '\n';
-
1152 data[readSoFar - 1] = '\0';
never executed (the execution status of this line is deduced): data[readSoFar - 1] = '\0';
-
1153 --readSoFar;
never executed (the execution status of this line is deduced): --readSoFar;
-
1154 }
never executed: }
0
1155 }
executed: }
Execution Count:178
178
1156 -
1157#if defined QIODEVICE_DEBUG -
1158 printf("%p \treturning %d, d->pos = %d, d->buffer.size() = %d, size() = %d\n", -
1159 this, int(readSoFar), int(d->pos), d->buffer.size(), int(size())); -
1160 debugBinaryString(data, int(readSoFar)); -
1161#endif -
1162 return readSoFar;
executed: return readSoFar;
Execution Count:731
731
1163} -
1164 -
1165/*! -
1166 \overload -
1167 -
1168 Reads a line from the device, but no more than \a maxSize characters, -
1169 and returns the result as a QByteArray. -
1170 -
1171 This function has no way of reporting errors; returning an empty -
1172 QByteArray() can mean either that no data was currently available -
1173 for reading, or that an error occurred. -
1174*/ -
1175QByteArray QIODevice::readLine(qint64 maxSize) -
1176{ -
1177 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
1178 QByteArray result;
executed (the execution status of this line is deduced): QByteArray result;
-
1179 -
1180 CHECK_MAXLEN(readLine, result);
never executed: return result;
executed: }
Execution Count:21432
partially evaluated: maxSize < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21432
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21432
0-21432
1181 -
1182#if defined QIODEVICE_DEBUG -
1183 printf("%p QIODevice::readLine(%d), d->pos = %d, d->buffer.size() = %d\n", -
1184 this, int(maxSize), int(d->pos), int(d->buffer.size())); -
1185#else -
1186 Q_UNUSED(d);
executed (the execution status of this line is deduced): (void)d;;
-
1187#endif -
1188 -
1189 if (maxSize > INT_MAX) {
partially evaluated: maxSize > 2147483647
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21432
0-21432
1190 qWarning("QIODevice::read: maxSize argument exceeds QByteArray size limit");
never executed (the execution status of this line is deduced): QMessageLogger("io/qiodevice.cpp", 1190, __PRETTY_FUNCTION__).warning("QIODevice::read: maxSize argument exceeds QByteArray size limit");
-
1191 maxSize = INT_MAX;
never executed (the execution status of this line is deduced): maxSize = 2147483647;
-
1192 }
never executed: }
0
1193 -
1194 result.resize(int(maxSize));
executed (the execution status of this line is deduced): result.resize(int(maxSize));
-
1195 qint64 readBytes = 0;
executed (the execution status of this line is deduced): qint64 readBytes = 0;
-
1196 if (!result.size()) {
evaluated: !result.size()
TRUEFALSE
yes
Evaluation Count:21423
yes
Evaluation Count:9
9-21423
1197 // If resize fails or maxSize == 0, read incrementally -
1198 if (maxSize == 0)
partially evaluated: maxSize == 0
TRUEFALSE
yes
Evaluation Count:21423
no
Evaluation Count:0
0-21423
1199 maxSize = INT_MAX;
executed: maxSize = 2147483647;
Execution Count:21423
21423
1200 -
1201 // The first iteration needs to leave an extra byte for the terminating null -
1202 result.resize(1);
executed (the execution status of this line is deduced): result.resize(1);
-
1203 -
1204 qint64 readResult;
executed (the execution status of this line is deduced): qint64 readResult;
-
1205 do { -
1206 result.resize(int(qMin(maxSize, result.size() + QIODEVICE_BUFFERSIZE)));
executed (the execution status of this line is deduced): result.resize(int(qMin(maxSize, result.size() + static_cast<long long>(16384LL))));
-
1207 readResult = readLine(result.data() + readBytes, result.size() - readBytes);
executed (the execution status of this line is deduced): readResult = readLine(result.data() + readBytes, result.size() - readBytes);
-
1208 if (readResult > 0 || readBytes == 0)
evaluated: readResult > 0
TRUEFALSE
yes
Evaluation Count:21406
yes
Evaluation Count:85
partially evaluated: readBytes == 0
TRUEFALSE
yes
Evaluation Count:85
no
Evaluation Count:0
0-21406
1209 readBytes += readResult;
executed: readBytes += readResult;
Execution Count:21491
21491
1210 } while (readResult == QIODEVICE_BUFFERSIZE
executed: }
Execution Count:21491
evaluated: readResult == static_cast<long long>(16384LL)
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:21415
76-21491
1211 && result[int(readBytes - 1)] != '\n');
evaluated: result[int(readBytes - 1)] != '\n'
TRUEFALSE
yes
Evaluation Count:68
yes
Evaluation Count:8
8-68
1212 } else
executed: }
Execution Count:21423
21423
1213 readBytes = readLine(result.data(), result.size());
executed: readBytes = readLine(result.data(), result.size());
Execution Count:9
9
1214 -
1215 if (readBytes <= 0)
evaluated: readBytes <= 0
TRUEFALSE
yes
Evaluation Count:85
yes
Evaluation Count:21347
85-21347
1216 result.clear();
executed: result.clear();
Execution Count:85
85
1217 else -
1218 result.resize(readBytes);
executed: result.resize(readBytes);
Execution Count:21347
21347
1219 -
1220 return result;
executed: return result;
Execution Count:21432
21432
1221} -
1222 -
1223/*! -
1224 Reads up to \a maxSize characters into \a data and returns the -
1225 number of characters read. -
1226 -
1227 This function is called by readLine(), and provides its base -
1228 implementation, using getChar(). Buffered devices can improve the -
1229 performance of readLine() by reimplementing this function. -
1230 -
1231 readLine() appends a '\\0' byte to \a data; readLineData() does not -
1232 need to do this. -
1233 -
1234 If you reimplement this function, be careful to return the correct -
1235 value: it should return the number of bytes read in this line, -
1236 including the terminating newline, or 0 if there is no line to be -
1237 read at this point. If an error occurs, it should return -1 if and -
1238 only if no bytes were read. Reading past EOF is considered an error. -
1239*/ -
1240qint64 QIODevice::readLineData(char *data, qint64 maxSize) -
1241{ -
1242 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
1243 qint64 readSoFar = 0;
executed (the execution status of this line is deduced): qint64 readSoFar = 0;
-
1244 char c;
executed (the execution status of this line is deduced): char c;
-
1245 int lastReadReturn = 0;
executed (the execution status of this line is deduced): int lastReadReturn = 0;
-
1246 d->baseReadLineDataCalled = true;
executed (the execution status of this line is deduced): d->baseReadLineDataCalled = true;
-
1247 -
1248 while (readSoFar < maxSize && (lastReadReturn = read(&c, 1)) == 1) {
evaluated: readSoFar < maxSize
TRUEFALSE
yes
Evaluation Count:837125
yes
Evaluation Count:87
evaluated: (lastReadReturn = read(&c, 1)) == 1
TRUEFALSE
yes
Evaluation Count:836792
yes
Evaluation Count:333
87-837125
1249 *data++ = c;
executed (the execution status of this line is deduced): *data++ = c;
-
1250 ++readSoFar;
executed (the execution status of this line is deduced): ++readSoFar;
-
1251 if (c == '\n')
evaluated: c == '\n'
TRUEFALSE
yes
Evaluation Count:658
yes
Evaluation Count:836134
658-836134
1252 break;
executed: break;
Execution Count:658
658
1253 }
executed: }
Execution Count:836134
836134
1254 -
1255#if defined QIODEVICE_DEBUG -
1256 printf("%p QIODevice::readLineData(%p, %d), d->pos = %d, d->buffer.size() = %d, returns %d\n", -
1257 this, data, int(maxSize), int(d->pos), int(d->buffer.size()), int(readSoFar)); -
1258#endif -
1259 if (lastReadReturn != 1 && readSoFar == 0)
evaluated: lastReadReturn != 1
TRUEFALSE
yes
Evaluation Count:350
yes
Evaluation Count:728
evaluated: readSoFar == 0
TRUEFALSE
yes
Evaluation Count:349
yes
Evaluation Count:1
1-728
1260 return isSequential() ? lastReadReturn : -1;
executed: return isSequential() ? lastReadReturn : -1;
Execution Count:349
349
1261 return readSoFar;
executed: return readSoFar;
Execution Count:729
729
1262} -
1263 -
1264#ifdef Q_CC_RVCT -
1265#pragma pop -
1266#endif -
1267 -
1268/*! -
1269 Returns true if a complete line of data can be read from the device; -
1270 otherwise returns false. -
1271 -
1272 Note that unbuffered devices, which have no way of determining what -
1273 can be read, always return false. -
1274 -
1275 This function is often called in conjunction with the readyRead() -
1276 signal. -
1277 -
1278 Subclasses that reimplement this function must call the base -
1279 implementation in order to include the contents of the QIODevice's buffer. Example: -
1280 -
1281 \snippet code/src_corelib_io_qiodevice.cpp 3 -
1282 -
1283 \sa readyRead(), readLine() -
1284*/ -
1285bool QIODevice::canReadLine() const -
1286{ -
1287 return d_func()->buffer.canReadLine();
executed: return d_func()->buffer.canReadLine();
Execution Count:586
586
1288} -
1289 -
1290/*! -
1291 Writes at most \a maxSize bytes of data from \a data to the -
1292 device. Returns the number of bytes that were actually written, or -
1293 -1 if an error occurred. -
1294 -
1295 \sa read(), writeData() -
1296*/ -
1297qint64 QIODevice::write(const char *data, qint64 maxSize) -
1298{ -
1299 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
1300 CHECK_WRITABLE(write, qint64(-1));
executed: return qint64(-1);
Execution Count:2
executed: return qint64(-1);
Execution Count:1
executed: }
Execution Count:1577757
evaluated: (d->openMode & WriteOnly) == 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1577757
evaluated: d->openMode == NotOpen
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1577757
0-1577757
1301 CHECK_MAXLEN(write, qint64(-1));
never executed: return qint64(-1);
executed: }
Execution Count:1577757
partially evaluated: maxSize < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1577757
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1577757
0-1577757
1302 -
1303 const bool sequential = d->isSequential();
executed (the execution status of this line is deduced): const bool sequential = d->isSequential();
-
1304 // Make sure the device is positioned correctly. -
1305 if (d->pos != d->devicePos && !sequential && !seek(d->pos))
evaluated: d->pos != d->devicePos
TRUEFALSE
yes
Evaluation Count:12956
yes
Evaluation Count:1564801
evaluated: !sequential
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12910
partially evaluated: !seek(d->pos)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-1564801
1306 return qint64(-1);
never executed: return qint64(-1);
0
1307 -
1308#ifdef Q_OS_WIN -
1309 if (d->openMode & Text) { -
1310 const char *endOfData = data + maxSize; -
1311 const char *startOfBlock = data; -
1312 -
1313 qint64 writtenSoFar = 0; -
1314 -
1315 forever { -
1316 const char *endOfBlock = startOfBlock; -
1317 while (endOfBlock < endOfData && *endOfBlock != '\n') -
1318 ++endOfBlock; -
1319 -
1320 qint64 blockSize = endOfBlock - startOfBlock; -
1321 if (blockSize > 0) { -
1322 qint64 ret = writeData(startOfBlock, blockSize); -
1323 if (ret <= 0) { -
1324 if (writtenSoFar && !sequential) -
1325 d->buffer.skip(writtenSoFar); -
1326 return writtenSoFar ? writtenSoFar : ret; -
1327 } -
1328 if (!sequential) { -
1329 d->pos += ret; -
1330 d->devicePos += ret; -
1331 } -
1332 writtenSoFar += ret; -
1333 } -
1334 -
1335 if (endOfBlock == endOfData) -
1336 break; -
1337 -
1338 qint64 ret = writeData("\r\n", 2); -
1339 if (ret <= 0) { -
1340 if (writtenSoFar && !sequential) -
1341 d->buffer.skip(writtenSoFar); -
1342 return writtenSoFar ? writtenSoFar : ret; -
1343 } -
1344 if (!sequential) { -
1345 d->pos += ret; -
1346 d->devicePos += ret; -
1347 } -
1348 ++writtenSoFar; -
1349 -
1350 startOfBlock = endOfBlock + 1; -
1351 } -
1352 -
1353 if (writtenSoFar && !sequential) -
1354 d->buffer.skip(writtenSoFar); -
1355 return writtenSoFar; -
1356 } -
1357#endif -
1358 -
1359 qint64 written = writeData(data, maxSize);
executed (the execution status of this line is deduced): qint64 written = writeData(data, maxSize);
-
1360 if (written > 0) {
evaluated: written > 0
TRUEFALSE
yes
Evaluation Count:1575555
yes
Evaluation Count:2202
2202-1575555
1361 if (!sequential) {
evaluated: !sequential
TRUEFALSE
yes
Evaluation Count:274402
yes
Evaluation Count:1301153
274402-1301153
1362 d->pos += written;
executed (the execution status of this line is deduced): d->pos += written;
-
1363 d->devicePos += written;
executed (the execution status of this line is deduced): d->devicePos += written;
-
1364 }
executed: }
Execution Count:274402
274402
1365 if (!d->buffer.isEmpty() && !sequential)
evaluated: !d->buffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:1575544
evaluated: !sequential
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
2-1575544
1366 d->buffer.skip(written);
executed: d->buffer.skip(written);
Execution Count:2
2
1367 }
executed: }
Execution Count:1575555
1575555
1368 return written;
executed: return written;
Execution Count:1577757
1577757
1369} -
1370 -
1371/*! -
1372 \since 4.5 -
1373 -
1374 \overload -
1375 -
1376 Writes data from a zero-terminated string of 8-bit characters to the -
1377 device. Returns the number of bytes that were actually written, or -
1378 -1 if an error occurred. This is equivalent to -
1379 \code -
1380 ... -
1381 QIODevice::write(data, qstrlen(data)); -
1382 ... -
1383 \endcode -
1384 -
1385 \sa read(), writeData() -
1386*/ -
1387qint64 QIODevice::write(const char *data) -
1388{ -
1389 return write(data, qstrlen(data));
executed: return write(data, qstrlen(data));
Execution Count:2913
2913
1390} -
1391 -
1392/*! \fn qint64 QIODevice::write(const QByteArray &byteArray) -
1393 -
1394 \overload -
1395 -
1396 Writes the content of \a byteArray to the device. Returns the number of -
1397 bytes that were actually written, or -1 if an error occurred. -
1398 -
1399 \sa read(), writeData() -
1400*/ -
1401 -
1402/*! -
1403 Puts the character \a c back into the device, and decrements the -
1404 current position unless the position is 0. This function is -
1405 usually called to "undo" a getChar() operation, such as when -
1406 writing a backtracking parser. -
1407 -
1408 If \a c was not previously read from the device, the behavior is -
1409 undefined. -
1410*/ -
1411void QIODevice::ungetChar(char c) -
1412{ -
1413 Q_D(QIODevice);
executed (the execution status of this line is deduced): QIODevicePrivate * const d = d_func();
-
1414 CHECK_READABLE(read, Q_VOID);
never executed: return ;
never executed: return ;
executed: }
Execution Count:36147
partially evaluated: (d->openMode & ReadOnly) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36147
never evaluated: d->openMode == NotOpen
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36147
0-36147
1415 -
1416#if defined QIODEVICE_DEBUG -
1417 printf("%p QIODevice::ungetChar(0x%hhx '%c')\n", this, c, isprint(c) ? c : '?'); -
1418#endif -
1419 -
1420 d->buffer.ungetChar(c);
executed (the execution status of this line is deduced): d->buffer.ungetChar(c);
-
1421 if (!d->isSequential())
evaluated: !d->isSequential()
TRUEFALSE
yes
Evaluation Count:35697
yes
Evaluation Count:450
450-35697
1422 --d->pos;
executed: --d->pos;
Execution Count:35697
35697
1423}
executed: }
Execution Count:36147
36147
1424 -
1425/*! \fn bool QIODevice::putChar(char c) -
1426 -
1427 Writes the character \a c to the device. Returns true on success; -
1428 otherwise returns false. -
1429 -
1430 \sa write(), getChar(), ungetChar() -
1431*/ -
1432bool QIODevice::putChar(char c) -
1433{ -
1434 return d_func()->putCharHelper(c);
executed: return d_func()->putCharHelper(c);
Execution Count:18740
18740
1435} -
1436 -
1437/*! -
1438 \internal -
1439*/ -
1440bool QIODevicePrivate::putCharHelper(char c) -
1441{ -
1442 return q_func()->write(&c, 1) == 1;
executed: return q_func()->write(&c, 1) == 1;
Execution Count:17436
17436
1443} -
1444 -
1445/*! -
1446 \internal -
1447*/ -
1448qint64 QIODevicePrivate::peek(char *data, qint64 maxSize) -
1449{ -
1450 qint64 readBytes = q_func()->read(data, maxSize);
executed (the execution status of this line is deduced): qint64 readBytes = q_func()->read(data, maxSize);
-
1451 if (readBytes <= 0)
evaluated: readBytes <= 0
TRUEFALSE
yes
Evaluation Count:680
yes
Evaluation Count:4506
680-4506
1452 return readBytes;
executed: return readBytes;
Execution Count:680
680
1453 -
1454 buffer.ungetBlock(data, readBytes);
executed (the execution status of this line is deduced): buffer.ungetBlock(data, readBytes);
-
1455 *pPos -= readBytes;
executed (the execution status of this line is deduced): *pPos -= readBytes;
-
1456 return readBytes;
executed: return readBytes;
Execution Count:4506
4506
1457} -
1458 -
1459/*! -
1460 \internal -
1461*/ -
1462QByteArray QIODevicePrivate::peek(qint64 maxSize) -
1463{ -
1464 QByteArray result = q_func()->read(maxSize);
executed (the execution status of this line is deduced): QByteArray result = q_func()->read(maxSize);
-
1465 -
1466 if (result.isEmpty())
evaluated: result.isEmpty()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:533
7-533
1467 return result;
executed: return result;
Execution Count:7
7
1468 -
1469 buffer.ungetBlock(result.constData(), result.size());
executed (the execution status of this line is deduced): buffer.ungetBlock(result.constData(), result.size());
-
1470 *pPos -= result.size();
executed (the execution status of this line is deduced): *pPos -= result.size();
-
1471 return result;
executed: return result;
Execution Count:533
533
1472} -
1473 -
1474/*! \fn bool QIODevice::getChar(char *c) -
1475 -
1476 Reads one character from the device and stores it in \a c. If \a c -
1477 is 0, the character is discarded. Returns true on success; -
1478 otherwise returns false. -
1479 -
1480 \sa read(), putChar(), ungetChar() -
1481*/ -
1482bool QIODevice::getChar(char *c) -
1483{ -
1484 // readability checked in read() -
1485 char ch;
executed (the execution status of this line is deduced): char ch;
-
1486 return (1 == read(c ? c : &ch, 1));
executed: return (1 == read(c ? c : &ch, 1));
Execution Count:1466285
1466285
1487} -
1488 -
1489/*! -
1490 \since 4.1 -
1491 -
1492 Reads at most \a maxSize bytes from the device into \a data, without side -
1493 effects (i.e., if you call read() after peek(), you will get the same -
1494 data). Returns the number of bytes read. If an error occurs, such as -
1495 when attempting to peek a device opened in WriteOnly mode, this function -
1496 returns -1. -
1497 -
1498 0 is returned when no more data is available for reading. -
1499 -
1500 Example: -
1501 -
1502 \snippet code/src_corelib_io_qiodevice.cpp 4 -
1503 -
1504 \sa read() -
1505*/ -
1506qint64 QIODevice::peek(char *data, qint64 maxSize) -
1507{ -
1508 return d_func()->peek(data, maxSize);
executed: return d_func()->peek(data, maxSize);
Execution Count:6634
6634
1509} -
1510 -
1511/*! -
1512 \since 4.1 -
1513 \overload -
1514 -
1515 Peeks at most \a maxSize bytes from the device, returning the data peeked -
1516 as a QByteArray. -
1517 -
1518 Example: -
1519 -
1520 \snippet code/src_corelib_io_qiodevice.cpp 5 -
1521 -
1522 This function has no way of reporting errors; returning an empty -
1523 QByteArray() can mean either that no data was currently available -
1524 for peeking, or that an error occurred. -
1525 -
1526 \sa read() -
1527*/ -
1528QByteArray QIODevice::peek(qint64 maxSize) -
1529{ -
1530 return d_func()->peek(maxSize);
executed: return d_func()->peek(maxSize);
Execution Count:724
724
1531} -
1532 -
1533/*! -
1534 Blocks until new data is available for reading and the readyRead() -
1535 signal has been emitted, or until \a msecs milliseconds have -
1536 passed. If msecs is -1, this function will not time out. -
1537 -
1538 Returns true if new data is available for reading; otherwise returns -
1539 false (if the operation timed out or if an error occurred). -
1540 -
1541 This function can operate without an event loop. It is -
1542 useful when writing non-GUI applications and when performing -
1543 I/O operations in a non-GUI thread. -
1544 -
1545 If called from within a slot connected to the readyRead() signal, -
1546 readyRead() will not be reemitted. -
1547 -
1548 Reimplement this function to provide a blocking API for a custom -
1549 device. The default implementation does nothing, and returns false. -
1550 -
1551 \warning Calling this function from the main (GUI) thread -
1552 might cause your user interface to freeze. -
1553 -
1554 \sa waitForBytesWritten() -
1555*/ -
1556bool QIODevice::waitForReadyRead(int msecs) -
1557{ -
1558 Q_UNUSED(msecs);
executed (the execution status of this line is deduced): (void)msecs;;
-
1559 return false;
executed: return false;
Execution Count:325
325
1560} -
1561 -
1562/*! -
1563 For buffered devices, this function waits until a payload of -
1564 buffered written data has been written to the device and the -
1565 bytesWritten() signal has been emitted, or until \a msecs -
1566 milliseconds have passed. If msecs is -1, this function will -
1567 not time out. For unbuffered devices, it returns immediately. -
1568 -
1569 Returns true if a payload of data was written to the device; -
1570 otherwise returns false (i.e. if the operation timed out, or if an -
1571 error occurred). -
1572 -
1573 This function can operate without an event loop. It is -
1574 useful when writing non-GUI applications and when performing -
1575 I/O operations in a non-GUI thread. -
1576 -
1577 If called from within a slot connected to the bytesWritten() signal, -
1578 bytesWritten() will not be reemitted. -
1579 -
1580 Reimplement this function to provide a blocking API for a custom -
1581 device. The default implementation does nothing, and returns false. -
1582 -
1583 \warning Calling this function from the main (GUI) thread -
1584 might cause your user interface to freeze. -
1585 -
1586 \sa waitForReadyRead() -
1587*/ -
1588bool QIODevice::waitForBytesWritten(int msecs) -
1589{ -
1590 Q_UNUSED(msecs);
never executed (the execution status of this line is deduced): (void)msecs;;
-
1591 return false;
never executed: return false;
0
1592} -
1593 -
1594/*! -
1595 Sets the human readable description of the last device error that -
1596 occurred to \a str. -
1597 -
1598 \sa errorString() -
1599*/ -
1600void QIODevice::setErrorString(const QString &str) -
1601{ -
1602 d_func()->errorString = str;
executed (the execution status of this line is deduced): d_func()->errorString = str;
-
1603}
executed: }
Execution Count:1693
1693
1604 -
1605/*! -
1606 Returns a human-readable description of the last device error that -
1607 occurred. -
1608 -
1609 \sa setErrorString() -
1610*/ -
1611QString QIODevice::errorString() const -
1612{ -
1613 Q_D(const QIODevice);
executed (the execution status of this line is deduced): const QIODevicePrivate * const d = d_func();
-
1614 if (d->errorString.isEmpty()) {
evaluated: d->errorString.isEmpty()
TRUEFALSE
yes
Evaluation Count:3061
yes
Evaluation Count:388
388-3061
1615#ifdef QT_NO_QOBJECT -
1616 return QLatin1String(QT_TRANSLATE_NOOP(QIODevice, "Unknown error")); -
1617#else -
1618 return tr("Unknown error");
executed: return tr("Unknown error");
Execution Count:3061
3061
1619#endif -
1620 } -
1621 return d->errorString;
executed: return d->errorString;
Execution Count:388
388
1622} -
1623 -
1624/*! -
1625 \fn qint64 QIODevice::readData(char *data, qint64 maxSize) -
1626 -
1627 Reads up to \a maxSize bytes from the device into \a data, and -
1628 returns the number of bytes read or -1 if an error occurred. -
1629 -
1630 If there are no bytes to be read and there can never be more bytes -
1631 available (examples include socket closed, pipe closed, sub-process -
1632 finished), this function returns -1. -
1633 -
1634 This function is called by QIODevice. Reimplement this function -
1635 when creating a subclass of QIODevice. -
1636 -
1637 When reimplementing this function it is important that this function -
1638 reads all the required data before returning. This is required in order -
1639 for QDataStream to be able to operate on the class. QDataStream assumes -
1640 all the requested information was read and therefore does not retry reading -
1641 if there was a problem. -
1642 -
1643 This function might be called with a maxSize of 0, which can be used to -
1644 perform post-reading operations. -
1645 -
1646 \sa read(), readLine(), writeData() -
1647*/ -
1648 -
1649/*! -
1650 \fn qint64 QIODevice::writeData(const char *data, qint64 maxSize) -
1651 -
1652 Writes up to \a maxSize bytes from \a data to the device. Returns -
1653 the number of bytes written, or -1 if an error occurred. -
1654 -
1655 This function is called by QIODevice. Reimplement this function -
1656 when creating a subclass of QIODevice. -
1657 -
1658 When reimplementing this function it is important that this function -
1659 writes all the data available before returning. This is required in order -
1660 for QDataStream to be able to operate on the class. QDataStream assumes -
1661 all the information was written and therefore does not retry writing if -
1662 there was a problem. -
1663 -
1664 \sa read(), write() -
1665*/ -
1666 -
1667 -
1668#if !defined(QT_NO_DEBUG_STREAM) -
1669QDebug operator<<(QDebug debug, QIODevice::OpenMode modes) -
1670{ -
1671 debug << "OpenMode(";
never executed (the execution status of this line is deduced): debug << "OpenMode(";
-
1672 QStringList modeList;
never executed (the execution status of this line is deduced): QStringList modeList;
-
1673 if (modes == QIODevice::NotOpen) {
never evaluated: modes == QIODevice::NotOpen
0
1674 modeList << QLatin1String("NotOpen");
never executed (the execution status of this line is deduced): modeList << QLatin1String("NotOpen");
-
1675 } else {
never executed: }
0
1676 if (modes & QIODevice::ReadOnly)
never evaluated: modes & QIODevice::ReadOnly
0
1677 modeList << QLatin1String("ReadOnly");
never executed: modeList << QLatin1String("ReadOnly");
0
1678 if (modes & QIODevice::WriteOnly)
never evaluated: modes & QIODevice::WriteOnly
0
1679 modeList << QLatin1String("WriteOnly");
never executed: modeList << QLatin1String("WriteOnly");
0
1680 if (modes & QIODevice::Append)
never evaluated: modes & QIODevice::Append
0
1681 modeList << QLatin1String("Append");
never executed: modeList << QLatin1String("Append");
0
1682 if (modes & QIODevice::Truncate)
never evaluated: modes & QIODevice::Truncate
0
1683 modeList << QLatin1String("Truncate");
never executed: modeList << QLatin1String("Truncate");
0
1684 if (modes & QIODevice::Text)
never evaluated: modes & QIODevice::Text
0
1685 modeList << QLatin1String("Text");
never executed: modeList << QLatin1String("Text");
0
1686 if (modes & QIODevice::Unbuffered)
never evaluated: modes & QIODevice::Unbuffered
0
1687 modeList << QLatin1String("Unbuffered");
never executed: modeList << QLatin1String("Unbuffered");
0
1688 }
never executed: }
0
1689 qSort(modeList);
never executed (the execution status of this line is deduced): qSort(modeList);
-
1690 debug << modeList.join(QLatin1Char('|'));
never executed (the execution status of this line is deduced): debug << modeList.join(QLatin1Char('|'));
-
1691 debug << ')';
never executed (the execution status of this line is deduced): debug << ')';
-
1692 return debug;
never executed: return debug;
0
1693} -
1694#endif -
1695 -
1696QT_END_NAMESPACE -
1697 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial