add RageFile::Flush
This commit is contained in:
+17
-11
@@ -281,17 +281,6 @@ int RageFile::Read( void *buffer, size_t bytes )
|
|||||||
return ret;
|
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 )
|
int RageFile::Seek( int offset )
|
||||||
{
|
{
|
||||||
if( !IsOpen() )
|
if( !IsOpen() )
|
||||||
@@ -395,6 +384,18 @@ int RageFile::Read( CString &buffer, size_t bytes )
|
|||||||
return ret;
|
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 )
|
int RageFile::Write( const void *buffer, size_t bytes, int nmemb )
|
||||||
{
|
{
|
||||||
/* Simple write. We never return partial writes. */
|
/* 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;
|
return ret / bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RageFile::Flush()
|
||||||
|
{
|
||||||
|
return m_File->Flush();
|
||||||
|
}
|
||||||
|
|
||||||
int RageFile::Read( void *buffer, size_t bytes, int nmemb )
|
int RageFile::Read( void *buffer, size_t bytes, int nmemb )
|
||||||
{
|
{
|
||||||
const int ret = Read( buffer, bytes*nmemb );
|
const int ret = Read( buffer, bytes*nmemb );
|
||||||
|
|||||||
@@ -57,10 +57,11 @@ public:
|
|||||||
void Rewind();
|
void Rewind();
|
||||||
|
|
||||||
/* Raw I/O: */
|
/* 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( void *buffer, size_t bytes );
|
||||||
int Read( CString &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. */
|
/* These are just here to make wrappers (eg. vorbisfile, SDL_rwops) easier. */
|
||||||
int Write( const void *buffer, size_t bytes, int nmemb );
|
int Write( const void *buffer, size_t bytes, int nmemb );
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public:
|
|||||||
/* Raw I/O: */
|
/* Raw I/O: */
|
||||||
virtual int Read(void *buffer, size_t bytes) = 0;
|
virtual int Read(void *buffer, size_t bytes) = 0;
|
||||||
virtual int Write(const 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 void Rewind() = 0;
|
||||||
virtual RageFileObj *Copy( RageFile &p ) const = 0;
|
virtual RageFileObj *Copy( RageFile &p ) const = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -182,13 +182,12 @@ private:
|
|||||||
|
|
||||||
CString write_buf;
|
CString write_buf;
|
||||||
|
|
||||||
int FlushWrites();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RageFileObjDirect( const CString &path, int fd_, RageFile &p );
|
RageFileObjDirect( const CString &path, int fd_, RageFile &p );
|
||||||
virtual ~RageFileObjDirect();
|
virtual ~RageFileObjDirect();
|
||||||
virtual int Read(void *buffer, size_t bytes);
|
virtual int Read(void *buffer, size_t bytes);
|
||||||
virtual int Write(const void *buffer, size_t bytes);
|
virtual int Write(const void *buffer, size_t bytes);
|
||||||
|
virtual int Flush();
|
||||||
virtual void Rewind();
|
virtual void Rewind();
|
||||||
virtual int Seek( int offset );
|
virtual int Seek( int offset );
|
||||||
virtual int GetFileSize();
|
virtual int GetFileSize();
|
||||||
@@ -368,7 +367,7 @@ RageFileObjDirect::RageFileObjDirect( const CString &path_, int fd_, RageFile &p
|
|||||||
|
|
||||||
RageFileObjDirect::~RageFileObjDirect()
|
RageFileObjDirect::~RageFileObjDirect()
|
||||||
{
|
{
|
||||||
FlushWrites();
|
Flush();
|
||||||
|
|
||||||
if( fd != -1 )
|
if( fd != -1 )
|
||||||
close( fd );
|
close( fd );
|
||||||
@@ -386,7 +385,7 @@ int RageFileObjDirect::Read( void *buf, size_t bytes )
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageFileObjDirect::FlushWrites()
|
int RageFileObjDirect::Flush()
|
||||||
{
|
{
|
||||||
if( !write_buf.size() )
|
if( !write_buf.size() )
|
||||||
return 0;
|
return 0;
|
||||||
@@ -406,7 +405,7 @@ int RageFileObjDirect::Write( const void *buf, size_t bytes )
|
|||||||
{
|
{
|
||||||
if( write_buf.size()+bytes > BUFSIZE )
|
if( write_buf.size()+bytes > BUFSIZE )
|
||||||
{
|
{
|
||||||
if( FlushWrites() == -1 )
|
if( Flush() == -1 )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user