fix(libc): open fopen and freopen paths through the wide CRT on Windows #2588

Closed
xXPBSXx wants to merge 1 commit from upstream-pr/2588 into main
xXPBSXx commented 2026-10-10 07:12:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-10T07:12:14Z.


What

On Windows, the guest fopen and freopen pass the resolved path to the narrow CRT, which reads it in the ANSI code page. UTF-8 guest file names are garbled: a guest that writes セーブé.tmp with fopen creates a host file named セーブé.tmp and cannot read it back.

fopen now uses _wfopen and freopen uses _wfreopen with the path as std::filesystem::path. Other platforms are unchanged. FileStream::Reopen takes a path instead of a narrow string.

Fixes #2329. Same approach as #2335 for directory entries.

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON.

  • file_streams has a new case: write, read back and freopen of セーブé.tmp, checking the name and size on disk. It fails on current main (the file is created as セーブé.tmp) and passes with this change.
  • Full ctest: 641 tests. 13 failed in one run: 11 relinker tests failed because Malwarebytes quarantined their generated executables in the temp directory; with TEMP and TMP on an excluded directory all 11 pass. video_out_flip_controls crashed in the parallel run and is skipped when run alone. agc_driver_f32_arithmetic_nan fails on an NVIDIA RTX 4080 SUPER (0x7fc12345 instead of 0x7f812345 in v_fmamk_f32); it does not touch libc, but I did not run it on an unmodified main.
  • tools/check_conventions.py passes.

Linux, macOS, PS5 hardware and titles: not tested.

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:4809491317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2588). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-10T07:12:14Z. --- ### What On Windows, the guest `fopen` and `freopen` pass the resolved path to the narrow CRT, which reads it in the ANSI code page. UTF-8 guest file names are garbled: a guest that writes `セーブé.tmp` with `fopen` creates a host file named `セーブé.tmp` and cannot read it back. `fopen` now uses `_wfopen` and `freopen` uses `_wfreopen` with the path as `std::filesystem::path`. Other platforms are unchanged. `FileStream::Reopen` takes a path instead of a narrow string. Fixes #2329. Same approach as #2335 for directory entries. ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `BUILD_TESTING=ON`. - `file_streams` has a new case: write, read back and `freopen` of `セーブé.tmp`, checking the name and size on disk. It fails on current `main` (the file is created as `セーブé.tmp`) and passes with this change. - Full ctest: 641 tests. 13 failed in one run: 11 relinker tests failed because Malwarebytes quarantined their generated executables in the temp directory; with `TEMP` and `TMP` on an excluded directory all 11 pass. `video_out_flip_controls` crashed in the parallel run and is skipped when run alone. `agc_driver_f32_arithmetic_nan` fails on an NVIDIA RTX 4080 SUPER (`0x7fc12345` instead of `0x7f812345` in `v_fmamk_f32`); it does not touch libc, but I did not run it on an unmodified `main`. - `tools/check_conventions.py` passes. Linux, macOS, PS5 hardware and titles: not tested. ### 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)
github-actions[bot] commented 2026-10-10 07:12:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T07:12:58Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095004310 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2588#issuecomment-6095004310). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T07:12:58Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

Pull request closed

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!2588
No description provided.