]> git.saurik.com Git - wxWidgets.git/commitdiff
Check for and allow zero length files
authorRobin Dunn <robin@alldunn.com>
Mon, 30 Jun 2003 17:37:34 +0000 (17:37 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 30 Jun 2003 17:37:34 +0000 (17:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21517 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/src/stc/stc.cpp
contrib/src/stc/stc.cpp.in
src/stc/stc.cpp
src/stc/stc.cpp.in

index d4fbcec50ccceca291efb7d6197645da14722e82..c437fee5a0aa6687daaebc2199c32acec0487521 100644 (file)
@@ -2093,23 +2093,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
 
 bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 {
+    bool success = false;
     wxFile file(filename, wxFile::read);
 
-    if (!file.IsOpened())
-        return FALSE;
-
-    wxString contents;
-    off_t len = file.Length();
-
-    wxChar *buf = contents.GetWriteBuf(len);
-    bool success = (file.Read(buf, len) == len);
-    contents.UngetWriteBuf();
-
-    if (success)
+    if (file.IsOpened())
     {
-        SetText(contents);
-        EmptyUndoBuffer();
-        SetSavePoint();
+        wxString contents;
+        off_t len = file.Length();
+
+        if (len > 0)
+        {
+            wxChar *buf = contents.GetWriteBuf(len);
+            success = (file.Read(buf, len) == len);
+            contents.UngetWriteBuf();
+        }
+        else
+            success = true;            // empty file is ok
+
+        if (success)
+        {
+            SetText(contents);
+            EmptyUndoBuffer();
+            SetSavePoint();
+        }
     }
 
     return success;
index 8952840b6c732e742f087cb9f10723cce0250b05..60360d977e0f607e354712e0ee6c4c37496c4a18 100644 (file)
@@ -325,23 +325,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
 
 bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 {
+    bool success = false;
     wxFile file(filename, wxFile::read);
 
-    if (!file.IsOpened())
-        return FALSE;
-
-    wxString contents;
-    off_t len = file.Length();
-
-    wxChar *buf = contents.GetWriteBuf(len);
-    bool success = (file.Read(buf, len) == len);
-    contents.UngetWriteBuf();
-
-    if (success)
+    if (file.IsOpened())
     {
-        SetText(contents);
-        EmptyUndoBuffer();
-        SetSavePoint();
+        wxString contents;
+        off_t len = file.Length();
+
+        if (len > 0)
+        {
+            wxChar *buf = contents.GetWriteBuf(len);
+            success = (file.Read(buf, len) == len);
+            contents.UngetWriteBuf();
+        }
+        else
+            success = true;            // empty file is ok
+
+        if (success)
+        {
+            SetText(contents);
+            EmptyUndoBuffer();
+            SetSavePoint();
+        }
     }
 
     return success;
index d4fbcec50ccceca291efb7d6197645da14722e82..c437fee5a0aa6687daaebc2199c32acec0487521 100644 (file)
@@ -2093,23 +2093,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
 
 bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 {
+    bool success = false;
     wxFile file(filename, wxFile::read);
 
-    if (!file.IsOpened())
-        return FALSE;
-
-    wxString contents;
-    off_t len = file.Length();
-
-    wxChar *buf = contents.GetWriteBuf(len);
-    bool success = (file.Read(buf, len) == len);
-    contents.UngetWriteBuf();
-
-    if (success)
+    if (file.IsOpened())
     {
-        SetText(contents);
-        EmptyUndoBuffer();
-        SetSavePoint();
+        wxString contents;
+        off_t len = file.Length();
+
+        if (len > 0)
+        {
+            wxChar *buf = contents.GetWriteBuf(len);
+            success = (file.Read(buf, len) == len);
+            contents.UngetWriteBuf();
+        }
+        else
+            success = true;            // empty file is ok
+
+        if (success)
+        {
+            SetText(contents);
+            EmptyUndoBuffer();
+            SetSavePoint();
+        }
     }
 
     return success;
index 8952840b6c732e742f087cb9f10723cce0250b05..60360d977e0f607e354712e0ee6c4c37496c4a18 100644 (file)
@@ -325,23 +325,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
 
 bool wxStyledTextCtrl::LoadFile(const wxString& filename)
 {
+    bool success = false;
     wxFile file(filename, wxFile::read);
 
-    if (!file.IsOpened())
-        return FALSE;
-
-    wxString contents;
-    off_t len = file.Length();
-
-    wxChar *buf = contents.GetWriteBuf(len);
-    bool success = (file.Read(buf, len) == len);
-    contents.UngetWriteBuf();
-
-    if (success)
+    if (file.IsOpened())
     {
-        SetText(contents);
-        EmptyUndoBuffer();
-        SetSavePoint();
+        wxString contents;
+        off_t len = file.Length();
+
+        if (len > 0)
+        {
+            wxChar *buf = contents.GetWriteBuf(len);
+            success = (file.Read(buf, len) == len);
+            contents.UngetWriteBuf();
+        }
+        else
+            success = true;            // empty file is ok
+
+        if (success)
+        {
+            SetText(contents);
+            EmptyUndoBuffer();
+            SetSavePoint();
+        }
     }
 
     return success;