Files
YYCCommonplace/src/IOHelper.cpp

26 lines
546 B
C++
Raw Normal View History

2024-04-25 10:38:13 +08:00
#include "IOHelper.hpp"
2024-04-26 15:37:28 +08:00
#if YYCC_OS == YYCC_OS_WINDOWS
2024-04-25 10:38:13 +08:00
#include "EncodingHelper.hpp"
#include <cstdio>
#include <iostream>
namespace YYCC::IOHelper {
2024-04-26 15:37:28 +08:00
FILE* FOpen(const char* u8_filepath, const char* u8_mode) {
2024-04-25 10:38:13 +08:00
std::wstring wmode, wpath;
bool suc = YYCC::EncodingHelper::CharToWchar(u8_mode, wmode, CP_UTF8);
suc = suc && YYCC::EncodingHelper::CharToWchar(u8_filepath, wpath, CP_UTF8);
if (suc) {
return _wfopen(wpath.c_str(), wmode.c_str());
} else {
// fallback
return std::fopen(u8_filepath, u8_mode);
}
}
}
2024-04-26 15:37:28 +08:00
#endif