diff options
author | dimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7> | 2000-12-03 19:13:07 (GMT) |
---|---|---|
committer | dimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7> | 2000-12-03 19:13:07 (GMT) |
commit | fe67b8eb68129713327965c201f2d7226b83202f (patch) | |
tree | 485fb83c5a301dd4b0edb3c534b1f31eeb08ab1f /qtools/qfile_unix.cpp | |
parent | a30c2e3c5ea41ae1947e9893c82ed8c8b6d7c5a2 (diff) | |
download | Doxygen-fe67b8eb68129713327965c201f2d7226b83202f.zip Doxygen-fe67b8eb68129713327965c201f2d7226b83202f.tar.gz Doxygen-fe67b8eb68129713327965c201f2d7226b83202f.tar.bz2 |
Release-1.2.3-20001203
Diffstat (limited to 'qtools/qfile_unix.cpp')
-rw-r--r-- | qtools/qfile_unix.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/qtools/qfile_unix.cpp b/qtools/qfile_unix.cpp index 5c27988..e074eed 100644 --- a/qtools/qfile_unix.cpp +++ b/qtools/qfile_unix.cpp @@ -236,7 +236,7 @@ bool QFile::open( int m ) } else { length = (int)st.st_size; ioIndex = (flags() & IO_Append) == 0 ? 0 : length; - if ( (flags() & !IO_Truncate) && length == 0 && isReadable() ) { + if ( !(flags()&IO_Truncate) && length == 0 && isReadable() ) { // try if you can read from it (if you can, it's a sequential // device; e.g. a file in the /proc filesystem) int c = getch(); @@ -300,13 +300,13 @@ bool QFile::open( int m, FILE *f ) STATBUF st; FSTAT( FILENO(fh), &st ); ioIndex = (int)ftell( fh ); - if ( (st.st_mode & STAT_MASK) != STAT_REG ) { + if ( (st.st_mode & STAT_MASK) != STAT_REG || f == stdin ) { //stdin is non seekable // non-seekable setType( IO_Sequential ); length = INT_MAX; } else { length = (int)st.st_size; - if ( (flags() & !IO_Truncate) && length == 0 && isReadable() ) { + if ( !(flags()&IO_Truncate) && length == 0 && isReadable() ) { // try if you can read from it (if you can, it's a sequential // device; e.g. a file in the /proc filesystem) int c = getch(); @@ -350,7 +350,7 @@ bool QFile::open( int m, int f ) STATBUF st; FSTAT( fd, &st ); ioIndex = (int)LSEEK(fd, 0, SEEK_CUR); - if ( (st.st_mode & STAT_MASK) != STAT_REG ) { + if ( (st.st_mode & STAT_MASK) != STAT_REG || f == 0 ) { // stdin is not seekable... // non-seekable setType( IO_Sequential ); length = INT_MAX; @@ -365,6 +365,7 @@ bool QFile::open( int m, int f ) setType( IO_Sequential ); length = INT_MAX; } + resetStatus(); } } return TRUE; @@ -466,18 +467,31 @@ int QFile::readBlock( char *p, uint len ) return -1; } #endif - int nread; // number of bytes read - if ( isRaw() ) { // raw file - nread = READ( fd, p, len ); - if ( len && nread <= 0 ) { - nread = 0; - setStatus(IO_ReadError); + int nread = 0; // number of bytes read + if ( !ungetchBuffer.isEmpty() ) { + // need to add these to the returned string. + int l = ungetchBuffer.length(); + while( nread < l ) { + *p = ungetchBuffer[ l - nread - 1 ]; + p++; + nread++; } - } else { // buffered file - nread = fread( p, 1, len, fh ); - if ( (uint)nread != len ) { - if ( ferror( fh ) || nread==0 ) + ungetchBuffer.truncate( l - nread ); + } + + if ( nread < (int)len ) { + if ( isRaw() ) { // raw file + nread += READ( fd, p, len-nread ); + if ( len && nread <= 0 ) { + nread = 0; setStatus(IO_ReadError); + } + } else { // buffered file + nread += fread( p, 1, len-nread, fh ); + if ( (uint)nread != len ) { + if ( ferror( fh ) || nread==0 ) + setStatus(IO_ReadError); + } } } ioIndex += nread; |