diff --git a/src/fart/Engine.cpp b/src/fart/Engine.cpp index 0e7492e..d2ddffd 100644 --- a/src/fart/Engine.cpp +++ b/src/fart/Engine.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include Engine::Engine(const RenderParams & params) : params(params) @@ -28,5 +31,23 @@ int Engine::run(string_view input_file, opt output_file) return 1; } + /* Verify the output file can be written before rendering. */ + FILE * fh = fopen(output_path.c_str(), "wb"); + if (fh == nullptr) + { + fprintf(stderr, "Error opening output file '%s': %s\n", output_path.c_str(), strerror(errno)); + return 1; + } + if (fclose(fh) != 0) + { + fprintf(stderr, "Error closing output file '%s': %s\n", output_path.c_str(), strerror(errno)); + return 1; + } + if (remove(output_path.c_str()) != 0) + { + fprintf(stderr, "Error removing output file '%s': %s\n", output_path.c_str(), strerror(errno)); + return 1; + } + return 0; }