Skip to content

Filenames containing multibyte characters on Windows #65

@na6ko

Description

@na6ko

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 using GetFullPathNameW() in textencoding_windows.c, which is used in my project, as it required less effort. As a temporary measure, I removed realpath().
  • 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.

mruby-require_fopen.patch

textencoding_extracts.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions