CString foo;

file.Read( foo );
to read the entire file
This commit is contained in:
Glenn Maynard
2003-12-21 09:17:39 +00:00
parent ff68567397
commit efc1ce7a5d
2 changed files with 23 additions and 7 deletions
+22 -6
View File
@@ -343,13 +343,29 @@ void RageFile::Rewind()
m_File->Rewind();
}
int RageFile::Read( CString &buffer, size_t bytes )
int RageFile::Read( CString &buffer, int bytes )
{
char *buf = new char[bytes];
int ret = Read( buf, bytes );
if( ret != -1 )
buffer.assign( buf, buf+ret );
delete [] buf;
buffer.clear();
buffer.reserve( bytes != -1? bytes: this->GetFileSize() );
int ret = 0;
char buf[4096];
while( bytes == -1 || ret < bytes )
{
int ToRead = sizeof(buf);
if( bytes != -1 )
ToRead = min( ToRead, bytes-ret );
const int got = Read( buf, ToRead );
if( got == 0 )
break;
if( got == -1 )
return -1;
buffer.append( buf, got );
ret += got;
}
return ret;
}