File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#include " common.hpp"
22#include " defines.hpp"
3+ #include < exception>
34#include < filesystem>
45#include < fstream>
56#include < iostream>
7+ #include < stdexcept>
68
79bool create_tmp_dbc_with (const char * filename, const char * content) {
810 auto * file = std::fopen (filename, " w" );
@@ -20,13 +22,19 @@ std::string create_temporary_dbc_with(const char* contents) {
2022 std::filesystem::path temp_dir = std::filesystem::temp_directory_path ();
2123
2224 // Generate a unique temporary file name
23- std::filesystem::path temp_file = temp_dir / " temp_file_XXXXXX" ; // "XXXXXX" is a placeholder for a unique name
25+ char filename[] = " temp_file_XXXXXX" ;
26+ if (std::tmpnam (filename) == nullptr ) {
27+ throw std::runtime_error (" Failed to generate a unique temporary filename." );
28+ }
29+ std::filesystem::path temp_file = temp_dir / filename;
2430
2531 std::ofstream file (temp_file);
26- if (file.is_open ()) {
27- file << contents << std::endl;
28- file.close ();
32+ if (!file.is_open ()) {
33+ throw std::runtime_error (" Failed to create temporary file." );
2934 }
3035
36+ file << contents << std::endl;
37+ file.close ();
38+
3139 return temp_file;
3240}
You can’t perform that action at this time.
0 commit comments