feat(libc): implement wide and unlocked stream I/O #5816
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5816"
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 Nawasfadili on 2026-10-14T12:10:35Z.
What
Implement 7 missing POSIX/FreeBSD standard stream I/O functions in libc:
fgetws(NID:F81hKe2k2tg): Read wide string from stream until newline or EOF, with buffer size and null pointer validation.getwc(NID:CosTELN5ETk): Read single wide character from stream.getwchar(NID:n2mWDsholo8): Read wide character from standard input (__stdinp).putwc(NID:UZJnC81pUCw): Write wide character to stream.putwchar(NID:aW9KhGC4cOo): Write wide character to standard output (__stdoutp).getchar_unlocked(NID:H0pVDvSuAVQ): Fast unlocked character input from standard input (__stdinp).putchar_unlocked(NID:v95AEAzqm+0): Fast unlocked character output to standard output (__stdoutp).Also adds comprehensive unit tests in
GuestStandardStreams.cppcovering wide string line reading, single/unlocked character I/O, error handling, EOF, and buffer bounds, and updates technical debt documentation indocs/dev/debt/libc.md.Tested
Windows 10, built with GCC 15 / Ninja.
Ran unit test suite via CTest:
guest_standard_streamspassed (100% tests passed)file_streams,guest_wide_formatting,guest_wide_strings,guest_wide_conversionpassedtools/check_conventions.pypassed with 0 findingsChecklist
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 github-actions[bot] on 2026-10-14T13:41:11Z.
Progress report (
4469ea2→6509ec2)📈 System libraries: 88.7% (+0.02%, +7 implemented functions)
✅ 7 implemented
fgetws_nid_postfixgetchar_unlocked_nid_postfixgetwc_nid_postfixgetwchar_nid_postfixputchar_unlocked_nid_postfixputwc_nid_postfixputwchar_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:45:39Z.
Review: CHANGES_REQUESTED
Thanks for the PR. Build and ctest pass here, and the new test fails to link without the change. One problem to fix:
getwc,getwcharandfgetwssit on top offgetwc(core/libs/prx/libc/src/StandardStreams.cpp:22), which reads a single byte, whilefputwc/putwc/putwcharwrite UTF-8 (core/libs/prx/libc/src/FormattingWide.cpp:335).putwc(u'é')followed bygetwcreturns0xC3, not0xE9, so the pair does not round-trip for anything >= 0x80. The tests only use ASCII, so they cannot see it. Either decode UTF-8 in the read path (and test a 2-byte and a 3-byte character withfgetws/getwc), or throw for bytes >= 0x80 and record the limit indocs/dev/debt/libc.md.fgetws(FormattingWide.cpp:380-388) returns the partial buffer whenfgetwcfails with an error mid-line, not only on EOF. FreeBSD'sfgetwsreturns NULL on error; please checkferrorafter the loop.Rest looks fine: the unlocked variants reuse
getc_unlocked/putc_unlocked, and the debt lines are in the right section.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T13:51:41Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL36-37docs/dev/debt/libc.mdL37Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/FormattingWide.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/GuestStandardStreams.cppcore/libs/prx/libc/src/StandardStreams.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by Nawasfadili on 2026-10-14T14:27:33Z.
Thank you for the review!
Updated in the latest push:
fgetwcto support multi-byte sequences (with round-trip unit tests for 2-byteu'é'and 3-byteu'\u20ac'characters coveringputwc,getwc, andfgetws).ferrorcheck infgetwsafter the loop to returnNULLon error (with a unit test covering mid-line encoding failure).docs/dev/debt/libc.mdaccordingly.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:09:28Z.
Review: APPROVED
Re-checked against the new head:
fgetwcnow decodes UTF-8, soputwc/getwc/fgetwsround-tripéand€(new tests), andfgetwsreturns NULL on stream error. Build and ctest pass here and the new test still fails to link without the change; merging once the full build is green.