Fix file_stream for windows

This commit is contained in:
Nikita Lisitsa 2021-04-26 01:51:09 +03:00
parent 0cf6ee13dc
commit 749c026d7c

View file

@ -1,18 +1,20 @@
#include <psemek/io/file_stream.hpp>
#include <cstring>
#include <codecvt>
namespace psemek::io
{
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)
{
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);
return f;
}