Commit e1e1bced authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen Committed by Wouter van Oortmerssen

Fixed LoadFile on Windows

parent b56add95
...@@ -112,10 +112,18 @@ inline bool FileExists(const char *name) { ...@@ -112,10 +112,18 @@ inline bool FileExists(const char *name) {
inline bool LoadFile(const char *name, bool binary, std::string *buf) { inline bool LoadFile(const char *name, bool binary, std::string *buf) {
std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in); std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in);
if (!ifs.is_open()) return false; if (!ifs.is_open()) return false;
ifs.seekg(0, std::ios::end); if (binary) {
(*buf).resize(static_cast<size_t>(ifs.tellg())); // The fastest way to read a file into a string.
ifs.seekg(0, std::ios::beg); ifs.seekg(0, std::ios::end);
ifs.read(&(*buf)[0], (*buf).size()); (*buf).resize(static_cast<size_t>(ifs.tellg()));
ifs.seekg(0, std::ios::beg);
ifs.read(&(*buf)[0], (*buf).size());
} else {
// This is slower, but works correctly on all platforms for text files.
std::ostringstream oss;
oss << ifs.rdbuf();
*buf = oss.str();
}
return !ifs.bad(); return !ifs.bad();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment