fixed bug in ReadAll(): it always returned error when reading files with DOS EOLs in text mode
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -115,14 +115,20 @@ bool wxFFile::ReadAll(wxString *str, wxMBConv& conv)
|
|||||||
|
|
||||||
const size_t fileLen = Length();
|
const size_t fileLen = Length();
|
||||||
wxCharBuffer buf(fileLen + 1);
|
wxCharBuffer buf(fileLen + 1);
|
||||||
if ( (fread(buf.data(), sizeof(char), fileLen, m_fp) < fileLen) || Error() )
|
|
||||||
|
// note that realLen may be less than fileLen for text files with DOS EOLs
|
||||||
|
// ('\r's get dropped by CRT when reading which means that we have
|
||||||
|
// realLen = fileLen - numOfLinesInTheFile)
|
||||||
|
size_t realLen = fread(buf.data(), sizeof(char), fileLen, m_fp);
|
||||||
|
|
||||||
|
if ( Error() )
|
||||||
{
|
{
|
||||||
wxLogSysError(_("Read error on file '%s'"), m_name.c_str());
|
wxLogSysError(_("Read error on file '%s'"), m_name.c_str());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.data()[fileLen] = 0;
|
buf.data()[realLen] = 0;
|
||||||
*str = wxString(buf, conv);
|
*str = wxString(buf, conv);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user