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

Merged
Nawasfadili merged 1 commit from upstream-pr/5816 into main 2026-10-15 13:58:45 +00:00
Nawasfadili commented 2026-10-14 12:10:35 +00:00 (Migrated from github.com)

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.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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4857646722 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5816). Originally posted by [Nawasfadili](https://github.com/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.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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 13:41:11 +00:00 (Migrated from github.com)

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
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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6169743523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5816#issuecomment-6169743523). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T13:41:11Z. --- <!-- progress-report --> ### Progress report (4469ea2 → 6509ec2) 📈 **System libraries**: 88.7% (+0.02%, +7 implemented functions) <details> <summary>✅ 7 implemented</summary> | 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` | </details>
adriadam10 commented 2026-10-14 13:45:39 +00:00 (Migrated from github.com)

Imported 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, 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5518922087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5816#pullrequestreview-5518922087). Originally posted by [adriadam10](https://github.com/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`, `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[bot] commented 2026-10-14 13:51:41 +00:00 (Migrated from github.com)

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.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6169955843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5816#issuecomment-6169955843). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T13:51:41Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/8dc92ae290c382721f1e564fd19388934f529bd2/docs/dev/debt/libc.md#L36-L37) | | | | #6107 | `docs/dev/debt/libc.md` [L37](https://github.com/boykopovar/AnyPS5/blob/8dc92ae290c382721f1e564fd19388934f529bd2/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`<br>`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`<br>`docs/dev/debt/libc.md` | | #6226 | `docs/dev/debt/libc.md` |
Nawasfadili commented 2026-10-14 14:27:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nawasfadili on 2026-10-14T14:27:33Z.


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.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6170698378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5816#issuecomment-6170698378). Originally posted by [Nawasfadili](https://github.com/Nawasfadili) on 2026-10-14T14:27:33Z. --- 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 commented 2026-10-15 13:09:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:09:28Z.

Review: APPROVED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5533597865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5816#pullrequestreview-5533597865). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:09:28Z. **Review:** APPROVED --- 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 in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5816
No description provided.