From 582eeb48091e7a4e2e8f93c8131e74d1bb3d0c5d Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Fri, 7 Feb 2025 13:37:10 +0100 Subject: fix compilation errors/warnings --- tools/generate-tiles/main.cc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'tools/generate-tiles/main.cc') 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 #include #include +#include +#include #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 +} -- cgit v1.3.1