Skip to content

Commit c025ca9

Browse files
authored
Improve error handling in platform::read_binary_file (#291)
1 parent e87d853 commit c025ca9

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/platform/file.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ Result<std::vector<ccc::u8>> read_binary_file(const fs::path& path)
1414
{
1515
std::ifstream file(path, std::ios::binary);
1616
CCC_CHECK(file, "Failed to open file '%s' (%s).", path.string().c_str(), strerror(errno));
17-
CCC_CHECK(fs::is_regular_file(path), "Failed to open '%s' (not a regular file).", path.string().c_str());
17+
1818
file.seekg(0, std::ios::end);
1919
s64 size = file.tellg();
20-
file.seekg(0, std::ios::beg);
20+
CCC_CHECK(size >= 0, "Failed to determine size of file '%s'.", path.string().c_str());
21+
2122
std::vector<u8> output(size);
23+
file.seekg(0, std::ios::beg);
2224
file.read((char*) output.data(), size);
23-
CCC_CHECK(file, "Failed to read from file '%s' (%s).", path.string().c_str(), strerror(errno));
25+
CCC_CHECK(file.good(), "Failed to read from file '%s' (%s).", path.string().c_str(), strerror(errno));
26+
2427
return output;
2528
}
2629

0 commit comments

Comments
 (0)