Fix file_stream for windows
This commit is contained in:
parent
0cf6ee13dc
commit
749c026d7c
1 changed files with 4 additions and 2 deletions
|
|
@ -1,18 +1,20 @@
|
||||||
#include <psemek/io/file_stream.hpp>
|
#include <psemek/io/file_stream.hpp>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
namespace psemek::io
|
namespace psemek::io
|
||||||
{
|
{
|
||||||
|
|
||||||
static void throw_fopen [[noreturn]] (std::filesystem::path const & path)
|
static void throw_fopen [[noreturn]] (std::filesystem::path const & path)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to open " + path.native() + ": " + std::string(std::strerror(errno)));
|
throw std::runtime_error("Failed to open " + path.string() + ": " + std::string(std::strerror(errno)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static FILE * safe_fopen(std::filesystem::path const & path, const char * mode)
|
static FILE * safe_fopen(std::filesystem::path const & path, const char * mode)
|
||||||
{
|
{
|
||||||
auto f = std::fopen(path.c_str(), mode);
|
std::string path_str = path.string();
|
||||||
|
auto f = std::fopen(path_str.c_str(), mode);
|
||||||
if (!f) throw_fopen(path);
|
if (!f) throw_fopen(path);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue