throw std::runtime_error(std::string("Failed to open file: ").append(filename).c_str());
}
- fseek(fp, 0, SEEK_END);
+ if (fseek(fp, 0, SEEK_END)) {
+ throw std::runtime_error(std::string("Failed to fseek end of file").c_str());
+ }
long fsize = ftell(fp);
- fseek(fp, 0, SEEK_SET); //rewind
+ if (fsize < 0) {
+ throw std::runtime_error(std::string("Failed to ftell").c_str());
+ }
+ if (fseek(fp, 0, SEEK_SET)) {
+ throw std::runtime_error(std::string("Failed to fseek beginning of file").c_str());
+ }
auto str = std::unique_ptr<char[]>(new char[fsize + 1]); // TODO change to make_unique when c++14 becomes available
const int count = 1;