Skip to content

Commit

Permalink
Codechange: Use std::filesystem::remove/rename in settingsgen. (OpenT…
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterN authored Apr 12, 2024
1 parent 44b8210 commit ca73f03
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/settingsgen/settingsgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
#include "../core/mem_func.hpp"
#include "../error_func.h"

#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h>
#include <sys/stat.h>
#endif
#include <filesystem>

#include "../safeguards.h"

Expand Down Expand Up @@ -493,15 +490,14 @@ int CDECL main(int argc, char *argv[])
AppendFile(after_file, fp);
fclose(fp);

std::error_code error_code;
if (CompareFiles(tmp_output, output_file)) {
/* Files are equal. tmp2.xxx is not needed. */
unlink(tmp_output);
std::filesystem::remove(tmp_output, error_code);
} else {
/* Rename tmp2.xxx to output file. */
#if defined(_WIN32)
unlink(output_file);
#endif
if (rename(tmp_output, output_file) == -1) FatalError("rename() failed");
std::filesystem::rename(tmp_output, output_file, error_code);
if (error_code) FatalError("rename({}, {}) failed: {}", tmp_output, output_file, error_code.message());
}
}
return 0;
Expand Down

0 comments on commit ca73f03

Please sign in to comment.