feat(libc): scan 16-bit wide conversions in fscanf on Linux #5291

Closed
Nixitov wants to merge 2 commits from upstream-pr/5291 into main
Nixitov commented 2026-10-13 16:37:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-13T16:37:00Z.


What

Follows #5285, which taught vsscanf/sscanf the 16-bit wide conversions on Linux. fscanf still threw for them; it now scans them the same way:

  • %ls, %S, %lc, %C decode the stream's UTF-8 into the guest's 16-bit buffer independently of the host locale, a code point above U+FFFF becoming a surrogate pair;
  • %l[ is scanned through the host's wide scanset;
  • literals, whitespace and %n counts are read one character at a time, so the stream position and the reported counts match;
  • the non-wide conversions keep the host's vfscanf behaviour.

The _s forms still throw for wide conversions on Linux.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.

  • guest_standard_streams gains a wide case — a %ls %ls scan of a file written through fprintf, followed by a %lc at end of file; it passes.
  • guest_formatting and guest_wide_formatting pass; python tools/check_conventions.py --base origin/main passes.
  • This machine runs the Windows path (ScanFileWindows), so the new Linux stream scanner is exercised by Linux CI, not locally. The behaviour is recorded in docs/dev/debt/libc.md.

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 under Silent stubs in their library's technical debt file
  • 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: #5285
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846394928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5291). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-13T16:37:00Z. --- ### What Follows #5285, which taught `vsscanf`/`sscanf` the 16-bit wide conversions on Linux. `fscanf` still threw for them; it now scans them the same way: - `%ls`, `%S`, `%lc`, `%C` decode the stream's UTF-8 into the guest's 16-bit buffer independently of the host locale, a code point above U+FFFF becoming a surrogate pair; - `%l[` is scanned through the host's wide scanset; - literals, whitespace and `%n` counts are read one character at a time, so the stream position and the reported counts match; - the non-wide conversions keep the host's `vfscanf` behaviour. The `_s` forms still throw for wide conversions on Linux. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. - `guest_standard_streams` gains a wide case — a `%ls %ls` scan of a file written through `fprintf`, followed by a `%lc` at end of file; it passes. - `guest_formatting` and `guest_wide_formatting` pass; `python tools/check_conventions.py --base origin/main` passes. - This machine runs the Windows path (`ScanFileWindows`), so the new Linux stream scanner is exercised by Linux CI, not locally. The behaviour is recorded in `docs/dev/debt/libc.md`. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: #5285 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 16:37:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T16:37:43Z.


Progress report (016db92 → b4a53f6)

📈 System libraries: 88.24% (+0.05%, +2 implemented functions)

✅ 2 implemented
Library Name
libc fscanf_nid_postfix
libc vsscanf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150397968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5291#issuecomment-6150397968). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T16:37:43Z. --- <!-- progress-report --> ### Progress report (016db92 → b4a53f6) 📈 **System libraries**: 88.24% (+0.05%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `fscanf_nid_postfix` | | libc | `vsscanf_nid_postfix` | </details>
github-actions[bot] commented 2026-10-13 17:00:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T17:00:38Z.


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
#4966 core/libs/prx/libc/src/Formatting.cpp L97-98, L293, L377, L396
#5222 core/libs/prx/libc/src/Formatting.cpp L11
#5330 core/libs/prx/libc/src/Formatting.cpp L11
#5606 core/libs/prx/libc/src/Formatting.cpp L98-99, L374, L393, L396
docs/dev/debt/libc.md L56
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150813975 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5291#issuecomment-6150813975). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T17:00:38Z. --- <!-- 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 | |---|---|---|---| | #4966 | `core/libs/prx/libc/src/Formatting.cpp` [L97-98](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L97-L98), [L293](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L293), [L377](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L377), [L396](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L396) | | | | #5222 | `core/libs/prx/libc/src/Formatting.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L11) | | | | #5330 | `core/libs/prx/libc/src/Formatting.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L11) | | | | #5606 | `core/libs/prx/libc/src/Formatting.cpp` [L98-99](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L98-L99), [L374](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L374), [L393](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L393), [L396](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L396)<br>`docs/dev/debt/libc.md` [L56](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libc.md#L56) | | |
Nixitov commented 2026-10-13 17:03:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-13T17:03:27Z.


Thanks bot. Same adjacent overlap as #5285, which this PR depends on: the wide-scanning scanner lives in Formatting.cpp, which #4966 (suppressed conversions before EOF) and #5222 (EOF stickiness) also touch. The stream scanner added here (ScanWideFile) sits next to ScanGuest.

No duplicated logic; this builds on #5285. Whoever lands second needs a small rebase, and I'll align the wide scanners' input-failure/EOF return values with #5222's ScanResultAtEndOfFile when it lands.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150864570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5291#issuecomment-6150864570). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-13T17:03:27Z. --- Thanks bot. Same adjacent overlap as #5285, which this PR depends on: the wide-scanning scanner lives in `Formatting.cpp`, which #4966 (suppressed conversions before EOF) and #5222 (EOF stickiness) also touch. The stream scanner added here (`ScanWideFile`) sits next to `ScanGuest`. No duplicated logic; this builds on #5285. Whoever lands second needs a small rebase, and I'll align the wide scanners' input-failure/EOF return values with #5222's `ScanResultAtEndOfFile` when it lands. AI-assisted: yes
oneandonlydean commented 2026-10-14 02:29:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:29:33Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159548320 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5291#issuecomment-6159548320). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:29:33Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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