-
-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
The fopen() function is used to open files, but it does not work correctly when the filename contains multibyte (UTF-8) characters on Windows. Specifically, when the filename includes non-ASCII characters (e.g., Japanese "テスト.txt"), there is an issue where the file cannot be opened.
If the string passed to fopen() is in CP932 multibyte encoding, it works fine on a Japanese Windows system. However, this issue does not get resolved on Windows with different locale settings.
I replaced fopen() and GetFullPathNameA() with _wfopen() and GetFullPathNameW(). The issue was resolved by modifying the code as shown below, and I confirmed that it works correctly.
- Changing the arguments of
MAKELANGID()to English is not a mandatory modification. This decision is based on my personal preference to prevent situations where users encounter garbled characters and find it difficult to contact the developer, or to avoid the effort of deciphering an unfamiliar language for the developer. - To handle
realpath(), I implemented preprocessing usingGetFullPathNameW()intextencoding_windows.c, which is used in my project, as it required less effort. As a temporary measure, I removedrealpath(). - The code snippets and modifications provided are based on the coding style used in my project. If necessary, please adapt the code to fit the coding guidelines of the target project.
- The same issue exists in mruby (with the use of
_open()), and I plan to post a separate issue about it.
Metadata
Metadata
Assignees
Labels
No labels