Added wxFile::ReadAll() for consistency with wxFFile::ReadAll().

Make it possible to use wxFFile and wxFile interchangeably for simply reading
the entire contents of the file as a string.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72596 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-30 22:28:08 +00:00
parent ce364c4ecd
commit 614108e211
4 changed files with 49 additions and 1 deletions

View File

@@ -291,6 +291,34 @@ bool wxFile::Close()
// read/write
// ----------------------------------------------------------------------------
bool wxFile::ReadAll(wxString *str, const wxMBConv& conv)
{
wxCHECK_MSG( str, false, wxS("Output string must be non-NULL") );
size_t length = wx_truncate_cast(size_t, Length());
wxCHECK_MSG( (wxFileOffset)length == Length(), false, wxT("huge file not supported") );
wxCharBuffer buf(length);
char* p = buf.data();
for ( ;; )
{
static const unsigned READSIZE = 4096;
ssize_t read = Read(p, length > READSIZE ? READSIZE : length);
if ( read == wxInvalidOffset )
return false;
p += read;
}
*p = 0;
wxString strTmp(buf, conv);
str->swap(strTmp);
return true;
}
// read
ssize_t wxFile::Read(void *pBuf, size_t nCount)
{