emilk / emilk/loguru

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

Open
#232 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
280
Avg merge
7m
Merged PRs (30d)
4

Description

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:

```cpp
const auto needed = MultiByteToWideChar(CP_UTF8, 0, file_path, -1, nullptr, 0);
auto w_file_path = std::unique_ptr(new wchar_t[needed]);
MultiByteToWideChar(CP_UTF8, 0, file_path, -1, w_file_path.get(), needed);

if (_wmkdir(w_file_path.get()) == -1) {
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.