Skip to content

feat(libc): implement wide and unlocked stream I/O - #5816

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Nawasfadili:feat/libc-wide-and-unlocked-stream-io
Oct 15, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Nawasfadili:feat/libc-wide-and-unlocked-stream-io

Conversation

@Nawasfadili

@Nawasfadili Nawasfadili commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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.cpp covering wide string line reading, single/unlocked character I/O, error handling, EOF, and buffer bounds, and updates technical debt documentation in docs/dev/debt/libc.md.

Tested

Windows 10, built with GCC 15 / Ninja.
Ran unit test suite via CTest:

  • guest_standard_streams passed (100% tests passed)
  • file_streams, guest_wide_formatting, guest_wide_strings, guest_wide_conversion passed
  • tools/check_conventions.py passed with 0 findings

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Progress report (4469ea2 → 6509ec2)

📈 System libraries: 88.7% (+0.02%, +7 implemented functions)

✅ 7 implemented
Library Name
libc fgetws_nid_postfix
libc getchar_unlocked_nid_postfix
libc getwc_nid_postfix
libc getwchar_nid_postfix
libc putchar_unlocked_nid_postfix
libc putwc_nid_postfix
libc putwchar_nid_postfix

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Build and ctest pass here, and the new test fails to link without the change. One problem to fix:

  • getwc, getwchar and fgetws sit on top of fgetwc (core/libs/prx/libc/src/StandardStreams.cpp:22), which reads a single byte, while fputwc/putwc/putwchar write UTF-8 (core/libs/prx/libc/src/FormattingWide.cpp:335). putwc(u'é') followed by getwc returns 0xC3, not 0xE9, 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 with fgetws/getwc), or throw for bytes >= 0x80 and record the limit in docs/dev/debt/libc.md.
  • fgetws (FormattingWide.cpp:380-388) returns the partial buffer when fgetwc fails with an error mid-line, not only on EOF. FreeBSD's fgetws returns NULL on error; please check ferror after the loop.

Rest looks fine: the unlocked variants reuse getc_unlocked/putc_unlocked, and the debt lines are in the right section.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#3965 docs/dev/debt/libc.md L36-37
#6107 docs/dev/debt/libc.md L37

Some 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.

Pull request Shared files not compared
#3891 core/libs/prx/libc/src/StandardStreams.cpp
#4156 core/libs/prx/libc/src/StandardStreams.cpp
#4396 core/libs/prx/libc/src/StandardStreams.cpp
#4397 core/libs/prx/libc/src/StandardStreams.cpp
#4422 core/libs/prx/libc/src/StandardStreams.cpp
#4423 core/libs/prx/libc/src/StandardStreams.cpp
#4424 core/libs/prx/libc/src/StandardStreams.cpp
#4520 core/libs/prx/libc/src/StandardStreams.cpp
#4521 core/libs/prx/libc/src/StandardStreams.cpp
#4522 core/libs/prx/libc/src/StandardStreams.cpp
#4523 core/libs/prx/libc/src/StandardStreams.cpp
#4566 core/libs/prx/libc/src/StandardStreams.cpp
#4599 core/libs/prx/libc/src/StandardStreams.cpp
#4718 core/libs/prx/libc/src/StandardStreams.cpp
#4740 core/libs/prx/libc/src/StandardStreams.cpp
#4749 core/libs/prx/libc/src/StandardStreams.cpp
#4760 core/libs/prx/libc/src/StandardStreams.cpp
#4813 core/libs/prx/libc/src/StandardStreams.cpp
#5021 core/libs/prx/libc/src/StandardStreams.cpp
#5303 core/libs/prx/libc/src/FormattingWide.cpp
docs/dev/debt/libc.md
#5835 docs/dev/debt/libc.md
#6044 core/libs/tests/GuestStandardStreams.cpp
#6222 core/libs/prx/libc/src/StandardStreams.cpp
docs/dev/debt/libc.md
#6226 docs/dev/debt/libc.md

@Nawasfadili
Nawasfadili force-pushed the feat/libc-wide-and-unlocked-stream-io branch from 6970d3d to 6509ec2 Compare October 14, 2026 14:25
@Nawasfadili

Copy link
Copy Markdown
Contributor Author

Thank you for the review!

Updated in the latest push:

  • Decoded UTF-8 in fgetwc to support multi-byte sequences (with round-trip unit tests for 2-byte u'é' and 3-byte u'\u20ac' characters covering putwc, getwc, and fgetws).
  • Added ferror check in fgetws after the loop to return NULL on error (with a unit test covering mid-line encoding failure).
  • Updated docs/dev/debt/libc.md accordingly.

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked against the new head: fgetwc now decodes UTF-8, so putwc/getwc/fgetws round-trip é and € (new tests), and fgetws returns 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants