Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging to files fails on Windows if the path contains Unicode characters #232

Open
lethal-guitar opened this issue Nov 20, 2022 · 0 comments

Comments

@lethal-guitar
Copy link

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) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant