summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r--src/corelib/io/qiodevice.cpp58
1 files changed, 25 insertions, 33 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 5630a8b226..b0029e2af7 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -9,50 +9,42 @@
#include "qfile.h"
#include "qstringlist.h"
#include "qdir.h"
-#include "private/qbytearray_p.h"
+#include "private/qtools_p.h"
#include <algorithm>
-#ifdef QIODEVICE_DEBUG
-# include <ctype.h>
-#endif
-
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
-#ifdef QIODEVICE_DEBUG
-void debugBinaryString(const QByteArray &input)
+[[maybe_unused]]
+static void debugBinaryString(const char *input, qint64 maxlen)
{
QByteArray tmp;
- int startOffset = 0;
- for (int i = 0; i < input.size(); ++i) {
+ qlonglong startOffset = 0;
+ for (qint64 i = 0; i < maxlen; ++i) {
tmp += input[i];
- if ((i % 16) == 15 || i == (input.size() - 1)) {
- printf("\n%15d:", startOffset);
+ if ((i % 16) == 15 || i == (maxlen - 1)) {
+ printf("\n%15lld:", startOffset);
startOffset += tmp.size();
- for (int j = 0; j < tmp.size(); ++j)
+ for (qsizetype j = 0; j < tmp.size(); ++j)
printf(" %02x", int(uchar(tmp[j])));
- for (int j = tmp.size(); j < 16 + 1; ++j)
+ for (qsizetype j = tmp.size(); j < 16 + 1; ++j)
printf(" ");
- for (int j = 0; j < tmp.size(); ++j)
- printf("%c", isprint(int(uchar(tmp[j]))) ? tmp[j] : '.');
+ for (qsizetype j = 0; j < tmp.size(); ++j)
+ printf("%c", isAsciiPrintable(tmp[j]) ? tmp[j] : '.');
tmp.clear();
}
}
printf("\n\n");
}
-void debugBinaryString(const char *data, qint64 maxlen)
-{
- debugBinaryString(QByteArray(data, maxlen));
-}
-#endif
-
#define Q_VOID
+Q_DECL_COLD_FUNCTION
static void checkWarnMessage(const QIODevice *device, const char *function, const char *what)
{
#ifndef QT_NO_WARNING_OUTPUT
@@ -96,9 +88,9 @@ static void checkWarnMessage(const QIODevice *device, const char *function, cons
#define CHECK_MAXBYTEARRAYSIZE(function) \
do { \
- if (maxSize >= MaxByteArraySize) { \
+ if (maxSize >= QByteArray::max_size()) { \
checkWarnMessage(this, #function, "maxSize argument exceeds QByteArray size limit"); \
- maxSize = MaxByteArraySize - 1; \
+ maxSize = QByteArray::max_size() - 1; \
} \
} while (0)
@@ -1017,7 +1009,7 @@ qint64 QIODevice::read(char *data, qint64 maxSize)
*data = c;
#if defined QIODEVICE_DEBUG
printf("%p \tread 0x%hhx (%c) returning 1 (shortcut)\n", this,
- int(c), isprint(c) ? c : '?');
+ int(c), isAsciiPrintable(c) ? c : '?');
#endif
if (d->buffer.isEmpty())
readData(data, 0);
@@ -1250,7 +1242,7 @@ QByteArray QIODevice::readAll()
: d->buffer.size());
qint64 readResult;
do {
- if (readBytes + readChunkSize >= MaxByteArraySize) {
+ if (readBytes + readChunkSize >= QByteArray::max_size()) {
// If resize would fail, don't read more, return what we have.
break;
}
@@ -1264,8 +1256,8 @@ QByteArray QIODevice::readAll()
} else {
// Read it all in one go.
readBytes -= d->pos;
- if (readBytes >= MaxByteArraySize)
- readBytes = MaxByteArraySize;
+ if (readBytes >= QByteArray::max_size())
+ readBytes = QByteArray::max_size();
result.resize(readBytes);
readBytes = d->read(result.data(), readBytes);
}
@@ -1334,7 +1326,7 @@ qint64 QIODevice::readLine(char *data, qint64 maxSize)
#if defined QIODEVICE_DEBUG
printf("%p \treturning %lld, d->pos = %lld, d->buffer.size() = %lld, size() = %lld\n",
this, readBytes, d->pos, d->buffer.size(), size());
- debugBinaryString(data, qsizetype(readBytes));
+ debugBinaryString(data, readBytes);
#endif
return readBytes;
@@ -1378,7 +1370,7 @@ qint64 QIODevicePrivate::readLine(char *data, qint64 maxSize)
#if defined QIODEVICE_DEBUG
printf("%p \tread from buffer: %lld bytes, last character read: %hhx\n", q,
readSoFar, data[readSoFar - 1]);
- debugBinaryString(data, qsizetype(readSoFar));
+ debugBinaryString(data, readSoFar);
#endif
if (data[readSoFar - 1] == '\n') {
if (openMode & QIODevice::Text) {
@@ -1405,7 +1397,7 @@ qint64 QIODevicePrivate::readLine(char *data, qint64 maxSize)
printf("%p \tread from readLineData: %lld bytes, readSoFar = %lld bytes\n", q,
readBytes, readSoFar);
if (readBytes > 0) {
- debugBinaryString(data, qsizetype(readSoFar + readBytes));
+ debugBinaryString(data, readSoFar + readBytes);
}
#endif
if (readBytes < 0) {
@@ -1456,7 +1448,7 @@ QByteArray QIODevice::readLine(qint64 maxSize)
qint64 readBytes = 0;
if (maxSize == 0) {
// Size is unknown, read incrementally.
- maxSize = MaxByteArraySize - 1;
+ maxSize = QByteArray::max_size() - 1;
// The first iteration needs to leave an extra byte for the terminating null
result.resize(1);
@@ -1508,7 +1500,7 @@ qint64 QIODevice::readLineData(char *data, qint64 maxSize)
Q_D(QIODevice);
qint64 readSoFar = 0;
char c;
- int lastReadReturn = 0;
+ qint64 lastReadReturn = 0;
d->baseReadLineDataCalled = true;
while (readSoFar < maxSize && (lastReadReturn = read(&c, 1)) == 1) {
@@ -1798,7 +1790,7 @@ void QIODevice::ungetChar(char c)
}
#if defined QIODEVICE_DEBUG
- printf("%p QIODevice::ungetChar(0x%hhx '%c')\n", this, c, isprint(c) ? c : '?');
+ printf("%p QIODevice::ungetChar(0x%hhx '%c')\n", this, c, isAsciiPrintable(c) ? c : '?');
#endif
d->buffer.ungetChar(c);