fix(libc): accept the ' flag in Windows formatting #3567

Merged
DariusHQ merged 1 commit from upstream-pr/3567 into main 2026-10-11 21:34:57 +00:00
DariusHQ commented 2026-10-11 13:26:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DariusHQ on 2026-10-11T13:26:54Z.


What

FreeBSD's vfprintf takes ' as a flag: group the integer part of d, i, u, f, F, g and G with the locale's thousands separator. The guest formatter (FormatWindows) did not know it and threw Unsupported format conversion, so printf("%'d", n) from a title aborted on Windows.

The guest's setlocale accepts only "C", "POSIX" and "", all the C locale, and its localeconv() reports an empty thousands_sep and grouping. So ' never changes the output. The formatter now skips it before it hands the conversion to the host's snprintf, which also keeps the host's own locale from adding separators. TechnicalDebt no longer lists the ' flag among what the guest formatter throws for.

The formatter is shared: Windows runs it for every format, Linux only for formats with a guest wide conversion (%ls, %lc, %S, %C) and hands the rest to glibc, which already accepts '.

Tested

Windows 11 (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with BUILD_TESTING=ON on main a11c8f7f7 with four branches merged together: this one and the %#.0o, ' flag, positional-argument and sendfile branches opened alongside it: ctest 833/837 passed. The four failures fail the same way on main here:

  • windows_exceptions (#3411);
  • guest_kernel_sys: symlink throws Function not implemented on Windows, which #3510 addresses;
  • guest_filesystem: restoring the directory time fails on Windows, which #3518 addresses;
  • agc_driver_emulated_color_compare: the GPU here cannot sample the sRGB image it uses.

guest_formatting now formats ' through snprintf and vsnprintf: with d, u, f and g; next to -, + and 0; with a width, a precision and the l, ll and z lengths; and in a format with %ls. It fails without the fix.

Not run on Linux (no Linux host here); the change has no platform-specific part.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819395184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3567). Originally posted by [DariusHQ](https://github.com/DariusHQ) on 2026-10-11T13:26:54Z. --- ### What FreeBSD's `vfprintf` takes `'` as a flag: group the integer part of `d`, `i`, `u`, `f`, `F`, `g` and `G` with the locale's thousands separator. The guest formatter (`FormatWindows`) did not know it and threw `Unsupported format conversion`, so `printf("%'d", n)` from a title aborted on Windows. The guest's `setlocale` accepts only `"C"`, `"POSIX"` and `""`, all the C locale, and its `localeconv()` reports an empty `thousands_sep` and `grouping`. So `'` never changes the output. The formatter now skips it before it hands the conversion to the host's `snprintf`, which also keeps the host's own locale from adding separators. TechnicalDebt no longer lists the `'` flag among what the guest formatter throws for. The formatter is shared: Windows runs it for every format, Linux only for formats with a guest wide conversion (`%ls`, `%lc`, `%S`, `%C`) and hands the rest to glibc, which already accepts `'`. ### Tested Windows 11 (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with `BUILD_TESTING=ON` on `main` `a11c8f7f7` with four branches merged together: this one and the `%#.0o`, `'` flag, positional-argument and `sendfile` branches opened alongside it: `ctest` 833/837 passed. The four failures fail the same way on `main` here: - `windows_exceptions` (#3411); - `guest_kernel_sys`: `symlink` throws `Function not implemented` on Windows, which #3510 addresses; - `guest_filesystem`: restoring the directory time fails on Windows, which #3518 addresses; - `agc_driver_emulated_color_compare`: the GPU here cannot sample the sRGB image it uses. `guest_formatting` now formats `'` through `snprintf` and `vsnprintf`: with `d`, `u`, `f` and `g`; next to `-`, `+` and `0`; with a width, a precision and the `l`, `ll` and `z` lengths; and in a format with `%ls`. It fails without the fix. Not run on Linux (no Linux host here); the change has no platform-specific part. ### 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
github-actions[bot] commented 2026-10-11 21:10:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T21:10:02Z.


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
#3990 docs/dev/TechnicalDebt.md L555-556
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113787332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3567#issuecomment-6113787332). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T21:10:02Z. --- <!-- 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 | |---|---|---|---| | #3990 | `docs/dev/TechnicalDebt.md` [L555-556](https://github.com/boykopovar/AnyPS5/blob/1770f352d7546c1eae9cf1e1441e1ae2428dc3a0/docs/dev/TechnicalDebt.md#L555-L556) | | |
adriadam10 commented 2026-10-11 21:34:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:34:46Z.


Checked the diff against FreeBSD vfprintf (' flag, no effect in the C locale), build + ctest on the touched libs (74 tests green), and that guest_formatting fails without the change; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114028860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3567#issuecomment-6114028860). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:34:46Z. --- Checked the diff against FreeBSD `vfprintf` (`'` flag, no effect in the C locale), build + ctest on the touched libs (74 tests green), and that `guest_formatting` fails without the change; merging.
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!3567
No description provided.