feat(libScePosixForWebKit): implement fnmatch #3545

Merged
babyhuey merged 2 commits from upstream-pr/3545 into main 2026-10-11 21:37:42 +00:00
babyhuey commented 2026-10-11 12:56:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T12:56:33Z.


What

Exports fnmatch (60q1rziOzzQ) from libScePosixForWebKit, ported from FreeBSD 11 lib/libc/gen/fnmatch.c for the C locale: ?, * with backtracking, bracket expressions with !/^ negation and ranges, backslash escapes, and the flags FNM_NOESCAPE, FNM_PATHNAME, FNM_PERIOD, FNM_LEADING_DIR and FNM_CASEFOLD with FreeBSD's values. A malformed bracket matches [ literally, as FreeBSD does. Each byte is one character, FNM_CASEFOLD folds ASCII letters and ranges compare byte values, and [:class:] names are plain bracket characters, as in FreeBSD 11 through 14; multibyte characters and locale collation are not modelled, which TechnicalDebt records. A null pattern or string throws.

Cloud Play (PPSA99600) imports it from libScePosixForWebKit and stops at it on main a11c8f7f (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

  • Linux: app.elf: symbol lookup error: app.elf: undefined symbol: 60q1rziOzzQ
  • Windows: FAIL: unresolved ELF import 60q1rziOzzQ (fnmatch) from libScePosixForWebKit.prx
  • with this PR, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: H1bArJPagV0 (getservbyname)
  • with this PR, Windows: FAIL: unresolved ELF import H1bArJPagV0 (getservbyname) from libScePosixForWebKit.prx

Tested

Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release: the new guest_fnmatch passes 5/5 (--repeat until-fail:5) on both, with no warnings in the changed files. Its 50 cases cover every flag, [[:digit:]]-style class syntax, ranges, negation, escapes, leading periods, FNM_PATHNAME slashes and backtracking; each expected result comes from FreeBSD 11's own fnmatch.c compiled on Linux with the C-locale collation path. It also checks that a null pattern throws. 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:4819207850 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T12:56:33Z. --- ### What Exports `fnmatch` (`60q1rziOzzQ`) from libScePosixForWebKit, ported from FreeBSD 11 [`lib/libc/gen/fnmatch.c`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libc/gen/fnmatch.c) for the C locale: `?`, `*` with backtracking, bracket expressions with `!`/`^` negation and ranges, backslash escapes, and the flags `FNM_NOESCAPE`, `FNM_PATHNAME`, `FNM_PERIOD`, `FNM_LEADING_DIR` and `FNM_CASEFOLD` with FreeBSD's values. A malformed bracket matches `[` literally, as FreeBSD does. Each byte is one character, `FNM_CASEFOLD` folds ASCII letters and ranges compare byte values, and `[:class:]` names are plain bracket characters, as in FreeBSD 11 through 14; multibyte characters and locale collation are not modelled, which TechnicalDebt records. A null pattern or string throws. Cloud Play (PPSA99600) imports it from libScePosixForWebKit and stops at it on `main` a11c8f7f (catalog build, `eboot.bin` and `sce_module/libc.prx` unwrapped as #2605 requires; tracked in #1578): - Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: 60q1rziOzzQ` - Windows: `FAIL: unresolved ELF import 60q1rziOzzQ (fnmatch) from libScePosixForWebKit.prx` - with this PR, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: H1bArJPagV0` (`getservbyname`) - with this PR, Windows: `FAIL: unresolved ELF import H1bArJPagV0 (getservbyname) from libScePosixForWebKit.prx` ### Tested Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release: the new `guest_fnmatch` passes 5/5 (`--repeat until-fail:5`) on both, with no warnings in the changed files. Its 50 cases cover every flag, `[[:digit:]]`-style class syntax, ranges, negation, escapes, leading periods, `FNM_PATHNAME` slashes and backtracking; each expected result comes from FreeBSD 11's own `fnmatch.c` compiled on Linux with the C-locale collation path. It also checks that a null pattern throws. `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 12:56:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T12:56:57Z.


Progress report (a11c8f7 → 81e3e34)

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

✅ 1 implemented
Library Name
libScePosixForWebKit fnmatch_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109256208 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545#issuecomment-6109256208). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T12:56:57Z. --- <!-- progress-report --> ### Progress report (a11c8f7 → 81e3e34) 📈 **System libraries**: 85.82% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libScePosixForWebKit | `fnmatch_nid_postfix` | </details>
MarcZX10 commented 2026-10-11 13:15:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:15:52Z.


I noticed bracket expressions currently handle individual bytes and ranges, but not POSIX named character classes. For example, [[:digit:]] is parsed as a literal [ plus a trailing ], so it won’t match 7 as FreeBSD fnmatch does in the C locale. Could you add the C-locale classes (at least a regression for [[:digit:]]) or make unsupported class syntax fail explicitly, so this doesn’t silently return a false match?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109417207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545#issuecomment-6109417207). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T13:15:52Z. --- I noticed bracket expressions currently handle individual bytes and ranges, but not POSIX named character classes. For example, `[[:digit:]]` is parsed as a literal `[` plus a trailing `]`, so it won’t match `7` as FreeBSD `fnmatch` does in the C locale. Could you add the C-locale classes (at least a regression for `[[:digit:]]`) or make unsupported class syntax fail explicitly, so this doesn’t silently return a false match?
babyhuey commented 2026-10-11 13:32:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T13:32:25Z.


@MarcZX100 thanks for checking. FreeBSD 11's fnmatch.c, which this follows, has no [:class:] handling in rangematch: it reads [[:digit:]] as the set [, :, d, i, g, t followed by a literal ]. stable/12, stable/13 and releng/14.1 are the same; class support only shows up on FreeBSD main. Built as an oracle, FreeBSD 11's own code returns FNM_NOMATCH for [[:digit:]] against 7 and a match against d], and so does this port.

Since the PS5 libc follows FreeBSD 11, I kept that behaviour and pinned it: 81e3e346 adds those cases (plus :] and a[[:alpha:]] against ab) to guest_fnmatch and says it in the TechnicalDebt line. guest_fnmatch passes 5/5 on Linux and Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109560826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545#issuecomment-6109560826). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T13:32:25Z. --- @MarcZX100 thanks for checking. FreeBSD 11's `fnmatch.c`, which this follows, has no `[:class:]` handling in `rangematch`: it reads `[[:digit:]]` as the set `[`, `:`, `d`, `i`, `g`, `t` followed by a literal `]`. stable/12, stable/13 and releng/14.1 are the same; class support only shows up on FreeBSD `main`. Built as an oracle, FreeBSD 11's own code returns `FNM_NOMATCH` for `[[:digit:]]` against `7` and a match against `d]`, and so does this port. Since the PS5 libc follows FreeBSD 11, I kept that behaviour and pinned it: 81e3e346 adds those cases (plus `:]` and `a[[:alpha:]]` against `ab`) to `guest_fnmatch` and says it in the TechnicalDebt line. `guest_fnmatch` passes 5/5 on Linux and Windows.
MarcZX10 commented 2026-10-11 13:45:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:45:06Z.


Thanks for checking FreeBSD 11 directly and adding regression cases. My earlier assumption about POSIX named character classes was incorrect: the PS5 follows the older implementation, which parses those bytes literally. Your oracle results and tests resolve my concern.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109670924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545#issuecomment-6109670924). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T13:45:06Z. --- Thanks for checking FreeBSD 11 directly and adding regression cases. My earlier assumption about POSIX named character classes was incorrect: the PS5 follows the older implementation, which parses those bytes literally. Your oracle results and tests resolve my concern.
github-actions[bot] commented 2026-10-11 17:28:11 +00:00 (Migrated from github.com)

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


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
#3798 docs/dev/TechnicalDebt.md L361
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111705022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545#issuecomment-6111705022). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T17:28:11Z. --- <!-- 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 | |---|---|---|---| | #3798 | `docs/dev/TechnicalDebt.md` [L361](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/docs/dev/TechnicalDebt.md#L361) | | |
adriadam10 commented 2026-10-11 21:37:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:37:38Z.


Checked the port against FreeBSD 11 fnmatch.c (C-locale path) with 30M random pattern/string/flag combinations: no differences. guest_fnmatch passes and does not link without the change; ctest for libs and libScePosixForWebKit is green. The NID resolves to fnmatch and no other library exports it. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114054289 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3545#issuecomment-6114054289). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:37:38Z. --- Checked the port against FreeBSD 11 `fnmatch.c` (C-locale path) with 30M random pattern/string/flag combinations: no differences. `guest_fnmatch` passes and does not link without the change; ctest for libs and libScePosixForWebKit is green. The NID resolves to `fnmatch` and no other library exports it. Merging.
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!3545
No description provided.