fix(libc): parse fopen and freopen modes as FreeBSD does #2033
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2033"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-09T05:33:49Z.
What
vkQuake (PPSA99010, the homebrew Vulkan port) opens
history.txtwith mode"rt"at startup, and AnyPS5 threw fromfopen.FreeBSD's
__sflags(lib/libc/stdio/flags.c) reads the access character (r,w,a), thenb,+,x,eandv, and stops at the first other character without failing, so on the console"rt"opens for reading. On Windows, AnyPS5'sfopeninsertedbafter the first character and passed the rest on:"rt"became"rbt". The CRT rejected that withEINVAL, andfopenthrows for any error other thanENOENT.freopenaccepted only a fixed list of 15 modes.Both now parse the mode like
__sflags(ParseFileMode):+if seen, thenbon Windows, thenxif seen.xon a read-only stream, returns NULL withEINVAL, as__sflagsdoes.xon an existing file returns NULL withEEXISTinstead of throwing.e(close-on-exec) andv(verify) are accepted and ignored."rt+", which FreeBSD opens read-only, no longer counts as writing.Tests (
guest_standard_streams):fopenandfreopen, adds"rt","r+t","wt","w+e","ae"and"rbv"."","q","tr","rx"and"rbx"return NULL withEINVALfrom both."wx"on an existing file returns NULL withEEXIST, and on a new file creates and writes it."rt+"opens read-only: a write fails.fopenon"rt") with the oldFileAndHeap.cpp.Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.
CTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.tools/check_conventions.py --base origin/mainpasses.history.txtopen with this, on a local branch with my other pending changes.Not tested on Linux or macOS. The
binsertion stays Windows-only as before.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T05:53:52Z.
Review: APPROVED
Reviewed the complete current diff. The parser follows the documented FreeBSD mode scan, preserves the Windows binary-mode conversion, and the expanded guest_standard_streams cases exercise accepted flags, stop-at-unknown behavior, invalid access/exclusive modes, and create/no-replace semantics. Current Linux and Windows CI plus conventions/report checks are green. Approved.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:17:32Z.
Conflicts with main in
core/libs/prx/libc/src/FileAndHeap.cpp; please rebase.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:56:59Z.
Rebased onto current main, no conflicts. Checked
ParseFileModeagainst FreeBSD__sflags,guest_standard_streamspasses on Linux and fails with the oldFileAndHeap.cpp, and Build/Conventions are green on this head; merging.