feat(libc): implement wcstok #2220

Closed
reyani-dev wants to merge 1 commit from upstream-pr/2220 into main
reyani-dev commented 2026-10-09 11:59:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T11:59:23Z.


What

Exports wcstok on the guest's 16-bit wchar_t, next to wcsspn and using the same Contains helper. The behaviour follows FreeBSD's three-argument wcstok (lib/libc/string/wcstok.c):

  • leading delimiters are skipped;
  • the token ends at the next delimiter, which is overwritten with 0, and *last points past it;
  • when the string is exhausted, *last becomes NULL, both after the last token and when only delimiters remain;
  • with text == NULL it continues from *last, and returns NULL when that is NULL.

Code units are compared one by one, so a surrogate pair is never split by a BMP delimiter.

Title: PPSA99420 PS5MC imports it from libSceLibcInternal (resolved through libc.prx), per the #1578 audit. I haven't run the title.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • New checks in guest_wide_string_tests, next to wcsspn:
    • leading and repeated delimiters (u",,one,,two;three");
    • the save pointer after each token;
    • a different delimiter set on a later call;
    • NULL save pointer after the last token and on a delimiters-only string;
    • a CJK unit and a surrogate pair around the delimiter.
  • Mutation check: leaving *last at the terminator (strtok_r style), or not skipping leading delimiters, each make guest_wide_strings fail.
  • cmake --build build --target libs: the patched libc.prx exports 8ngzWNZzFJU.
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap. It also merges cleanly with #1459, which touches the same files.

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:4800098557 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2220). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T11:59:23Z. --- ### What Exports `wcstok` on the guest's 16-bit `wchar_t`, next to `wcsspn` and using the same `Contains` helper. The behaviour follows FreeBSD's three-argument `wcstok` (`lib/libc/string/wcstok.c`): - leading delimiters are skipped; - the token ends at the next delimiter, which is overwritten with 0, and `*last` points past it; - when the string is exhausted, `*last` becomes NULL, both after the last token and when only delimiters remain; - with `text == NULL` it continues from `*last`, and returns NULL when that is NULL. Code units are compared one by one, so a surrogate pair is never split by a BMP delimiter. Title: PPSA99420 PS5MC imports it from `libSceLibcInternal` (resolved through `libc.prx`), per the #1578 audit. I haven't run the title. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_wide_string_tests`, next to `wcsspn`: - leading and repeated delimiters (`u",,one,,two;three"`); - the save pointer after each token; - a different delimiter set on a later call; - NULL save pointer after the last token and on a delimiters-only string; - a CJK unit and a surrogate pair around the delimiter. - Mutation check: leaving `*last` at the terminator (`strtok_r` style), or not skipping leading delimiters, each make `guest_wide_strings` fail. - `cmake --build build --target libs`: the patched `libc.prx` exports `8ngzWNZzFJU`. - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. It also merges cleanly with #1459, which touches the same files. ### 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-09 11:59:46 +00:00 (Migrated from github.com)

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


Progress report (d70b899 → c7818fd)

📈 System libraries: 84.7% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc wcstok_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080424902 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2220#issuecomment-6080424902). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T11:59:46Z. --- <!-- progress-report --> ### Progress report (d70b899 → c7818fd) 📈 **System libraries**: 84.7% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `wcstok_nid_postfix` | </details>
MarcZX10 commented 2026-10-09 12:10:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T12:10:24Z.

Review: APPROVED


Reviewed the full diff and reported checks. The implementation follows the three-argument tokenizer semantics: it skips leading delimiters, terminates at the first delimiter, saves the next position, and clears the continuation pointer at exhaustion. The tests cover repeated calls, alternate delimiter sets, delimiters-only input, and UTF-16 code units. The focused Windows report and all three relinker jobs pass; Conventions passes. Full Linux/Windows Build jobs are skipped on this PR, so the project Build workflow still needs to run before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5469820799 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2220#pullrequestreview-5469820799). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T12:10:24Z. **Review:** APPROVED --- Reviewed the full diff and reported checks. The implementation follows the three-argument tokenizer semantics: it skips leading delimiters, terminates at the first delimiter, saves the next position, and clears the continuation pointer at exhaustion. The tests cover repeated calls, alternate delimiter sets, delimiters-only input, and UTF-16 code units. The focused Windows report and all three relinker jobs pass; Conventions passes. Full Linux/Windows Build jobs are skipped on this PR, so the project Build workflow still needs to run before merge.
reyani-dev commented 2026-10-09 12:28:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T12:28:00Z.


Full Linux and Windows builds and tests for this head (c7818fdd), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (d70b8998):

Job Result
linux success; full build, ctest: 516/516 passed
windows success; full build, ctest: 507/507 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37927142712

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080879283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2220#issuecomment-6080879283). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-09T12:28:00Z. --- Full Linux and Windows builds and tests for this head (`c7818fdd`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`d70b8998`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/37927142712/job/113808741894) | success; full build, `ctest`: 516/516 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/37927142712/job/113808741836) | success; full build, `ctest`: 507/507 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/37927142712
oneandonlydean commented 2026-10-09 20:10:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:10:20Z.


Same as #2167, for wcstok.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088447568 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2220#issuecomment-6088447568). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:10:20Z. --- Same as #2167, for `wcstok`.

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