fix(libc): support the FreeBSD strftime conversions %k %l %s %v and %+ on Windows #2702

Closed
husseinkad wants to merge 4 commits from upstream-pr/2702 into main
husseinkad commented 2026-10-10 11:33:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T11:33:58Z.


What

The guest strftime passes the format to the Windows CRT, which does not know %k, %l, %s, %v and %+. The call returned 0 and wrote nothing. FreeBSD's strftime(3) documents all five:

  • %k is the hour (24-hour clock), blank-padded; %l the hour (12-hour clock), blank-padded
  • %s is the seconds since the Epoch: mktime of the broken-down time in the local time zone, as in FreeBSD 9 and 11 (current FreeBSD uses tm_gmtoff), -1 if it cannot be represented
  • %v is %e-%b-%Y
  • %+ is %a %b %e %H:%M:%S %Z %Y in the C locale, with %Z taken from the broken-down time's tm_zone (or tzname[tm_isdst != 0] when it is null)

Time.cpp expands these five before calling the host strftime. E and O modifiers in front of them are accepted as in FreeBSD's _fmt(); %%k stays literal, and %E%/%O% are copied as one unit so the next character stays literal, as the host and FreeBSD treat them. A format that contains none of the five goes to the host untouched. The caller's tm is never modified (%s works on a copy). What is still different (padding flags on the new conversions, an unknown conversion or a trailing lone %, a doubled modifier, %P, a standalone %z/%Z) is recorded in TechnicalDebt.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:

  • guest_time_conversion (fixed epoch 1700000000, TZ=UTC-2) covers all five conversions, hours 0/12/13 and single-digit padding, exact fit and one byte short, %%k/%%%k, %E%k and friends, the E/O forms, a tm_zone that differs from the host's zone name, a null tm_zone with tm_isdst 0 and 1, and %s against mktime. It fails with Time.cpp reverted and passes with the change; ctest -R guest_time passes.
  • Outside the repo, differential runs against main's Time.cpp, built from the same sources: about 3.0M format/tm/size cases (7 TZ settings, hours -12 to INT_MAX, tm_year extremes, buffer sizes 0 to 255 and 4 MB formats) against an independent FreeBSD strftime reference: 0 differences for formats without the new conversions, no regression, no overrun, the caller's tm unchanged, about 52.5k cases fixed; and all 111,111 formats of length 0 to 5 over %EOkls+vZa against a reference written from FreeBSD's _fmt() (read at releng/9.3, 11.0, 13.2 and 14.0): 0 mismatches.
  • tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py --branch reports no overlap. Closed PR #2665 also edits strftime (to preserve tm_zone for %z/%Z); this change leaves a standalone %z/%Z alone, so the two touch different behaviour but the same function.
  • Linux not run (the new code is platform-independent; the non-Windows tzname fallback is untested).

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
  • 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:4810892203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2702). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T11:33:58Z. --- ### What The guest `strftime` passes the format to the Windows CRT, which does not know `%k`, `%l`, `%s`, `%v` and `%+`. The call returned 0 and wrote nothing. FreeBSD's `strftime(3)` documents all five: - `%k` is the hour (24-hour clock), blank-padded; `%l` the hour (12-hour clock), blank-padded - `%s` is the seconds since the Epoch: `mktime` of the broken-down time in the local time zone, as in FreeBSD 9 and 11 (current FreeBSD uses `tm_gmtoff`), `-1` if it cannot be represented - `%v` is `%e-%b-%Y` - `%+` is `%a %b %e %H:%M:%S %Z %Y` in the C locale, with `%Z` taken from the broken-down time's `tm_zone` (or `tzname[tm_isdst != 0]` when it is null) `Time.cpp` expands these five before calling the host `strftime`. `E` and `O` modifiers in front of them are accepted as in FreeBSD's `_fmt()`; `%%k` stays literal, and `%E%`/`%O%` are copied as one unit so the next character stays literal, as the host and FreeBSD treat them. A format that contains none of the five goes to the host untouched. The caller's `tm` is never modified (`%s` works on a copy). What is still different (padding flags on the new conversions, an unknown conversion or a trailing lone `%`, a doubled modifier, `%P`, a standalone `%z`/`%Z`) is recorded in TechnicalDebt. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release: - `guest_time_conversion` (fixed epoch 1700000000, `TZ=UTC-2`) covers all five conversions, hours 0/12/13 and single-digit padding, exact fit and one byte short, `%%k`/`%%%k`, `%E%k` and friends, the `E`/`O` forms, a `tm_zone` that differs from the host's zone name, a null `tm_zone` with `tm_isdst` 0 and 1, and `%s` against `mktime`. It fails with `Time.cpp` reverted and passes with the change; `ctest -R guest_time` passes. - Outside the repo, differential runs against `main`'s `Time.cpp`, built from the same sources: about 3.0M format/tm/size cases (7 TZ settings, hours -12 to INT_MAX, `tm_year` extremes, buffer sizes 0 to 255 and 4 MB formats) against an independent FreeBSD `strftime` reference: 0 differences for formats without the new conversions, no regression, no overrun, the caller's `tm` unchanged, about 52.5k cases fixed; and all 111,111 formats of length 0 to 5 over `%EOkls+vZa` against a reference written from FreeBSD's `_fmt()` (read at releng/9.3, 11.0, 13.2 and 14.0): 0 mismatches. - `tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py --branch` reports no overlap. Closed PR #2665 also edits `strftime` (to preserve `tm_zone` for `%z`/`%Z`); this change leaves a standalone `%z`/`%Z` alone, so the two touch different behaviour but the same function. - Linux not run (the new code is platform-independent; the non-Windows `tzname` fallback is untested). ### 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 - [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-10 11:34:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T11:34:08Z.


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:6097066679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2702#issuecomment-6097066679). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T11:34:08Z. --- 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!2702
No description provided.