feat(libc): implement rewind #3198

Merged
adriadam10 merged 1 commit from upstream-pr/3198 into main 2026-10-11 01:02:07 +00:00
adriadam10 commented 2026-10-11 00:55:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T00:55:13Z.


What

rewind (3QIPIh-GDjw, imported from libSceLibcInternal) isn't exported. Since #1529, Linux binds libSceLibcInternal imports to the system libraries instead of the title's bundled libc.prx, so these four catalog homebrew titles now stop on it at load on main:

Title Stop on main f1ae427b6
PSXS5 (PPSA97510) ./app.elf: symbol lookup error: ./app.elf: undefined symbol: 3QIPIh-GDjw
vkQuake (PPSA99010) same
EVO Player (PPSA99039) same
Nuvio PS5 (PPSA99997) same

It follows FreeBSD 11 lib/libc/stdio/rewind.c:

  • seek to the start;
  • restore errno if the seek succeeded;
  • clear the end-of-file and error indicators either way.

It goes through the existing fseeko and clearerr paths, so a character pushed back with ungetc is dropped and the guest encoding-error flag is cleared too.

This is the same function as the closed #2354, which had no title stopping on it at the time.

Tested

Linux (CachyOS), GCC 16, Release.

  • guest_standard_streams passes. The new cases:
    • rewind after a write keeps errno and returns to offset 0;
    • a character pushed back with ungetc is dropped;
    • end-of-file and the encoding error are both cleared;
    • on a pipe (not Windows) the seek fails, errno is ESPIPE (29) and the indicators are still cleared.
  • On main the test doesn't link (rewind_nid_postfix is undefined).
  • Negative checks, each one makes the test fail: restoring errno after a failed seek too, not clearing, clearing only after a successful seek, and not seeking. Removing the restore on success survives: the host's fseeko doesn't touch errno when it succeeds, so that line can't be seen here. It's kept to match FreeBSD.
  • Title stops: catalog releases (sha256-checked) relinked for Linux with main's relinker and launched. Each stops at load with the line above.
  • tools/check_conventions.py passes.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815607045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3198). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T00:55:13Z. --- ### What `rewind` (`3QIPIh-GDjw`, imported from `libSceLibcInternal`) isn't exported. Since #1529, Linux binds `libSceLibcInternal` imports to the system libraries instead of the title's bundled `libc.prx`, so these four catalog homebrew titles now stop on it at load on `main`: | Title | Stop on `main` f1ae427b6 | |---|---| | PSXS5 (PPSA97510) | `./app.elf: symbol lookup error: ./app.elf: undefined symbol: 3QIPIh-GDjw` | | vkQuake (PPSA99010) | same | | EVO Player (PPSA99039) | same | | Nuvio PS5 (PPSA99997) | same | It follows FreeBSD 11 `lib/libc/stdio/rewind.c`: - seek to the start; - restore `errno` if the seek succeeded; - clear the end-of-file and error indicators either way. It goes through the existing `fseeko` and `clearerr` paths, so a character pushed back with `ungetc` is dropped and the guest encoding-error flag is cleared too. This is the same function as the closed #2354, which had no title stopping on it at the time. ### Tested Linux (CachyOS), GCC 16, Release. - `guest_standard_streams` passes. The new cases: - `rewind` after a write keeps `errno` and returns to offset 0; - a character pushed back with `ungetc` is dropped; - end-of-file and the encoding error are both cleared; - on a pipe (not Windows) the seek fails, `errno` is `ESPIPE` (29) and the indicators are still cleared. - On `main` the test doesn't link (`rewind_nid_postfix` is undefined). - Negative checks, each one makes the test fail: restoring `errno` after a failed seek too, not clearing, clearing only after a successful seek, and not seeking. Removing the restore on success survives: the host's `fseeko` doesn't touch `errno` when it succeeds, so that line can't be seen here. It's kept to match FreeBSD. - Title stops: catalog releases (sha256-checked) relinked for Linux with `main`'s relinker and launched. Each stops at load with the line above. - `tools/check_conventions.py` passes. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-11 00:55:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T00:55:34Z.


Progress report (06da117 → e7605c8)

➖ System libraries: 85.96% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc rewind_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103959775 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3198#issuecomment-6103959775). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T00:55:34Z. --- <!-- progress-report --> ### Progress report (06da117 → e7605c8) ➖ **System libraries**: 85.96% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `rewind_nid_postfix` | </details>
adriadam10 commented 2026-10-11 01:03:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T01:03:18Z.


Merged with Linux CI red only on the three AGC tests main has been failing since 3c46fa6f4 (agc_unit_shadow, agc_driver_flat_apertures, agc_driver_image_packed16_load). I'm on those now. Windows passed, and guest_standard_streams passed on both.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104016074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3198#issuecomment-6104016074). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T01:03:18Z. --- Merged with Linux CI red only on the three AGC tests main has been failing since 3c46fa6f4 (`agc_unit_shadow`, `agc_driver_flat_apertures`, `agc_driver_image_packed16_load`). I'm on those now. Windows passed, and `guest_standard_streams` passed on both.
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!3198
No description provided.