libc: strftime returns 0 and writes nothing for the FreeBSD conversions %k, %l, %s, %v and %+ on Windows #3106
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-10T22:18:01Z.
What
The guest
strftime(core/libs/prx/libc/src/Time.cpp) passes the format to the Windows CRT, which does not know%k,%l,%s,%vand%+: the call returns 0 and writes nothing. FreeBSD'sstrftime(3)documents all five:%kis the hour (24-hour clock), blank-padded;%lthe hour (12-hour clock), blank-padded%sis the seconds since the Epoch:mktimeof the broken-down time in the local time zone, as in FreeBSD 9 and 11 (current FreeBSD usestm_gmtoff),-1if it cannot be represented%vis%e-%b-%Y%+is%a %b %e %H:%M:%S %Z %Yin the C locale, with%Ztaken from the broken-down time'stm_zone(ortzname[tm_isdst != 0]when it is null)Reproduce
Windows 11, WinLibs GCC 15.2.0 r7,
mainat the time of writing:strftime(buffer, 64, "%k|%l", &tm)returns 0 for a validtm(FreeBSD: for hour 22,22|10).Fix
A tested fix is on my fork:
husseinkad:fix/libc-time-strftime-freebsd-conversions(five commits onmain; PR #2702, closed by the intake check):Time.cppexpands the five conversions itself before calling the hoststrftime.EandOmodifiers in front of them are accepted as in FreeBSD's_fmt();%%kstays literal and%E%/%O%are copied as one unit so the next character stays literal; a format without any of the five goes to the host untouched; the caller'stmis never modified. What is still different (padding flags on the new conversions, an unknown conversion or a trailing lone%, a doubled modifier,%P, a standalone%z/%Zusing the host zone) is recorded in TechnicalDebt; closed PR #2665 was about%z/%Z.guest_time_conversioncovers all five conversions, hours 0/12/13 and single-digit padding, exact fit and one byte short,%%k/%%%k,%E%kand friends, theE/Oforms, atm_zonethat differs from the host's, a nulltm_zone, and%sagainstmktime; it fails without the change. Differential runs againstmain'sTime.cppbuilt from the same sources: about 3 million format/tm/size cases (7 time-zone settings, extremetmvalues, buffer sizes 0 to 255 and 4 MB formats) against an independent FreeBSDstrftimereference: 0 differences for formats without the new conversions, no overrun, the caller'stmunchanged, about 52,500 cases fixed; and all 111,111 formats of length 0 to 5 over%EOkls+vZaagainst a reference written from FreeBSD's_fmt()(read at releng/9.3, 11.0, 13.2 and 14.0): 0 mismatches. Linux not run.AI-assisted: yes.