diff --git a/src/lib/io/fstream.cpp b/src/lib/io/fstream.cpp index 4aef9073..ea91859d 100644 --- a/src/lib/io/fstream.cpp +++ b/src/lib/io/fstream.cpp @@ -54,4 +54,16 @@ void open_utf8_path(std::fstream& stream, const std::string& path, std::ios_base open_utf8_path_impl(stream, path, mode); } +std::FILE* fopen_utf8_path(const std::string& path, const std::string& mode) +{ +#if SYSAPI_WIN32 + auto wchar_path = utf8_to_win_char(path); + auto wchar_mode = utf8_to_win_char(mode); + return _wfopen(reinterpret_cast(wchar_path.data()), + reinterpret_cast(wchar_mode.data())); +#else + return std::fopen(path.c_str(), mode.c_str()); +#endif +} + } // namespace barrier diff --git a/src/lib/io/fstream.h b/src/lib/io/fstream.h index 26288373..2b327f18 100644 --- a/src/lib/io/fstream.h +++ b/src/lib/io/fstream.h @@ -18,6 +18,7 @@ #ifndef BARRIER_LIB_IO_FSTREAM_H #define BARRIER_LIB_IO_FSTREAM_H +#include #include #include @@ -30,6 +31,8 @@ void open_utf8_path(std::ofstream& stream, const std::string& path, void open_utf8_path(std::fstream& stream, const std::string& path, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out); +std::FILE* fopen_utf8_path(const std::string& path, const std::string& mode); + } // namespace barrier #endif