feat(libc): implement wcsrtombs_s #736
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/736"
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 adriadam10 on 2026-10-05T18:29:40Z.
What
Implements
wcsrtombs_s(79s2tnYQI6I, renamed fromlibcCyberUnknown04) inMultibyte.cpp, using the 16-bit guestwchar_tand the existing C-localewcrtomb.No emulator implements it (KytyPS5, shadPS4 and fpPS4 have no body), so the behaviour comes from disassembling the console's own
sce_module/libc.prx(Dinkumware, C11 K.3.6.5.2):EINVAL(22),*retval = -1, anddst[0] = 0whendstis non-null with a positive size. Violations: nullretval,src,*srcorps; nulldstwith a non-zerodstsz; and with a non-nulldst,dstszorlenaboveRSIZE_MAX(checked as signed) ordstsz == 0(dstis left untouched then).dstnull: counts the bytes up to the terminator,*srcunchanged.EILSEQ(86) without going through the constraint handler,*retval = -1, a terminator written at the current output position,*srcunchanged.lenreached → terminates the output,*srcpoints to the next wide character,*retval= bytes written.ERANGE(34),dst[0] = 0,*retval = -1,*srcadvanced past the characters converted. Thedstszcheck runs before thelencheck.*src = NULL,*retval= length without the terminator.The console's default constraint handler (
libc.prx0x4170) writes the message tostderrand returns. That message is not written here, like the other_sfunctions that only return the error. Listed in TechnicalDebt together with the C-locale-only conversion.Tested
Linux, homebrew test
guest_wcsrtombs_s(registered in ctest, libc CMakeLists). It covers the count mode, a full conversion, the exact fit, thelenlimit,len0,ERANGEwithdstszandlenboth reaching zero,EILSEQin both modes, and every constraint violation listed above. Expected values come from the disassembly, not from this implementation. Each branch was checked by breaking it in turn, and the test fails each time. The one exception is the "multibyte character does not fit" branch, which can't be reached whileMB_CUR_MAXis 1. Onmainthe export throws (NotImplemented_nid_no_patch). The full Release build (GCC) and everyguest_test pass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T18:30:05Z.
Progress report (
fdd6519→55f548d)📈 System libraries: 79.24% (+0.03%, +1 implemented, -1 removed functions)
✅ 1 implemented
wcsrtombs_s_nid_postfix🗑️ 1 removed
libcCyberUnknown04