If the size_hint passed to read_file was an underestimate, or the
platform's `stat()` implementation gives an inaccurate file size (e.g.
MinGW) then `Util::read_file()` would only issue a single `read()` call
instead of reading the entire file.
Fixes #803.
result.resize(size_hint);
while (true) {
- if (pos > result.size()) {
+ if (pos == result.size()) {
result.resize(2 * result.size());
}
const size_t max_read = result.size() - pos;
#else
CHECK(data == "carpet\n\n");
#endif
+
+ Util::write_file("size_hint_test", std::string(8192, '\0'));
+ CHECK(Util::read_file("size_hint_test", 4096 /*size_hint*/).size() == 8192);
+
CHECK_THROWS_WITH(Util::read_file("does/not/exist"),
"No such file or directory");