feat(libc): implement asctime_r #12841
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12841"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by heditrigui on 2026-10-29T12:11:27Z.
What
Implement POSIX / FreeBSD \sctime_r\ (NID \488p6whx47U) in \libc, formatting broken-down time into a caller-supplied buffer with identical formatting to \sctime. Refactor \sctime\ to delegate to \sctime_r\ via a thread-local buffer, throw \std::invalid_argument\ when given a null buffer, and verify formatting and error handling in \GuestStrftime\ and \GuestTimeConversion.
Tested
Checklist
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T13:00:01Z.
Review: COMMENTED
Reviewed head
d690c78347againstmain157b02c4f1. I ran this on macOS arm64 with Apple clang. No console was used.What I checked
python3 tools/nid_names.py --name asctime_rgives488p6whx47U.mainhas no otherasctime_r.git merge-tree --write-tree upstream/main <head>merges cleanly, andgit diff --checkis clean.check_conventions.py --base upstream/mainreports 0 errors but 1 warning:docs/dev/debt/libc.md:202: [debt-length] ... 1047 characters. The line was 909 characters onmain, so this PR pushes it over the 1000 limit.pr_overlap.py --branch <head>(1400 PRs): there are no same-export conflicts. Three PRs (#10895, #11843, #12593) touch the neighbouring debt lines 201-203. #10409 (CONFLICTING with main) touchesTime.cppand both tests, but it doesn't changeasctime.asctime_r/asctimefromTime.cpp,clampedField/tableName, and the PR'sCheckAsctimerows fromGuestStrftime, plus the null-tm and null-buffer rows. It passes. The fixed26is safe, because every field is clamped (Fri Oct 99 99:99:99 9999\nis 25 characters plus the NUL).Mutants (single edits to the new function):
snprintfsize 25snprintfsize 64errno = EINVALRequested change: a null buffer should throw instead of returning
nullptr. The debt line says "the null-buffer result is assumed". CONTRIBUTING asks for unknown behaviour to throw and be recorded, not for an assumed result. FreeBSD'sasctime_rdoesn't check the buffer at all, sonullptrisn't attested anywhere. Suggested change:<stdexcept>is already included inTime.cpp. The test inGuestTimeConversion.cppwould become:The debt sentence then shrinks below the limit (1047 → 987 characters):
I checked this variant in the same harness: it passes, and the current head fails the new row.
Minor point: the "Tested" section lists only
check_conventions. Please add which ctest targets (GuestStrftime,GuestTimeConversion) you ran and on which OS.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T13:58:19Z.
Review: APPROVED
Re-reviewed head
e908061e32againstmain3adb909203on macOS arm64 with Apple clang. I didn't use a console.The change since my last review matches what I asked for. A null buffer now throws
std::invalid_argumentbefore anything is written. There's a test row for it, and the debt sentence is short again: line 202 is 987 characters, andcheck_conventionspasses with no warnings.asctime_r/asctimeverbatim fromTime.cppwithclampedField/tableName/the name tables, plus everyCheckAsctimerow fromGuestStrftime, the null-tm and null-buffer rows fromGuestTimeConversion, and one extra widest-output row (Fri Oct 99 99:99:99 9999\n, 25 characters plus the NUL, which fits the fixed26). It passes.snprintfsize 25,errno = EINVALdropped, null-tm returningnullptr, the success path returningnullptr, the seconds field swapped for minutes, and the year modulus 100000.git diff --check,merge-treeagainst3adb909203andcheck_conventions --base upstream/mainare all clean.pr_overlapprobed 1407 PRs and found no conflicting files and no same exports. The only ones listed are PRs that already conflict withmainand shareApi.hpp/libc.md.LGTM.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:19Z.
Review: COMMENTED
Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (
Unblocks: noneis allowed), and it contained no code review.