feat(libc): implement getline and getdelim with guest allocations #2060

Closed
QRMOE wants to merge 4 commits from upstream-pr/2060 into main
QRMOE commented 2026-10-09 06:19:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-09T06:19:05Z.


What

Adds getdelim (e0iUSkl6-uU) and getline (EFEe73sCz-8). Reads complete records under the native stream lock, includes the delimiter in the signed 64-bit result, keeps embedded NUL bytes, and grows the caller buffer through the application heap. Tracks library-generated stream errors and read access from fopen, fdopen and freopen; this gives guest EBADF for write-only streams even when UCRT leaves errno unchanged. Allocation failures retain the caller buffer and capacity. Reference: FreeBSD getdelim.

Tested

guest_line_input and guest_line_input_allocation_failure pass. Cases include empty input, blank/binary records, custom NUL delimiters, final unterminated records, EOF state, buffer growth/reuse, 128 KiB input, invalid arguments, write-only stream errors, and 300 complete records consumed by two threads sharing a stream. A guest allocator forced to fail checks ENOMEM, stream error state, unchanged buffer/capacity and recovery without losing the next byte. Existing guest_standard_streams and guest_errors also pass. The Linux nonblocking EAGAIN rollback and extreme EOVERFLOW path are not exercised on this Windows host.

Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7 UCRT/posix/SEH, Ninja Release, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=ON; base f145139676a48306681d3a4d5fabf83938759daf.

Combined validation of these three independent branches: full libs target built successfully, including NID patching; guest_memmem, guest_bcopy, both line-input tests, guest_standard_streams, and guest_errors pass (6/6). All four NIDs are present in patched libc.prx. Conventions, diff whitespace and test registration checks pass. The branches were also built and tested individually before integration.

Before publication, actual library diffs of 559 candidate PR heads were checked for these names and NIDs, including broad PRs and newer heads; no other implementation of these four exports was found. The candidates cover the cached open-PR list and every newer PR head; some candidates may have closed since that list was read.

Linux, console behavior, games and the complete CTest suite have not been run. This adds documented libc interfaces; no particular title starting successfully is claimed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR
  • No comments added in code
  • No silent success stubs added
  • No investigation notes, reports or images added to the repository
  • No third-party dependencies added
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes — OpenAI Codex assisted with implementation, tests and this description.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796793566 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2060). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-09T06:19:05Z. --- ### What Adds `getdelim` (`e0iUSkl6-uU`) and `getline` (`EFEe73sCz-8`). Reads complete records under the native stream lock, includes the delimiter in the signed 64-bit result, keeps embedded NUL bytes, and grows the caller buffer through the application heap. Tracks library-generated stream errors and read access from `fopen`, `fdopen` and `freopen`; this gives guest `EBADF` for write-only streams even when UCRT leaves errno unchanged. Allocation failures retain the caller buffer and capacity. Reference: [FreeBSD getdelim](https://github.com/freebsd/freebsd-src/blob/main/lib/libc/stdio/getdelim.c). ### Tested `guest_line_input` and `guest_line_input_allocation_failure` pass. Cases include empty input, blank/binary records, custom NUL delimiters, final unterminated records, EOF state, buffer growth/reuse, 128 KiB input, invalid arguments, write-only stream errors, and 300 complete records consumed by two threads sharing a stream. A guest allocator forced to fail checks ENOMEM, stream error state, unchanged buffer/capacity and recovery without losing the next byte. Existing `guest_standard_streams` and `guest_errors` also pass. The Linux nonblocking EAGAIN rollback and extreme EOVERFLOW path are not exercised on this Windows host. Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7 UCRT/posix/SEH, Ninja Release, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`; base `f145139676a48306681d3a4d5fabf83938759daf`. Combined validation of these three independent branches: full `libs` target built successfully, including NID patching; `guest_memmem`, `guest_bcopy`, both line-input tests, `guest_standard_streams`, and `guest_errors` pass (6/6). All four NIDs are present in patched `libc.prx`. Conventions, diff whitespace and test registration checks pass. The branches were also built and tested individually before integration. Before publication, actual library diffs of 559 candidate PR heads were checked for these names and NIDs, including broad PRs and newer heads; no other implementation of these four exports was found. The candidates cover the cached open-PR list and every newer PR head; some candidates may have closed since that list was read. Linux, console behavior, games and the complete CTest suite have not been run. This adds documented libc interfaces; no particular title starting successfully is claimed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR - [x] No comments added in code - [x] No silent success stubs added - [x] No investigation notes, reports or images added to the repository - [x] No third-party dependencies added - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes — OpenAI Codex assisted with implementation, tests and this description.
github-actions[bot] commented 2026-10-09 06:48:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T06:48:09Z.


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
#1841 __error_nid_postfix
#1860 __error_nid_postfix
#2033 core/libs/prx/libc/src/FileAndHeap.cpp L106-107
#2051 __error_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6075912951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2060#issuecomment-6075912951). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T06:48:09Z. --- <!-- 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 | |---|---|---|---| | #1841 | | `__error_nid_postfix` | | | #1860 | | `__error_nid_postfix` | | | #2033 | `core/libs/prx/libc/src/FileAndHeap.cpp` [L106-107](https://github.com/boykopovar/AnyPS5/blob/6cc0503dacc9d9697d23001d4103780ad2e9acba/core/libs/prx/libc/src/FileAndHeap.cpp#L106-L107) | | | | #2051 | | `__error_nid_postfix` | |
oneandonlydean commented 2026-10-09 08:57:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:57:44Z.


Same as #2058, for getline and getdelim.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077749350 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2060#issuecomment-6077749350). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:57:44Z. --- Same as #2058, for `getline` and `getdelim`.

Pull request closed

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!2060
No description provided.