Repository navigation
fix(libc): tell read-only and write-only streams apart on macOS so wrong-mode getc and putc keep errno - #28991
Conversation
…ong-mode getc and putc keep errno
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The change at head f1b3e9709be199bd35f609728f962a4928c2be88 checks Apple stream access flags before reading and preserves errno on wrong-mode calls.
What I ran
Read the changed file and relevant callers at the exact head above. No build or tests were run. The author’s test results were not independently verified.
env -u ANYPS5_READ_LOG python3 repo_read.py search 'OpenForReading'
env -u ANYPS5_READ_LOG python3 repo_read.py search 'OpenForWriting'
env -u ANYPS5_READ_LOG python3 repo_read.py search 'SwitchToReadingUnlocked'
env -u ANYPS5_READ_LOG python3 repo_read.py search '__SRW' core/libs/prx/libc
env -u ANYPS5_READ_LOG python3 repo_read.py cat core/libs/prx/libc/src/StandardStreams.cpp 100 150
env -u ANYPS5_READ_LOG python3 repo_read.py cat core/libs/prx/libc/src/StandardStreams.cpp 150 235
env -u ANYPS5_READ_LOG python3 repo_read.py cat core/libs/prx/libc/src/StandardStreams.cpp 325 395
Results
| Check | Result | Note |
|---|---|---|
| Changed file and callers | passed | All reviewed files were read |
| Build and tests | not run | No verification run by reviewer |
Negative control
Not run; no test was changed or executed.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The author-reported macOS test results were not independently confirmed. No other files were excluded: core/libs/prx/libc/include/FileStream.hpp was the only file listed for review and was read in full.
To get this to a good state
Nothing is required.
What
Follow-up to #22696. It made
fgetc,fputcand their unlocked forms leaveerrnoalone when the stream has the wrong mode, as the console does, by askingFileStreamwhether the stream was opened for reading or writing.OpenForReading,OpenForWritingand the mode check inSwitchToReadingUnlockedread the UCRT flags on Windows and__freadable/__fwritableon glibc, but answer "yes" on every other host. On macOS a wrong-modefputcorfgetctherefore reached the hostfputc/fgetc, which setsEBADF, andfile_streamsandguest_filesystemfail ("fputc after fgetc on a read-only stream", then "fgetc on a write-only stream").On macOS the three checks now read the BSD stream flags the host
FILEalready exposes (__SRD,__SWR,__SRW;FileStreamalready reads__SNBFthere), so a read-only or write-only stream fails the wrong-mode call before the host call, as on Windows and glibc.Tested
Apple M1 Pro, macOS 27.0.1, Apple clang 21.0.0, x86_64 build under Rosetta 2, on main 2c43b61 with the macOS build fixes #11049, #26739, #27739, #27767, #27843 and #27639 merged locally so that main builds.
libc,libkernelandlibSceLibcInternalwere rebuilt, since all three includeFileStream.hpp.file_streams: aborts on main ("fputc after fgetc on a read-only stream"; with only the write check fixed, "fgetc on a write-only stream"); passes 3/3 with this change.guest_filesystem: aborts on main; passes 3/3 with this change.stream|stdio|file|printf|scanf|wchar|getc|putc|ungetc|fopen|popen(203): 3 fail on main, 1 with this change;file_streamsandguest_filesystemare fixed and nothing new fails. The remaining failure,guest_host_streams, fails the same way with and without this change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_012LL9hfx4BY6MbUCYMduDAQ
Summary by CodeRabbit