Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 14, 2025
1 parent 877f98c commit 9de2f3c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cpp/s2p/s2p_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void S2p::ReadAccessToken(const path &filename)
}

ifstream token_file(filename);
if (token_file.fail()) {
if (!token_file) {
throw ParserException("Can't open access token file '" + filename.string() + "'");
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/s2pdump/s2pdump_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ string S2pDump::DumpRestore()
}

fstream file(filename, (restore ? ios::in : ios::out) | ios::binary);
if (file.fail()) {
if (!file) {
return "Can't open image file '" + filename + "': " + strerror(errno);
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/s2pexec/s2pexec_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ string S2pExec::ReadData()
const bool text = binary_input_filename.empty();

ifstream in(filename, text ? ios::in : ios::in | ios::binary);
if (in.fail()) {
if (!in) {
return fmt::format("Can't open input file '{0}': {1}", filename, strerror(errno));
}

Expand Down Expand Up @@ -563,7 +563,7 @@ string S2pExec::WriteData(span<const uint8_t> data)
}
else {
ofstream out(filename, text ? ios::out : ios::out | ios::binary);
if (out.fail()) {
if (!out) {
return fmt::format("Can't open output file '{0}': {1}", filename, strerror(errno));
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/s2pproto/s2pproto_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ int S2pProto::GenerateOutput(const string &input_filename, const string &output_
}

ofstream out(output_filename, output_format == ProtobufFormat::BINARY ? ios::binary : ios::out);
if (out.fail()) {
if (!out) {
cerr << "Error: Can't open protobuf data output file '" << output_filename << "'\n";
return EXIT_FAILURE;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/s2psimh/s2psimh_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool S2pSimh::ParseArguments(span<char*> args)

if (truncate) {
ofstream f(simh_filename);
if (f.fail()) {
if (!f) {
cerr << "Error: Can't open '" << simh_filename << "'\n";
return false;
}
Expand All @@ -161,7 +161,7 @@ int S2pSimh::Run(span<char*> args)
}

simh_file.open(simh_filename, (meta_data.empty() ? ios::in : ios::out) | ios::binary);
if (simh_file.fail()) {
if (!simh_file) {
cerr << "Error: Can't open '" << simh_filename << "':" << strerror(errno) << '\n';
return EXIT_FAILURE;
}
Expand Down

0 comments on commit 9de2f3c

Please sign in to comment.