mattn / mattn/mruby-require

Filenames containing multibyte characters on Windows

Open
#65 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
42
Forks
24
PR merge metrics
No merged PRs in 30d

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 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](https://github.com/user-attachments/files/18587961/mruby-require_fopen.patch)

[textencoding_extracts.txt](https://github.com/user-attachments/files/18587666/textencoding_extracts.txt)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the fopen() and GetFullPathNameA() call sites, along with textencoding_windows.c and the attached mruby-require_fopen.patch. Check how UTF-8 filenames such as テスト.txt are handled on Windows with different locale settings, including the realpath() path. Done means those filenames open correctly without locale-dependent failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.