mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix the hack for File::c_str to work (#1242)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
@@ -85,17 +86,11 @@ public:
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
char const *c_str(std::filesystem::path const &path) const {
|
||||
// FIXME: This is a hack to prevent the path string from being destroyed until
|
||||
// `.c_str(path)` is called again. It's necessary because just `return path.c_str()`
|
||||
// fails on Windows, where paths use `wchar_t`.
|
||||
static std::string path_string;
|
||||
return std::visit(Visitor{[&path](std::filebuf const &) {
|
||||
path_string = path.string();
|
||||
return path_string.c_str();
|
||||
},
|
||||
std::string string(std::filesystem::path const &path) const {
|
||||
return std::visit(Visitor{[&path](std::filebuf const &) { return path.string(); },
|
||||
[](std::streambuf const *buf) {
|
||||
return buf == std::cin.rdbuf() ? "<stdin>" : "<stdout>";
|
||||
return std::string{buf == std::cin.rdbuf()
|
||||
? "<stdin>" : "<stdout>"};
|
||||
}},
|
||||
_file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user