Permalink
Browse files

up

  • Loading branch information...
1 parent 989fd62 commit 3f9a99b198855009632f0627cc384bd8fdbddd33 @elliotwoods committed Dec 9, 2011
Showing with 19 additions and 29 deletions.
  1. +19 −29 src/TalkyBuffer.cpp
View
@@ -208,42 +208,32 @@ namespace Talky {
}
//------
- bool TalkyBuffer::loadFile(string filename) {
-
-
- // this is untested
-
+ bool TalkyBuffer::loadFile(string filename) {
ifstream inFile;
-
- if (inFile.is_open()) {
- try {
-
- inFile.open(filename.c_str(), ios::binary);
+ try {
+ inFile.open(filename.c_str(), ios::binary);
- //find filesize
- long begin, end;
- begin = inFile.tellg();
- inFile.seekg (0, ios::end);
- end = inFile.tellg();
+ //find filesize
+ long end;
+ inFile.seekg (0, ios::end);
+ end = inFile.tellg();
+ inFile.seekg(0, ios::beg);
- //allocate to this size
- allocate(end - begin);
+ //allocate to this size
+ allocate(end);
- inFile.read(_data, end-begin);
+ inFile.read(_data, end);
- if (inFile.fail())
- throw;
- } catch (...) {
- if (inFile.is_open())
- inFile.close();
- return false;
- }
-
- inFile.close();
- return true;
- } else {
+ if (inFile.fail())
+ throw;
+ } catch (...) {
+ if (inFile.is_open())
+ inFile.close();
return false;
}
+
+ inFile.close();
+ return true;
}
bool TalkyBuffer::saveFile(string filename) const {

0 comments on commit 3f9a99b

Please sign in to comment.