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

Closed
Aerovity wants to merge 1 commit from upstream-pr/2361 into main
Aerovity commented 2026-10-09 16:20:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aerovity on 2026-10-09T16:20:14Z.


What

Fixes #2329.

Guest paths are UTF-8, but on Windows the guest fopen and freopen passed the resolved path to the narrow CRT std::fopen/std::freopen, which read the name in the ANSI code page. Non-ASCII names were created garbled and could not be opened again.

  • FileStream.hpp: OpenNativeFile(path, mode) opens through _wfopen with the std::filesystem::path on Windows (std::fopen elsewhere). FileStream::Reopen takes a std::filesystem::path and uses _wfreopen on Windows.
  • FileAndHeap.cpp: fopen and freopen pass the resolved path itself instead of path.string().
  • GuestFiopen.cpp: creates セーブ with fopen and café with freopen, checks the host names with std::filesystem, and reads both back.

Note: #1549, #2033 and #2170 also change the fopen line, as the issue says. This is a small change that can be rebased onto whichever lands first.

Tested

Not tested: not built or 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: N/A
  • 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: N/A
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4803043320 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2361). Originally posted by [Aerovity](https://github.com/Aerovity) on 2026-10-09T16:20:14Z. --- ### What Fixes #2329. Guest paths are UTF-8, but on Windows the guest `fopen` and `freopen` passed the resolved path to the narrow CRT `std::fopen`/`std::freopen`, which read the name in the ANSI code page. Non-ASCII names were created garbled and could not be opened again. - `FileStream.hpp`: `OpenNativeFile(path, mode)` opens through `_wfopen` with the `std::filesystem::path` on Windows (`std::fopen` elsewhere). `FileStream::Reopen` takes a `std::filesystem::path` and uses `_wfreopen` on Windows. - `FileAndHeap.cpp`: `fopen` and `freopen` pass the resolved path itself instead of `path.string()`. - `GuestFiopen.cpp`: creates `セーブ` with `fopen` and `café` with `freopen`, checks the host names with `std::filesystem`, and reads both back. Note: #1549, #2033 and #2170 also change the `fopen` line, as the issue says. This is a small change that can be rebased onto whichever lands first. ### Tested Not tested: not built or 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt: N/A - [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: N/A - [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-09 16:32:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T16:32:30Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2170 core/libs/prx/libc/include/FileStream.hpp L3-5, L34, L69-107
core/libs/prx/libc/src/FileAndHeap.cpp L65-66, L79-109
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085034715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2361#issuecomment-6085034715). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T16:32:30Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2170 | `core/libs/prx/libc/include/FileStream.hpp` [L3-5](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/include/FileStream.hpp#L3-L5), [L34](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/include/FileStream.hpp#L34), [L69-107](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/include/FileStream.hpp#L69-L107)<br>`core/libs/prx/libc/src/FileAndHeap.cpp` [L65-66](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/src/FileAndHeap.cpp#L65-L66), [L79-109](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/core/libs/prx/libc/src/FileAndHeap.cpp#L79-L109) | | |
popcoder565 commented 2026-10-09 19:41:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:41:44Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 434e917a, merged onto main 8b393b6e in one build with 31 other PRs that had no Windows run.

  • This PR's tests pass: guest_fiopen.
  • Full ctest in that build: 520 of 521. The one failure is guest_offline_imports, broken by #2359 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088007827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2361#issuecomment-6088007827). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T19:41:44Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `434e917a`, merged onto `main` 8b393b6e in one build with 31 other PRs that had no Windows run. - This PR's tests pass: `guest_fiopen`. - Full ctest in that build: 520 of 521. The one failure is `guest_offline_imports`, broken by #2359 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
oneandonlydean commented 2026-10-09 20:12:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:12:23Z.


Closing: it hasn't been built or run, and #1549, #2033 and #2170 all change this fopen line. Reopen once it builds and the new test passes on Windows after those settle.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088477059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2361#issuecomment-6088477059). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:12:23Z. --- Closing: it hasn't been built or run, and #1549, #2033 and #2170 all change this `fopen` line. Reopen once it builds and the new test passes on Windows after those settle.

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