fix(libc): read directory entries through the wide dirent API on Windows #2335

Merged
reyani-dev merged 1 commit from upstream-pr/2335 into main 2026-10-10 04:47:04 +00:00
reyani-dev commented 2026-10-09 15:48:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T15:48:36Z.


What

The guest passes and expects UTF-8 path names. On Windows, though, opendir/readdir in Directory.cpp used MinGW's narrow dirent API (opendir, readdir), which works in the ANSI code page. The result:

  • opendir failed for a directory whose UTF-8 name contains characters outside the code page (e.g. セーブ on a Western code page).
  • readdir returned entry names as ANSI bytes rather than UTF-8. A character the code page lacks came back as ?, so the guest could not open the entry it had just listed.

On Windows the directory is now opened with _wopendir and read with _wreaddir (_wclosedir/_wrewinddir for the rest), and each name is converted to UTF-8 with std::filesystem::path::u8string(). Linux keeps DIR/readdir, since its names are already bytes.

This is the directory half of #2329. The fopen/freopen half is left out on purpose, because #1549, #2033 and #2170 already touch that line.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • GuestDirectory.cpp has a new case. It creates セーブ/été.txt, opens the directory with opendir using its UTF-8 path, and requires that readdir return été.txt in UTF-8 with type DT_REG, plus . and ...
    • On main it fails: opendir returns null.
    • With the fix it passes.
  • ctest -E "^agc_|video_out": 249/249.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap.

A Linux and Windows full build will be posted here once it has run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802702301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2335). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T15:48:36Z. --- ### What The guest passes and expects UTF-8 path names. On Windows, though, `opendir`/`readdir` in `Directory.cpp` used MinGW's narrow dirent API (`opendir`, `readdir`), which works in the ANSI code page. The result: - `opendir` failed for a directory whose UTF-8 name contains characters outside the code page (e.g. `セーブ` on a Western code page). - `readdir` returned entry names as ANSI bytes rather than UTF-8. A character the code page lacks came back as `?`, so the guest could not open the entry it had just listed. On Windows the directory is now opened with `_wopendir` and read with `_wreaddir` (`_wclosedir`/`_wrewinddir` for the rest), and each name is converted to UTF-8 with `std::filesystem::path::u8string()`. Linux keeps `DIR`/`readdir`, since its names are already bytes. This is the directory half of #2329. The `fopen`/`freopen` half is left out on purpose, because #1549, #2033 and #2170 already touch that line. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - `GuestDirectory.cpp` has a new case. It creates `セーブ/été.txt`, opens the directory with `opendir` using its UTF-8 path, and requires that `readdir` return `été.txt` in UTF-8 with type `DT_REG`, plus `.` and `..`. - On `main` it fails: `opendir` returns null. - With the fix it passes. - `ctest -E "^agc_|video_out"`: 249/249. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. A Linux and Windows full build will be posted here once it has run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
reyani-dev commented 2026-10-09 16:30:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T16:30:17Z.


Full Linux and Windows builds and tests for this head (46786b1e), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux success; full build, ctest: 516/516 passed
windows success; full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084998682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2335#issuecomment-6084998682). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T16:30:17Z. --- Full Linux and Windows builds and tests for this head (`46786b1e`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`d70b8998`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946/job/113901593690) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946/job/113901593948) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946
reyani-dev commented 2026-10-09 16:30:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T16:30:23Z.


Full Linux and Windows builds and tests for this head (46786b1e), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux success; full build, ctest: 516/516 passed
windows success; full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085000498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2335#issuecomment-6085000498). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T16:30:23Z. --- Full Linux and Windows builds and tests for this head (`46786b1e`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`d70b8998`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946/job/113901593690) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946/job/113901593948) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37954522946
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2335
No description provided.