summaryrefslogtreecommitdiff
path: root/qmake/tools/qbuffer.cpp
Side-by-side diff
Diffstat (limited to 'qmake/tools/qbuffer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qbuffer.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/qmake/tools/qbuffer.cpp b/qmake/tools/qbuffer.cpp
index b213dd9..0fc90e4 100644
--- a/qmake/tools/qbuffer.cpp
+++ b/qmake/tools/qbuffer.cpp
@@ -103,194 +103,194 @@ QBuffer::QBuffer()
QCString str = "abc";
QBuffer b( str );
b.open( IO_WriteOnly );
b.at( 3 ); // position at the 4th character (the terminating \0)
b.writeBlock( "def", 4 ); // write "def" including the terminating \0
b.close();
// Now, str == "abcdef" with a terminating \0
\endcode
\sa setBuffer()
*/
QBuffer::QBuffer( QByteArray buf ) : a(buf)
{
setFlags( IO_Direct );
a_len = a.size();
a_inc = (a_len > 512) ? 512 : a_len; // initial increment
if ( a_inc < 16 )
a_inc = 16;
ioIndex = 0;
}
/*!
Destroys the buffer.
*/
QBuffer::~QBuffer()
{
}
/*!
Replaces the buffer's contents with \a buf and returns TRUE.
Does nothing (and returns FALSE) if isOpen() is TRUE.
Note that if you open the buffer in write mode (\c IO_WriteOnly or
IO_ReadWrite) and write something into the buffer, \a buf is also
modified because QByteArray is an explicitly shared class.
\sa buffer(), open(), close()
*/
bool QBuffer::setBuffer( QByteArray buf )
{
if ( isOpen() ) {
#if defined(QT_CHECK_STATE)
qWarning( "QBuffer::setBuffer: Buffer is open" );
#endif
return FALSE;
}
a = buf;
a_len = a.size();
a_inc = (a_len > 512) ? 512 : a_len; // initial increment
if ( a_inc < 16 )
a_inc = 16;
ioIndex = 0;
return TRUE;
}
/*!
\fn QByteArray QBuffer::buffer() const
Returns this buffer's byte array.
\sa setBuffer()
*/
/*!
\reimp
Opens the buffer in mode \a m. Returns TRUE if successful;
otherwise returns FALSE. The buffer must be opened before use.
The mode parameter \a m must be a combination of the following flags.
\list
\i \c IO_ReadOnly opens the buffer in read-only mode.
\i \c IO_WriteOnly opens the buffer in write-only mode.
\i \c IO_ReadWrite opens the buffer in read/write mode.
\i \c IO_Append sets the buffer index to the end of the buffer.
\i \c IO_Truncate truncates the buffer.
\endlist
\sa close(), isOpen()
*/
bool QBuffer::open( int m )
{
if ( isOpen() ) { // buffer already open
#if defined(QT_CHECK_STATE)
qWarning( "QBuffer::open: Buffer already open" );
#endif
return FALSE;
}
setMode( m );
if ( m & IO_Truncate ) { // truncate buffer
- a.resize( 0 );
- a_len = 0;
+ a.resize( 1 );
+ a_len = 1;
}
if ( m & IO_Append ) { // append to end of buffer
ioIndex = a.size();
} else {
ioIndex = 0;
}
a_inc = 16;
setState( IO_Open );
setStatus( 0 );
return TRUE;
}
/*!
\reimp
Closes an open buffer.
\sa open()
*/
void QBuffer::close()
{
if ( isOpen() ) {
setFlags( IO_Direct );
ioIndex = 0;
a_inc = 16;
}
}
/*!
\reimp
The flush function does nothing for a QBuffer.
*/
void QBuffer::flush()
{
return;
}
/*!
\fn QIODevice::Offset QBuffer::at() const
\reimp
*/
/*!
\fn QIODevice::Offset QBuffer::size() const
\reimp
*/
/*!
\reimp
*/
bool QBuffer::at( Offset pos )
{
#if defined(QT_CHECK_STATE)
if ( !isOpen() ) {
qWarning( "QBuffer::at: Buffer is not open" );
return FALSE;
}
#endif
if ( pos > a_len ) {
#if defined(QT_CHECK_RANGE)
#if defined(QT_LARGEFILE_SUPPORT) && defined(QT_ABI_64BITOFFSET)
qWarning( "QBuffer::at: Index %llu out of range", pos );
#else
qWarning( "QBuffer::at: Index %lu out of range", pos );
#endif
#endif
return FALSE;
}
ioIndex = pos;
return TRUE;
}
/*!
\reimp
*/
Q_LONG QBuffer::readBlock( char *p, Q_ULONG len )
{
#if defined(QT_CHECK_STATE)
if ( !p ) {
qWarning( "QBuffer::readBlock: Null pointer error" );
return -1;
}
if ( !isOpen() ) { // buffer not open
qWarning( "QBuffer::readBlock: Buffer not open" );
return -1;
}
if ( !isReadable() ) { // reading not permitted