diff --git a/stepmania/src/RageFile.cpp b/stepmania/src/RageFile.cpp index b8c9b7d3a4..f124bc0975 100644 --- a/stepmania/src/RageFile.cpp +++ b/stepmania/src/RageFile.cpp @@ -352,3 +352,37 @@ void RageFile::Rewind() } +int RageFile::Write( const void *buffer, size_t bytes, int nmemb ) +{ + /* Simple write. We never return partial writes. */ + int ret = Write( buffer, bytes*nmemb ) / bytes; + if( ret == -1 ) + return -1; + return ret / bytes; +} + +int RageFile::Read( void *buffer, size_t bytes, int nmemb ) +{ + const int ret = Read( buffer, bytes*nmemb ); + if( ret == -1 ) + return -1; + + /* If we're reading 10-byte blocks, and we got 27 bytes, we have 7 extra bytes. + * Seek back. */ + const int extra = ret % bytes; + Seek( Tell()-extra ); + + return ret/bytes; +} + +int RageFile::Seek( int offset, int whence ) +{ + switch( whence ) + { + case SEEK_CUR: + return SeekCur( (int) offset ); + case SEEK_END: + offset += GetFileSize(); + } + return Seek( (int) offset ); +} diff --git a/stepmania/src/RageFile.h b/stepmania/src/RageFile.h index 10f0b034ca..71f411ff14 100644 --- a/stepmania/src/RageFile.h +++ b/stepmania/src/RageFile.h @@ -54,6 +54,11 @@ public: int Read( void *buffer, size_t bytes ); int Read( const CString &buffer, size_t bytes ); + /* These are just here to make wrappers (eg. vorbisfile, SDL_rwops) easier. */ + int Write( const void *buffer, size_t bytes, int nmemb ); + int Read( void *buffer, size_t bytes, int nmemb ); + int Seek( int offset, int whence ); + /* Line-based I/O: */ CString GetLine(); int GetLine( CString &out );