For example, trying to save a log file to a path which contains Greek, Russian etc. letters. The problem is that _fsopen and mkdir on Windows treat the file path argument as encoded in the platform codepage, which can in theory be set to UTF-8 but in practice is most often a language-specific codepage like Latin-1.
To fix this, it's necessary to use _wfsopen and _wmkdir and convert the paths to wide char before calling the functions. Something along those lines:
const auto needed = MultiByteToWideChar(CP_UTF8, 0, file_path, -1, nullptr, 0);
auto w_file_path = std::unique_ptr<wchar_t[]>(new wchar_t[needed]);
MultiByteToWideChar(CP_UTF8, 0, file_path, -1, w_file_path.get(), needed);
if (_wmkdir(w_file_path.get()) == -1) {
For example, trying to save a log file to a path which contains Greek, Russian etc. letters. The problem is that
_fsopen
andmkdir
on Windows treat the file path argument as encoded in the platform codepage, which can in theory be set to UTF-8 but in practice is most often a language-specific codepage like Latin-1.To fix this, it's necessary to use
_wfsopen
and_wmkdir
and convert the paths to wide char before calling the functions. Something along those lines: