summaryrefslogtreecommitdiff
path: root/tools/generate-tiles/main.cc
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-07 13:37:10 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-07 13:37:10 +0100
commit582eeb48091e7a4e2e8f93c8131e74d1bb3d0c5d (patch)
tree30ca7fe7ef0ae85fa497e61b32bcb5937bd6ffc7 /tools/generate-tiles/main.cc
parent95a039c8d1f926365c8bf3c20b09ec6250e60d8a (diff)
fix compilation errors/warnings
Diffstat (limited to 'tools/generate-tiles/main.cc')
-rw-r--r--tools/generate-tiles/main.cc34
1 files changed, 26 insertions, 8 deletions
diff --git a/tools/generate-tiles/main.cc b/tools/generate-tiles/main.cc
index dbee3fa..4ec4906 100644
--- a/tools/generate-tiles/main.cc
+++ b/tools/generate-tiles/main.cc
@@ -6,6 +6,8 @@
#include <cassert>
#include <cstdlib>
#include <cstdint>
+#include <unistd.h>
+#include <fcntl.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
@@ -215,6 +217,27 @@ namespace
return status::ok;
}
+
+ auto write_file(std::string_view const filename, std::string_view const content) -> status
+ {
+ auto const filename_str = std::string{ filename };
+
+ auto const fd = open(filename_str.c_str(), O_TRUNC | O_WRONLY | O_CREAT, 0644);
+ if (fd == -1)
+ {
+ perror("open");
+ return status::invalid;
+ }
+
+ if (write(fd, content.data(), content.length()) == -1)
+ {
+ perror("write");
+ return status::invalid;
+ }
+
+ close(fd);
+ return status::ok;
+ }
} // namespace
int main(int const argc, char** const argv)
@@ -285,13 +308,8 @@ int main(int const argc, char** const argv)
source << "} // namespace nes::app::tiles\n";
- auto header_file = std::ofstream{ std::string{ output_header } };
- header_file << header.str();
- header_file.flush();
-
- auto source_file = std::ofstream{ std::string{ output_source } };
- source_file << source.str();
- source_file.flush();
+ if (write_file(output_header, header.str()) != status::ok) { return EXIT_FAILURE; }
+ if (write_file(output_source, source.str()) != status::ok) { return EXIT_FAILURE; }
return EXIT_SUCCESS;
-} \ No newline at end of file
+}