diff options
author | Peter Hartmann <peter.hartmann@trolltech.com> | 2009-04-16 13:14:09 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@trolltech.com> | 2009-04-16 14:12:38 (GMT) |
commit | b43b57b251505157f32463094a9ac7c41ab69859 (patch) | |
tree | c258c768964902c64516dd3b12588cb909acb7dc /src | |
parent | 5c359a9b599e2024d070534c10c5a0e224eca5d8 (diff) | |
download | Qt-b43b57b251505157f32463094a9ac7c41ab69859.zip Qt-b43b57b251505157f32463094a9ac7c41ab69859.tar.gz Qt-b43b57b251505157f32463094a9ac7c41ab69859.tar.bz2 |
fix reading problem on 64-bit machines in QProcess and socket engine
QProcessPrivate and QNativeSocketEnginePrivate were reporting a wrong
number of bytes available on 64-bit machines, due to use of size_t in
ioctl. That was required by Irix, which we dropped support for, so we
can also drop size_t
Reviewed-by: Thiago
Task-number: 249537
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_inotify.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 8 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine_unix.cpp | 19 |
3 files changed, 7 insertions, 22 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 4445e3c..fa44531 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -316,7 +316,7 @@ void QInotifyFileSystemWatcherEngine::readFromInotify() // qDebug() << "QInotifyFileSystemWatcherEngine::readFromInotify"; int buffSize = 0; - ioctl(inotifyFd, FIONREAD, &buffSize); + ioctl(inotifyFd, FIONREAD, (char *) &buffSize); QVarLengthArray<char, 4096> buffer(buffSize); buffSize = read(inotifyFd, buffer.data(), buffSize); const char *at = buffer.data(); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 37173c8..33d4a47 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -850,10 +850,10 @@ bool QProcessPrivate::processStarted() qint64 QProcessPrivate::bytesAvailableFromStdout() const { - size_t nbytes = 0; + int nbytes = 0; qint64 available = 0; if (::ioctl(stdoutChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0) - available = (qint64) *((int *) &nbytes); + available = (qint64) nbytes; #if defined (QPROCESS_DEBUG) qDebug("QProcessPrivate::bytesAvailableFromStdout() == %lld", available); #endif @@ -862,10 +862,10 @@ qint64 QProcessPrivate::bytesAvailableFromStdout() const qint64 QProcessPrivate::bytesAvailableFromStderr() const { - size_t nbytes = 0; + int nbytes = 0; qint64 available = 0; if (::ioctl(stderrChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0) - available = (qint64) *((int *) &nbytes); + available = (qint64) nbytes; #if defined (QPROCESS_DEBUG) qDebug("QProcessPrivate::bytesAvailableFromStderr() == %lld", available); #endif diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 73f6f84..cc372a6 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -506,26 +506,11 @@ int QNativeSocketEnginePrivate::nativeAccept() qint64 QNativeSocketEnginePrivate::nativeBytesAvailable() const { - /* - Apparently, there is not consistency among different operating - systems on how to use FIONREAD. - - FreeBSD, Linux and Solaris all expect the 3rd argument to - ioctl() to be an int, which is normally 32-bit even on 64-bit - machines. - - IRIX, on the other hand, expects a size_t, which is 64-bit on - 64-bit machines. - - So, the solution is to use size_t initialized to zero to make - sure all bits are set to zero, preventing underflow with the - FreeBSD/Linux/Solaris ioctls. - */ - size_t nbytes = 0; + int nbytes = 0; // gives shorter than true amounts on Unix domain sockets. qint64 available = 0; if (::ioctl(socketDescriptor, FIONREAD, (char *) &nbytes) >= 0) - available = (qint64) *((int *) &nbytes); + available = (qint64) nbytes; #if defined (QNATIVESOCKETENGINE_DEBUG) qDebug("QNativeSocketEnginePrivate::nativeBytesAvailable() == %lli", available); |