Check for and allow zero length files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21517 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2093,17 +2093,22 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
{
|
||||||
|
|
||||||
wxString contents;
|
wxString contents;
|
||||||
off_t len = file.Length();
|
off_t len = file.Length();
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
bool success = (file.Read(buf, len) == len);
|
success = (file.Read(buf, len) == len);
|
||||||
contents.UngetWriteBuf();
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -2111,6 +2116,7 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
|||||||
EmptyUndoBuffer();
|
EmptyUndoBuffer();
|
||||||
SetSavePoint();
|
SetSavePoint();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@@ -325,17 +325,22 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
{
|
||||||
|
|
||||||
wxString contents;
|
wxString contents;
|
||||||
off_t len = file.Length();
|
off_t len = file.Length();
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
bool success = (file.Read(buf, len) == len);
|
success = (file.Read(buf, len) == len);
|
||||||
contents.UngetWriteBuf();
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -343,6 +348,7 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
|||||||
EmptyUndoBuffer();
|
EmptyUndoBuffer();
|
||||||
SetSavePoint();
|
SetSavePoint();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@@ -2093,17 +2093,22 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
{
|
||||||
|
|
||||||
wxString contents;
|
wxString contents;
|
||||||
off_t len = file.Length();
|
off_t len = file.Length();
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
bool success = (file.Read(buf, len) == len);
|
success = (file.Read(buf, len) == len);
|
||||||
contents.UngetWriteBuf();
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -2111,6 +2116,7 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
|||||||
EmptyUndoBuffer();
|
EmptyUndoBuffer();
|
||||||
SetSavePoint();
|
SetSavePoint();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@@ -325,17 +325,22 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
{
|
||||||
|
|
||||||
wxString contents;
|
wxString contents;
|
||||||
off_t len = file.Length();
|
off_t len = file.Length();
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
bool success = (file.Read(buf, len) == len);
|
success = (file.Read(buf, len) == len);
|
||||||
contents.UngetWriteBuf();
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -343,6 +348,7 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
|||||||
EmptyUndoBuffer();
|
EmptyUndoBuffer();
|
||||||
SetSavePoint();
|
SetSavePoint();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user