openbsd-ports/x11/qt3/patches/patch-src_tools_qfile_cpp
espie d88890e2cf Let qfile synch IO between read and write by using fflush, a bit like qt4
does.

This is hidden behind a pimpl, so there's no ABI change.

This should allow people to use QDataStream for input AND output with
impunity.
2006-10-18 18:05:31 +00:00

78 lines
2.1 KiB
Plaintext

$OpenBSD: patch-src_tools_qfile_cpp,v 1.1 2006/10/18 18:05:31 espie Exp $
--- src/tools/qfile.cpp.orig Wed Oct 18 13:21:33 2006
+++ src/tools/qfile.cpp Wed Oct 18 13:35:35 2006
@@ -70,8 +70,13 @@ class QFilePrivate
{
public:
QString errorString;
+ int lastAccess;
};
+#define ACCESS_NONE -1
+#define ACCESS_READ 0
+#define ACCESS_WRITE 1
+
extern bool qt_file_access( const QString& fn, int t );
/*!
@@ -196,6 +201,7 @@ void QFile::init()
{
delete d;
d = new QFilePrivate;
+ d->lastAccess = ACCESS_NONE;
setFlags( IO_Direct );
setStatus( IO_Ok );
setErrorString( qt_fileerr_unknown );
@@ -206,7 +212,6 @@ void QFile::init()
ext_f = FALSE; // not an external file handle
}
-
/*!
\fn QString QFile::name() const
@@ -375,6 +380,10 @@ Q_LONG QFile::readLine( char *p, Q_ULONG
if ( isRaw() ) { // raw file
nread = QIODevice::readLine( p, maxlen );
} else { // buffered file
+ if (d->lastAccess == ACCESS_WRITE) {
+ ::fseek(fh, 0, SEEK_CUR);
+ d->lastAccess = ACCESS_READ;
+ }
p = fgets( p, maxlen, fh );
if ( p ) {
nread = qstrlen( p );
@@ -456,6 +465,10 @@ int QFile::getch()
char buf[1];
ch = readBlock( buf, 1 ) == 1 ? buf[0] : EOF;
} else { // buffered file
+ if (d->lastAccess == ACCESS_WRITE) {
+ ::fseek(fh, 0, SEEK_CUR);
+ d->lastAccess = ACCESS_READ;
+ }
if ( (ch = getc( fh )) != EOF ) {
if ( !isSequentialAccess() )
ioIndex++;
@@ -492,6 +505,10 @@ int QFile::putch( int ch )
buf[0] = ch;
ch = writeBlock( buf, 1 ) == 1 ? ch : EOF;
} else { // buffered file
+ if (d->lastAccess == ACCESS_READ) {
+ ::fseek(fh, 0, SEEK_CUR);
+ d->lastAccess = ACCESS_WRITE;
+ }
if ( (ch = putc( ch, fh )) != EOF ) {
if ( !isSequentialAccess() )
ioIndex++;
@@ -546,6 +563,10 @@ int QFile::ungetch( int ch )
else
ch = EOF;
} else { // buffered file
+ if (d->lastAccess == ACCESS_WRITE) {
+ ::fseek(fh, 0, SEEK_CUR);
+ d->lastAccess = ACCESS_READ;
+ }
if ( (ch = ungetc(ch, fh)) != EOF ) {
if ( !isSequentialAccess() )
ioIndex--;