feat(libSceLibcInternal): implement getopt and getopt_long #3694

Merged
MarcZX10 merged 1 commit from upstream-pr/3694 into main 2026-10-12 20:03:44 +00:00
MarcZX10 commented 2026-10-11 15:32:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T15:32:02Z.


What

Carries David's ready implementation from issue #3562, preserving the original commit and authorship. Exports getopt, getopt_long, and the five guest state variables from libSceLibcInternal.

The implementation follows FreeBSD 11.4 getopt and getopt_long behavior, including GNU-compatible permutation, POSIXLY_CORRECT, + and - prefixes, W;, optind = 0 reset, long-option abbreviations, and guest stderr diagnostics. getopt_long_only is not part of the issue and is not included. The issue identifies predicted import failures for XPSemu and RetroArch; neither has been observed in a title run.

Tested

  • Linux, GCC 12.2, Release: built guest_getopt_tests; CTest guest_getopt passed 1/1.
  • python3 tools/check_conventions.py --base upstream/main --head ac55111f7 passed.
  • git diff --check upstream/main...ac55111f7 passed.
  • The issue author reports Windows 11 / MinGW GCC 15.2 Release coverage for guest_getopt and a broad suite on the original ready branch. I have not independently run Windows or a title.

Checklist

  • Based on current main; no other open PR implements these 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
  • No new third-party source is added; implementation follows the FreeBSD algorithm
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820180126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3694). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T15:32:02Z. --- ### What Carries David's ready implementation from [issue #3562](https://github.com/boykopovar/AnyPS5/issues/3562), preserving the original commit and authorship. Exports `getopt`, `getopt_long`, and the five guest state variables from `libSceLibcInternal`. The implementation follows FreeBSD 11.4 `getopt` and `getopt_long` behavior, including GNU-compatible permutation, `POSIXLY_CORRECT`, `+` and `-` prefixes, `W;`, `optind = 0` reset, long-option abbreviations, and guest `stderr` diagnostics. `getopt_long_only` is not part of the issue and is not included. The issue identifies predicted import failures for XPSemu and RetroArch; neither has been observed in a title run. ### Tested - Linux, GCC 12.2, Release: built `guest_getopt_tests`; CTest `guest_getopt` passed 1/1. - `python3 tools/check_conventions.py --base upstream/main --head ac55111f7` passed. - `git diff --check upstream/main...ac55111f7` passed. - The issue author reports Windows 11 / MinGW GCC 15.2 Release coverage for `guest_getopt` and a broad suite on the original ready branch. I have not independently run Windows or a title. ### Checklist - [x] Based on current `main`; no other open PR implements these 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 - [x] No new third-party source is added; implementation follows the FreeBSD algorithm - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 15:32:23 +00:00 (Migrated from github.com)

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


Progress report (1acfa7f → 1d67426)

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

✅ 2 implemented
Library Name
libSceLibcInternal getopt_long_nid_postfix
libSceLibcInternal getopt_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110633177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3694#issuecomment-6110633177). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T15:32:23Z. --- <!-- progress-report --> ### Progress report (1acfa7f → 1d67426) 📈 **System libraries**: 86.37% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libSceLibcInternal | `getopt_long_nid_postfix` | | libSceLibcInternal | `getopt_nid_postfix` | </details>
adriadam10 commented 2026-10-11 22:01:37 +00:00 (Migrated from github.com)

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


Rebased onto current main (only conflict: an adjacent TechnicalDebt line, both kept). Rebuilt and ran the libSceLibcInternal and libs tests: 29/29 pass, including guest_getopt. Logic checked earlier against FreeBSD 11 getopt.c/getopt_long.c; merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114300574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3694#issuecomment-6114300574). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:01:37Z. --- Rebased onto current main (only conflict: an adjacent TechnicalDebt line, both kept). Rebuilt and ran the libSceLibcInternal and libs tests: 29/29 pass, including `guest_getopt`. Logic checked earlier against FreeBSD 11 `getopt.c`/`getopt_long.c`; merging once CI is green.
MarcZX10 commented 2026-10-11 22:17:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T22:17:56Z.


Rebased the getopt implementation onto current main after the eligibility check found it no longer merged cleanly following #3858. The CMake conflict was resolved by retaining both the newly merged Windows TLS-destructor test setup and the getopt test registration. The commit author remains David. Linux GCC 12.2 Release build succeeded; guest_getopt and guest_force_tls_destructor passed (2/2). The conventions checker and git diff --check pass. Fresh GitHub checks are pending.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114497402 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3694#issuecomment-6114497402). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T22:17:56Z. --- Rebased the getopt implementation onto current main after the eligibility check found it no longer merged cleanly following #3858. The CMake conflict was resolved by retaining both the newly merged Windows TLS-destructor test setup and the getopt test registration. The commit author remains David. Linux GCC 12.2 Release build succeeded; guest_getopt and guest_force_tls_destructor passed (2/2). The conventions checker and git diff --check pass. Fresh GitHub checks are pending.
adriadam10 commented 2026-10-12 20:03:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:03:40Z.


Re-checked the new head (your rebase, same patch as the one we reviewed): guest_getopt passes on current main, conventions and eligibility are green. Logic was checked against FreeBSD 11 getopt.c/getopt_long.c; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131697790 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3694#issuecomment-6131697790). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:03:40Z. --- Re-checked the new head (your rebase, same patch as the one we reviewed): `guest_getopt` passes on current main, conventions and eligibility are green. Logic was checked against FreeBSD 11 `getopt.c`/`getopt_long.c`; 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!3694
No description provided.