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.
This commit is contained in:
espie 2006-10-18 18:05:31 +00:00
parent c982708c91
commit d88890e2cf
3 changed files with 135 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.63 2006/09/18 10:21:49 espie Exp $
# $OpenBSD: Makefile,v 1.64 2006/10/18 18:05:31 espie Exp $
# $FreeBSD: Makefile,v 1.33 1999/02/27 03:09:57 andreas Exp $
COMMENT= "C++ X11 GUI toolkit"
@ -11,9 +11,9 @@ PKGNAME= qt3-${VERSION}
PKGNAME-mysql= qt3-mysql-${VERSION}p1
PKGNAME-postgresql= qt3-postgresql-${VERSION}p1
PKGNAME-examples= qt3-examples-${VERSION}
FULLPKGNAME= qt3-mt-${VERSION}p6${PKGDEBUG}
FULLPKGNAME= qt3-mt-${VERSION}p7${PKGDEBUG}
FULLPKGNAME-html= qt3-html-${VERSION}
SHARED_LIBS= qt-mt 30.0 \
SHARED_LIBS= qt-mt 30.1 \
qui 2.0 \
qui-mt 2.0

View File

@ -0,0 +1,77 @@
$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--;

View File

@ -0,0 +1,55 @@
$OpenBSD: patch-src_tools_qfile_unix_cpp,v 1.1 2006/10/18 18:05:31 espie Exp $
--- src/tools/qfile_unix.cpp.orig Wed Oct 18 13:23:15 2006
+++ src/tools/qfile_unix.cpp Wed Oct 18 13:36:59 2006
@@ -53,6 +53,17 @@ static inline int qt_open(const char *pa
#include <errno.h>
#include <limits.h>
+class QFilePrivate
+{
+public:
+ QString errorString;
+ int lastAccess;
+};
+
+#define ACCESS_NONE -1
+#define ACCESS_READ 0
+#define ACCESS_WRITE 1
+
extern const char* qt_fileerr_read;
bool qt_file_access( const QString& fn, int t )
@@ -522,6 +533,7 @@ bool QFile::at( Offset pos )
#else
ok = ( ::fseek(fh, pos, SEEK_SET) == 0 );
#endif
+ d->lastAccess = ACCESS_NONE;
}
if ( ok )
#if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_QT4)
@@ -590,6 +602,10 @@ Q_LONG QFile::readBlock( char *p, Q_ULON
setErrorStringErrno( errno );
}
} else { // buffered file
+ if (d->lastAccess == ACCESS_WRITE) {
+ ::fseek(fh, 0, SEEK_CUR);
+ d->lastAccess = ACCESS_READ;
+ }
nread += fread( p, 1, len-nread, fh );
if ( (uint)nread != len ) {
if ( ferror( fh ) || nread==0 ) {
@@ -641,8 +657,13 @@ Q_LONG QFile::writeBlock( const char *p,
Q_ULONG nwritten; // number of bytes written
if ( isRaw() ) // raw file
nwritten = ::write( fd, (void *)p, len );
- else // buffered file
+ else { // buffered file
+ if (d->lastAccess == ACCESS_READ) {
+ ::fseek(fh, 0, SEEK_CUR);
+ d->lastAccess = ACCESS_WRITE;
+ }
nwritten = fwrite( p, 1, len, fh );
+ }
if ( nwritten != len ) { // write error
if ( errno == ENOSPC ) // disk is full
setStatus( IO_ResourceError );