feat(libc): implement ctime and rewind #1871

Closed
TheAggie wants to merge 1 commit from upstream-pr/1871 into main
TheAggie commented 2026-10-08 22:27:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T22:27:48Z.


What

ctime and rewind were not exported. ccleste (PPSA59322) imports both.

  • ctime formats through the existing localtime and asctime, as C defines it, and returns null when localtime does.
  • rewind seeks the stream to its start through fseeko and clears its error and end-of-file flags.

Test (guest_standard_streams): ctime of a fixed moment equals asctime(localtime(...)) and is 25 characters ending in a newline. After reading a stream to end of file, rewind clears end-of-file and the stream reads from its first byte again.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.

  • The full suite (485 tests) passes on current main with this PR and four other small libc/libkernel PRs of mine merged together (atol, getprogname, dup2, ctime/rewind, pthread_set_name_np). It was run from the generated CTestTestfile.cmake commands because antivirus blocks ctest.exe on this machine.
  • tools/check_conventions.py --base origin/main passes on this branch alone.

Not tested on Linux or macOS.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4793543114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T22:27:48Z. --- ### What `ctime` and `rewind` were not exported. ccleste (PPSA59322) imports both. - `ctime` formats through the existing `localtime` and `asctime`, as C defines it, and returns null when `localtime` does. - `rewind` seeks the stream to its start through `fseeko` and clears its error and end-of-file flags. Test (`guest_standard_streams`): `ctime` of a fixed moment equals `asctime(localtime(...))` and is 25 characters ending in a newline. After reading a stream to end of file, `rewind` clears end-of-file and the stream reads from its first byte again. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. - The full suite (485 tests) passes on current `main` with this PR and four other small libc/libkernel PRs of mine merged together (atol, getprogname, dup2, ctime/rewind, pthread_set_name_np). It was run from the generated `CTestTestfile.cmake` commands because antivirus blocks `ctest.exe` on this machine. - `tools/check_conventions.py --base origin/main` passes on this branch alone. Not tested on Linux or macOS. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-08 22:31:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T22:31:42Z.


Progress report (ce64d8e → 51067d7)

📈 System libraries: 84.77% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libc ctime_nid_postfix
libc rewind_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070371402 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871#issuecomment-6070371402). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T22:31:42Z. --- <!-- progress-report --> ### Progress report (ce64d8e → 51067d7) 📈 **System libraries**: 84.77% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `ctime_nid_postfix` | | libc | `rewind_nid_postfix` | </details>
Dextroid17 commented 2026-10-09 02:58:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T02:58:09Z.

Review: COMMENTED


Verified on Linux — the differential holds, and both symbols are genuinely new.

  • Arm A (this PR): cmake --build build --target guest_standard_stream_tests → clean; the test passes, exit 0. (For anyone reproducing: the target is guest_standard_stream_tests, singular.)
  • Arm B (control): Time.cpp and FileAndHeap.cpp back at main, the test kept → the target fails to link:
GuestStandardStreams.cpp:(.text.startup+0x4a7): undefined reference to `ctime_nid_postfix'
GuestStandardStreams.cpp:(.text.startup+0x9c0): undefined reference to `rewind_nid_postfix'

so both are truly absent from main. Worth grepping with a word boundary, incidentally — ctime_nid_postfix is a substring of asctime_nid_postfix and a plain grep -c on main returns a hit that is not there.

Claim cross-check: ctime is localtime → asctime with the null propagated (Time.cpp:104-107), and rewind is fseeko(stream, 0, SEEK_SET) + ClearError() (FileAndHeap.cpp:208-211). ClearError calls std::clearerr, which clears the error and end-of-file indicators together, then re-syncs the guest flags from feof/ferror (FileStream.hpp:96-100). So "clears its error and end-of-file flags" is right, and it is cleared at the C level rather than only in the guest word.

One detail worth keeping: the test pins ctime to asctime(localtime(...)) instead of a literal string, so it holds in any timezone — it ran here in EDT.

Not verified: Windows, the author's platform.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465208482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871#pullrequestreview-5465208482). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T02:58:09Z. **Review:** COMMENTED --- Verified on Linux — the differential holds, and both symbols are genuinely new. - **Arm A (this PR)**: `cmake --build build --target guest_standard_stream_tests` → clean; the test passes, **exit 0**. (For anyone reproducing: the target is `guest_standard_stream_tests`, singular.) - **Arm B (control)**: `Time.cpp` and `FileAndHeap.cpp` back at `main`, the test kept → the target fails to link: ``` GuestStandardStreams.cpp:(.text.startup+0x4a7): undefined reference to `ctime_nid_postfix' GuestStandardStreams.cpp:(.text.startup+0x9c0): undefined reference to `rewind_nid_postfix' ``` so both are truly absent from `main`. Worth grepping with a word boundary, incidentally — `ctime_nid_postfix` is a substring of `asctime_nid_postfix` and a plain `grep -c` on `main` returns a hit that is not there. **Claim cross-check**: `ctime` is `localtime` → `asctime` with the null propagated (`Time.cpp:104-107`), and `rewind` is `fseeko(stream, 0, SEEK_SET)` + `ClearError()` (`FileAndHeap.cpp:208-211`). `ClearError` calls `std::clearerr`, which clears the error **and** end-of-file indicators together, then re-syncs the guest flags from `feof`/`ferror` (`FileStream.hpp:96-100`). So "clears its error and end-of-file flags" is right, and it is cleared at the C level rather than only in the guest word. One detail worth keeping: the test pins `ctime` to `asctime(localtime(...))` instead of a literal string, so it holds in any timezone — it ran here in EDT. Not verified: Windows, the author's platform. Written with AI assistance.
oneandonlydean commented 2026-10-09 09:30:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:30:24Z.


Closing: ccleste stops at shm_open on main, before ctime and rewind. Reopen when either is a title's next stop on main, with the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078240567 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871#issuecomment-6078240567). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:30:24Z. --- Closing: ccleste stops at `shm_open` on main, before `ctime` and `rewind`. Reopen when either is a title's next stop on main, with the log line.
babyhuey commented 2026-10-10 02:24:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T02:24:51Z.


Both functions are now titles' next stops on current main, so here are the log lines the close note asked for, plus a check of this branch.

Checked 51067d7e merged onto main c963432d, Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC from WinLibs), Release. The conflict is in Time.cpp: main moved localtime, asctime and strftime to GuestTm, so in the merge I kept main's strftime and changed ctime to const GuestTm* local = localtime_nid_postfix(timer);. The rest of the branch merged as is.

  • guest_standard_streams passes 5/5 on both (--repeat until-fail:5); no compiler warnings and no CRT assertion dialog on Windows.
Title main with this branch
RommPS (PPSA76677) 0uAUs3hYuG4 (ctime) V02oFv+-JzA (__isinf, #2174), Linux and Windows
Capy Mobile (PPSA92280) 3QIPIh-GDjw (rewind) +my9jdHCMIQ (atol, #2186), Linux and Windows
ccleste (PPSA59322) 0uAUs3hYuG4 (ctime) QuJYZ2KVGGQ (shm_open, #1860), Linux; on Windows it doesn't relink yet (empty PT_TLS, #1911)

Example for RommPS on Windows: main FAIL: unresolved ELF import 0uAUs3hYuG4 (ctime) from libSceLibcInternal.prx; with this branch FAIL: unresolved ELF import V02oFv+-JzA (__isinf) from libSceLibcInternal.prx. EVO Player and Nuvio PS5 also reach rewind once atoll exists (#2186).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092698959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871#issuecomment-6092698959). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T02:24:51Z. --- Both functions are now titles' next stops on current `main`, so here are the log lines the close note asked for, plus a check of this branch. Checked 51067d7e merged onto `main` c963432d, Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC from WinLibs), Release. The conflict is in `Time.cpp`: `main` moved `localtime`, `asctime` and `strftime` to `GuestTm`, so in the merge I kept `main`'s `strftime` and changed `ctime` to `const GuestTm* local = localtime_nid_postfix(timer);`. The rest of the branch merged as is. - `guest_standard_streams` passes 5/5 on both (`--repeat until-fail:5`); no compiler warnings and no CRT assertion dialog on Windows. | Title | `main` | with this branch | |---|---|---| | RommPS (PPSA76677) | `0uAUs3hYuG4` (`ctime`) | `V02oFv+-JzA` (`__isinf`, #2174), Linux and Windows | | Capy Mobile (PPSA92280) | `3QIPIh-GDjw` (`rewind`) | `+my9jdHCMIQ` (`atol`, #2186), Linux and Windows | | ccleste (PPSA59322) | `0uAUs3hYuG4` (`ctime`) | `QuJYZ2KVGGQ` (`shm_open`, #1860), Linux; on Windows it doesn't relink yet (empty `PT_TLS`, #1911) | Example for RommPS on Windows: `main` `FAIL: unresolved ELF import 0uAUs3hYuG4 (ctime) from libSceLibcInternal.prx`; with this branch `FAIL: unresolved ELF import V02oFv+-JzA (__isinf) from libSceLibcInternal.prx`. EVO Player and Nuvio PS5 also reach `rewind` once `atoll` exists (#2186).
TheAggie commented 2026-10-10 04:49:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T04:49:06Z.


@oneandonlydean the reopen condition is met for both functions, from @babyhuey's runs above on current main (Linux and Windows):

  • RommPS (PPSA76677) stops at 0uAUs3hYuG4 (ctime) (FAIL: unresolved ELF import 0uAUs3hYuG4 (ctime) from libSceLibcInternal.prx); with this branch it moves on to V02oFv+-JzA (__isinf).
  • Capy Mobile (PPSA92280) stops at 3QIPIh-GDjw (rewind); with this branch it moves on to +my9jdHCMIQ (atol).

I rebased the branch onto current main (afb8cd22) and force-pushed it. main had moved localtime/asctime/strftime to GuestTm, so ctime now takes main's GuestTm from localtime_nid_postfix (the same resolution babyhuey used); rewind merged as is. On Windows (MinGW-w64 GCC 15.2, WinLibs, Release) it builds, guest_standard_streams and guest_time_conversion pass, and tools/check_conventions.py passes. I don't have RommPS or Capy Mobile locally, so the title runs are babyhuey's, not mine.

Could you reopen it? GitHub doesn't let me reopen a PR a maintainer closed. Thanks @babyhuey for the runs.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093920746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871#issuecomment-6093920746). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-10T04:49:06Z. --- @oneandonlydean the reopen condition is met for both functions, from @babyhuey's runs above on current `main` (Linux and Windows): - RommPS (PPSA76677) stops at `0uAUs3hYuG4` (`ctime`) (`FAIL: unresolved ELF import 0uAUs3hYuG4 (ctime) from libSceLibcInternal.prx`); with this branch it moves on to `V02oFv+-JzA` (`__isinf`). - Capy Mobile (PPSA92280) stops at `3QIPIh-GDjw` (`rewind`); with this branch it moves on to `+my9jdHCMIQ` (`atol`). I rebased the branch onto current `main` (afb8cd22) and force-pushed it. `main` had moved `localtime`/`asctime`/`strftime` to `GuestTm`, so `ctime` now takes `main`'s `GuestTm` from `localtime_nid_postfix` (the same resolution babyhuey used); `rewind` merged as is. On Windows (MinGW-w64 GCC 15.2, WinLibs, Release) it builds, `guest_standard_streams` and `guest_time_conversion` pass, and `tools/check_conventions.py` passes. I don't have RommPS or Capy Mobile locally, so the title runs are babyhuey's, not mine. Could you reopen it? GitHub doesn't let me reopen a PR a maintainer closed. Thanks @babyhuey for the runs. AI-assisted (Claude Code).
babyhuey commented 2026-10-10 22:36:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T22:36:19Z.


@TheAggie with #1529 in, the libc stops are back on main f38a036e (catalog builds with sce_module/libc.prx unwrapped), and this branch covers seven titles:

  • ctime (0uAUs3hYuG4): ccleste (PPSA59322), RommPS (PPSA76677)
  • rewind (3QIPIh-GDjw): Capy Mobile (PPSA92280), PSXS5 (PPSA97510), vkQuake (PPSA99010), EVO Player (PPSA99039), Nuvio PS5 (PPSA99997)

Linux: app.elf: symbol lookup error: app.elf: undefined symbol: 3QIPIh-GDjw. With the intake check at 10 merged PRs it can go up as a new PR; happy to run the seven titles on Linux and Windows against it once it's up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102919225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1871#issuecomment-6102919225). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T22:36:19Z. --- @TheAggie with #1529 in, the libc stops are back on `main` f38a036e (catalog builds with `sce_module/libc.prx` unwrapped), and this branch covers seven titles: - `ctime` (`0uAUs3hYuG4`): ccleste (PPSA59322), RommPS (PPSA76677) - `rewind` (`3QIPIh-GDjw`): Capy Mobile (PPSA92280), PSXS5 (PPSA97510), vkQuake (PPSA99010), EVO Player (PPSA99039), Nuvio PS5 (PPSA99997) Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: 3QIPIh-GDjw`. With the intake check at 10 merged PRs it can go up as a new PR; happy to run the seven titles on Linux and Windows against it once it's up.

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