feat(libc): export _Btowc and _Wctob, which give btowc and wctob results in the console's libc #11734
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11734"
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 verusferro on 2026-10-27T06:22:01Z.
What
libc did not export Dinkumware's
_Btowcand_Wctob, which the console'slibc.prxexports. In the SDK 7.00libc.prxthat PPSA06416 ships insce_module/(0x6e0e0 and 0x57710, read from its disassembly, REVERSE_ENGINEERING source 2):_Btowc(c)returnsWEOFforEOF. Otherwise it converts the byte with_Mbtowcand a zeroed state, and returns the 16-bit result if_Mbtowcreturned 0 or more,WEOFif not._Wctob(c)returnsEOFforWEOF. Otherwise it converts the low 16 bits with_Wctomband a zeroed state, and returns the byte if exactly one came out,EOFif not.Run in a host process, they give the same results and
errnoas this library'sbtowcandwctobfor every input below, so the new exports call those._Mbtowcand_Wctombare left out: here they would call_Mbtowcxand_Wctombx, which convert through the host'smbrtowcandwcrtomband throw for invalid or incomplete input, and I have not compared those with the module.Tested
Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with
BUILD_TESTING=ON, onmain2227f13661:libc.prx, converted by the relinker and loaded in a host process, against this library's unpatchedlibc.prx:_Btowcfor every value from -1 to 255, and_Wctobfor every value from 0 to 0x10000 and for 0xffffffff. The result anderrnomatch in all 65,795 calls. On the earlier basefe2b52c7e4the same held for 65,808 calls that also coveredINT_MIN,INT_MAXand values above 0x10000, and JJenkx found no difference against thelibc.prxof 11 titles.btowcandwctob, whichguest_rune_localeandguest_multibyte_localetest, and CONTRIBUTING asks for no export-only tests.ctest -R '^(guest_rune_locale|guest_multibyte_locale|guest_wide_conversion|patched_libraries|conventions_unknown_nids)$': 5/5 pass.tools/progress.py: +2 implemented. libc goes from 1419/1436 to 1421/1438.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch feat/libc-btowc-wctob-internals: no conflicting lines and no same exports. Of the pull requests it could not compare, #10324 and #10749 change other lines ofApi.hpp, andgit merge-treeof either with this branch conflicts only in the files where they already conflict withmain.Not tested: Windows, macOS, a title that calls these functions, a console run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T06:30:32Z.
Review: APPROVED
Reviewed exact head
d489ecd7a556b9cf217ea9214ad0cad8671dd8e2. Both internal exports are thin aliases to the existingbtowc/wctobimplementations, with matching parameter/result widths and no duplicated conversion logic. The description carefully limits the claim about_Mbtowc/_Wctomb, and reports exhaustive byte coverage plus all 65,536 16-bit inputs against the shipped module, includingerrno.The author reports a full Ubuntu 24.04/WSL2 build and 5/5 focused locale tests. Hosted conventions, intake, labels, Linux/Windows relinker, and ASan checks pass; macOS relinker jobs remain queued and full Linux/Windows product jobs are skipped by repository policy. I did not independently rerun the module comparison or full build.