fix write buffer alignment if the write buffer is empty and

misaligned; the m_iWriteBufferUsed == 0 case would
skip the realignment
This commit is contained in:
Glenn Maynard
2007-01-23 22:00:19 +00:00
parent 9f8519c0d9
commit 9ebd6bbf11
+17 -17
View File
@@ -204,18 +204,21 @@ int RageFileObj::EmptyWriteBuf()
if( m_pWriteBuffer == NULL ) if( m_pWriteBuffer == NULL )
return 0; return 0;
/* The write buffer may not align with the actual file, if we've seeked. Only if( m_iWriteBufferUsed )
* seek if needed. */ {
bool bSeeked = (m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos); /* The write buffer may not align with the actual file, if we've seeked. Only
if( bSeeked ) * seek if needed. */
SeekInternal( m_iWriteBufferPos ); bool bSeeked = (m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos);
if( bSeeked )
SeekInternal( m_iWriteBufferPos );
int iRet = WriteInternal( m_pWriteBuffer, m_iWriteBufferUsed ); int iRet = WriteInternal( m_pWriteBuffer, m_iWriteBufferUsed );
if( bSeeked ) if( bSeeked )
SeekInternal( m_iFilePos ); SeekInternal( m_iFilePos );
if( iRet == -1 ) if( iRet == -1 )
return iRet; return iRet;
}
m_iWriteBufferPos = m_iFilePos; m_iWriteBufferPos = m_iFilePos;
m_iWriteBufferUsed = 0; m_iWriteBufferUsed = 0;
@@ -228,14 +231,11 @@ int RageFileObj::Write( const void *pBuffer, size_t iBytes )
{ {
/* If the file position has moved away from the write buffer, or the /* If the file position has moved away from the write buffer, or the
* incoming data won't fit in the buffer, flush. */ * incoming data won't fit in the buffer, flush. */
if( m_iWriteBufferUsed ) if( m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos || m_iWriteBufferUsed + (int)iBytes > m_iWriteBufferSize )
{ {
if( m_iWriteBufferPos+m_iWriteBufferUsed != m_iFilePos || m_iWriteBufferUsed + (int)iBytes > m_iWriteBufferSize ) int iRet = EmptyWriteBuf();
{ if( iRet == -1 )
int iRet = EmptyWriteBuf(); return iRet;
if( iRet == -1 )
return iRet;
}
} }
if( m_iWriteBufferUsed + (int)iBytes <= m_iWriteBufferSize ) if( m_iWriteBufferUsed + (int)iBytes <= m_iWriteBufferSize )