fix(libc): format strftime and asctime as FreeBSD 11 does #4543

Merged
coltken95 merged 1 commit from upstream-pr/4543 into main 2026-10-13 11:10:43 +00:00
coltken95 commented 2026-10-12 15:15:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-12T15:15:30Z.


What

strftime (libc) handed most conversions to the host's strftime, which differs from FreeBSD 11's:

  • E and O with conversions glibc does not pair them with were printed literally (%Ea, %OX, %OD, %OF).
  • Years outside 1000 to 9999: %Y printed 899 and -1 where FreeBSD prints 0899 and -001; %C, %y, %G, %g, %F, %c, %D and %v followed.
  • Out-of-range fields: %I of hour 100 gave 88 (FreeBSD 04), %u of weekday 8 gave 1 (FreeBSD 8), and %W differed.
  • Padding flags on %+ and %v left them unexpanded (%_+ printed literally); on Windows the %-, %_ and %0 flags printed nothing.

asctime printed the year as a plain number; FreeBSD formats it with %Y (0899) and sets years longer than four digits apart ( 12345).

strftime now follows FreeBSD 11 strftime.c with the C locale on both hosts, and asctime follows asctime.c. %s keeps the guest's local-time mktime. The TechnicalDebt entry is rewritten; the Windows gaps it listed are gone, and that the console's libc uses this code is recorded as not measured.

Tested

Linux (Ubuntu 24.04, GCC 13.3). Compared against FreeBSD 11 strftime.c and asctime.c compiled as references: 500000 random cases (every conversion, padding flag, E/O modifier and unknown character, out-of-range fields, years from -2147481748 to 2147485547, short buffers), in UTC and America/New_York; no differences. New guest_strftime test (one case per difference above, short buffer, null format, both asctime layouts); it fails before this change and passes after. All 44 libc guest_* tests registered in this configuration, plus guest_crt and guest_rtc, pass. Windows not built locally (no MinGW toolchain available). No title 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4831389165 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4543). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-12T15:15:30Z. --- ### What `strftime` (libc) handed most conversions to the host's `strftime`, which differs from FreeBSD 11's: - `E` and `O` with conversions glibc does not pair them with were printed literally (`%Ea`, `%OX`, `%OD`, `%OF`). - Years outside 1000 to 9999: `%Y` printed `899` and `-1` where FreeBSD prints `0899` and `-001`; `%C`, `%y`, `%G`, `%g`, `%F`, `%c`, `%D` and `%v` followed. - Out-of-range fields: `%I` of hour 100 gave `88` (FreeBSD `04`), `%u` of weekday 8 gave `1` (FreeBSD `8`), and `%W` differed. - Padding flags on `%+` and `%v` left them unexpanded (`%_+` printed literally); on Windows the `%-`, `%_` and `%0` flags printed nothing. `asctime` printed the year as a plain number; FreeBSD formats it with `%Y` (`0899`) and sets years longer than four digits apart (` 12345`). `strftime` now follows FreeBSD 11 [strftime.c](https://github.com/freebsd/freebsd-src/blob/5ed7eb0d97ba4436218e810f61bd059acba984c2/lib/libc/stdtime/strftime.c) with the C locale on both hosts, and `asctime` follows [asctime.c](https://github.com/freebsd/freebsd-src/blob/5ed7eb0d97ba4436218e810f61bd059acba984c2/contrib/tzcode/stdtime/asctime.c). `%s` keeps the guest's local-time `mktime`. The TechnicalDebt entry is rewritten; the Windows gaps it listed are gone, and that the console's libc uses this code is recorded as not measured. ### Tested Linux (Ubuntu 24.04, GCC 13.3). Compared against FreeBSD 11 `strftime.c` and `asctime.c` compiled as references: 500000 random cases (every conversion, padding flag, `E`/`O` modifier and unknown character, out-of-range fields, years from -2147481748 to 2147485547, short buffers), in UTC and America/New_York; no differences. New `guest_strftime` test (one case per difference above, short buffer, null format, both `asctime` layouts); it fails before this change and passes after. All 44 libc `guest_*` tests registered in this configuration, plus `guest_crt` and `guest_rtc`, pass. Windows not built locally (no MinGW toolchain available). No title 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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
oneandonlydean commented 2026-10-13 05:21:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T05:21:19Z.


Needs a rebase: docs/dev/debt/libc.md conflicts with the entries merged today (#4733, #4811). The code merges cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6138843157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4543#issuecomment-6138843157). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T05:21:19Z. --- Needs a rebase: `docs/dev/debt/libc.md` conflicts with the entries merged today (#4733, #4811). The code merges cleanly.
xXPBSXx commented 2026-10-13 06:13:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T06:13:13Z.


Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release: this PR merged onto main ea2bbefb2 (the only merge conflict is docs/dev/debt/libc.md; I took this PR's side for the build).

  • guest_strftime (this PR), guest_time_conversion and guest_mktime pass.
  • As a counter-check I ran a local extra test, not part of this PR, with the padding-flag and modifier cases of FreeBSD 11.4's strftime for 2009-02-07 03:04:05 UTC (single-digit day, hour, minute, second, month, week): %-, %_ and %0 on each of %d %e %H %I %j %k %l %M %m %S %U %W %V, the flag with E / O before and after it (%-Ed, %_Od, %E-e, %O0k), the flag on conversions that ignore it (%-y, %_Y, %0C, %-D, %_T, %0F, %-a, %_b, %0p, %-n, %_t), %_v and %0+. All 9 format strings (about 60 conversions) give the FreeBSD result with this PR.
  • The same cases on main fail: strftime(buf, n, "%-d|%-e|...", &tm) returns 0 with an empty string on Windows, so the Windows part of the description is reproduced and fixed.

Not tested: Linux, a console, a title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139477635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4543#issuecomment-6139477635). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T06:13:13Z. --- Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release: this PR merged onto `main` `ea2bbefb2` (the only merge conflict is `docs/dev/debt/libc.md`; I took this PR's side for the build). - `guest_strftime` (this PR), `guest_time_conversion` and `guest_mktime` pass. - As a counter-check I ran a local extra test, not part of this PR, with the padding-flag and modifier cases of FreeBSD 11.4's `strftime` for 2009-02-07 03:04:05 UTC (single-digit day, hour, minute, second, month, week): `%-`, `%_` and `%0` on each of `%d %e %H %I %j %k %l %M %m %S %U %W %V`, the flag with `E` / `O` before and after it (`%-Ed`, `%_Od`, `%E-e`, `%O0k`), the flag on conversions that ignore it (`%-y`, `%_Y`, `%0C`, `%-D`, `%_T`, `%0F`, `%-a`, `%_b`, `%0p`, `%-n`, `%_t`), `%_v` and `%0+`. All 9 format strings (about 60 conversions) give the FreeBSD result with this PR. - The same cases on `main` fail: `strftime(buf, n, "%-d|%-e|...", &tm)` returns 0 with an empty string on Windows, so the Windows part of the description is reproduced and fixed. Not tested: Linux, a console, a title run. AI-assisted (Claude Code).
coltken95 commented 2026-10-13 10:19:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T10:19:02Z.


Rebased onto 77b9f7270. The docs/dev/debt/libc.md conflicts are resolved: #4811's localtime, mktime entry is kept as merged, and this PR's strftime and asctime entry replaces the old strftime one, followed by #4226's wcsftime entry. wcsftime now runs on this strftime; all 51 libc guest_* tests pass on Linux, including guest_strftime and the wcsftime cases.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143384866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4543#issuecomment-6143384866). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T10:19:02Z. --- Rebased onto 77b9f7270. The `docs/dev/debt/libc.md` conflicts are resolved: #4811's `localtime, mktime` entry is kept as merged, and this PR's `strftime and asctime` entry replaces the old `strftime` one, followed by #4226's `wcsftime` entry. `wcsftime` now runs on this `strftime`; all 51 libc `guest_*` tests pass on Linux, including `guest_strftime` and the `wcsftime` cases. AI-assisted: yes
github-actions[bot] commented 2026-10-13 10:28:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T10:28:32Z.


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
#5009 core/libs/prx/libc/src/Time.cpp L237
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143542355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4543#issuecomment-6143542355). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T10:28:32Z. --- <!-- 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 | |---|---|---|---| | #5009 | `core/libs/prx/libc/src/Time.cpp` [L237](https://github.com/boykopovar/AnyPS5/blob/b1328fc0f9012e820fb92c8fdbbb4af02007bd48/core/libs/prx/libc/src/Time.cpp#L237) | | |
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!4543
No description provided.