add RageFile::Flush

This commit is contained in:
Glenn Maynard
2003-12-12 07:47:38 +00:00
parent f063c76799
commit 63bb61388a
4 changed files with 25 additions and 18 deletions
+17 -11
View File
@@ -281,17 +281,6 @@ int RageFile::Read( void *buffer, size_t bytes )
return ret;
}
int RageFile::Write( const void *buffer, size_t bytes )
{
if( !IsOpen() )
RageException::Throw("\"%s\" is not open.", GetPath().c_str());
if( m_Mode != WRITE )
RageException::Throw("\"%s\" is not open for writing", GetPath().c_str());
return m_File->Write( buffer, bytes );
}
int RageFile::Seek( int offset )
{
if( !IsOpen() )
@@ -395,6 +384,18 @@ int RageFile::Read( CString &buffer, size_t bytes )
return ret;
}
int RageFile::Write( const void *buffer, size_t bytes )
{
if( !IsOpen() )
RageException::Throw("\"%s\" is not open.", GetPath().c_str());
if( m_Mode != WRITE )
RageException::Throw("\"%s\" is not open for writing", GetPath().c_str());
return m_File->Write( buffer, bytes );
}
int RageFile::Write( const void *buffer, size_t bytes, int nmemb )
{
/* Simple write. We never return partial writes. */
@@ -404,6 +405,11 @@ int RageFile::Write( const void *buffer, size_t bytes, int nmemb )
return ret / bytes;
}
int RageFile::Flush()
{
return m_File->Flush();
}
int RageFile::Read( void *buffer, size_t bytes, int nmemb )
{
const int ret = Read( buffer, bytes*nmemb );
+3 -2
View File
@@ -57,10 +57,11 @@ public:
void Rewind();
/* Raw I/O: */
int Write( const void *buffer, size_t bytes );
int Write( const CString& string ) { return Write( string.data(), string.size() ); }
int Read( void *buffer, size_t bytes );
int Read( CString &buffer, size_t bytes );
int Write( const void *buffer, size_t bytes );
int Write( const CString& string ) { return Write( string.data(), string.size() ); }
int Flush();
/* These are just here to make wrappers (eg. vorbisfile, SDL_rwops) easier. */
int Write( const void *buffer, size_t bytes, int nmemb );
+1
View File
@@ -46,6 +46,7 @@ public:
/* Raw I/O: */
virtual int Read(void *buffer, size_t bytes) = 0;
virtual int Write(const void *buffer, size_t bytes) = 0;
virtual int Flush() { return 0; }
virtual void Rewind() = 0;
virtual RageFileObj *Copy( RageFile &p ) const = 0;
};
+4 -5
View File
@@ -182,13 +182,12 @@ private:
CString write_buf;
int FlushWrites();
public:
RageFileObjDirect( const CString &path, int fd_, RageFile &p );
virtual ~RageFileObjDirect();
virtual int Read(void *buffer, size_t bytes);
virtual int Write(const void *buffer, size_t bytes);
virtual int Flush();
virtual void Rewind();
virtual int Seek( int offset );
virtual int GetFileSize();
@@ -368,7 +367,7 @@ RageFileObjDirect::RageFileObjDirect( const CString &path_, int fd_, RageFile &p
RageFileObjDirect::~RageFileObjDirect()
{
FlushWrites();
Flush();
if( fd != -1 )
close( fd );
@@ -386,7 +385,7 @@ int RageFileObjDirect::Read( void *buf, size_t bytes )
return ret;
}
int RageFileObjDirect::FlushWrites()
int RageFileObjDirect::Flush()
{
if( !write_buf.size() )
return 0;
@@ -406,7 +405,7 @@ int RageFileObjDirect::Write( const void *buf, size_t bytes )
{
if( write_buf.size()+bytes > BUFSIZE )
{
if( FlushWrites() == -1 )
if( Flush() == -1 )
return -1;
}