Skip to content

Commit 670b42b

Browse files
Check whether files could be opened before writing; resolves #542 (#555)
1 parent 27044f7 commit 670b42b

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

include/rfl/io/save_bytes.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Result<Nothing> save_bytes(const std::string& _fname, const T& _obj,
1515
const WriteFunction& _write) {
1616
try {
1717
std::ofstream output(_fname, std::ios::out | std::ios::binary);
18+
if (!output.is_open()) {
19+
return error("Unable to open file '" + _fname + "' for writing.");
20+
}
1821
_write(_obj, output);
1922
output.close();
2023
} catch (std::exception& e) {

include/rfl/io/save_string.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Result<Nothing> save_string(const std::string& _fname, const T& _obj,
1515
try {
1616
std::ofstream outfile;
1717
outfile.open(_fname);
18+
if (!outfile.is_open()) {
19+
return error("Unable to open file '" + _fname + "' for writing.");
20+
}
1821
_write(_obj, outfile);
1922
outfile.close();
2023
} catch (std::exception& e) {

0 commit comments

Comments
 (0)