Repository navigation
Conversation
efb989c to
26bd2fc
Compare
26bd2fc to
e033313
Compare
|
Rebased onto AI-assisted: yes (Claude Code) |
|
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.
|
|
This duplicates #15768, opened on 2026-11-04, which already implements the Linux failure of fscanf, vfscanf, scanf and vscanf on a write-only stream with EBADF and the error indicator (and ungetc and ungetwc returning EOF there) and is still open. Please take a look at #15768 before continuing here, to avoid two PRs for the same change. |
|
Closing as a duplicate of #15768, which was opened 23 minutes earlier, is mergeable with passing checks, and contains the identical Two PRs for the same change only split review; please take any remaining points to #15768. Feel free to reopen if this one covers something that one doesn't. |
What
On Linux, a read from a stream opened only for writing now fails as on FreeBSD 11.4:
EOF(or 0 forfread),errnoEBADF, and the error indicator set. Before,fscanf,vfscanf,scanfandvscanfleft the error indicator clear, as thelibc.mddebt entry "Reads on a write-only stream" recorded.__srefillsetserrno = EBADFand__SERRon a stream with neither__SRDnor__SRW, and every stdio read reaches it first.ungetcreturnsEOFon such a stream without touching either.__vfscanf_internal, which rejects_IO_NO_READSwithout setting_IO_ERR_SEEN.FileStream::SwitchToReadingUnlockednow fails a stream that__freadablereports unreadable, as the Windows branch already does (errno9, the guest error flag, status sync). Every guest read entry point (fgetc,getc_unlocked,fgets,fread, the scanf family and the wide reads built onfgetc) passes through it, so they all agree, and none reaches the host stream.OpenForReadingreturns__freadable, soungetcandungetwcreturnEOFbefore that check and leaveerrnoand the error indicator alone, as FreeBSD and the Windows branch do.Tested
file_streams:CheckReadsOnWriteOnlyStreamscheckederrnoand the error indicator afterfscanf, andungetcon a write-only stream, on Windows only. Those checks now run on every host.Linux (Ubuntu 24.04 container, GCC 13.3.0):
what(): fscanf on a write-only stream left errno or the error indicator unset.file_streamspasses with--repeat until-fail:3. The 66 tests matchingstream|stdio|scanf|ungetc|fopen|fread|fget|getc|freopen|fdopen|popen|wide|formatpass.Windows 11 Pro, Intel Core i5-14600KF, NVIDIA GPU, WinLibs GCC 15.2.0, full Release build with
libs: the Windows code is unchanged.file_streamspasses.ctest:99% tests passed, 6 tests failed out of 4005. All six fail onmainon this machine too:test_registrationandselect_tests_MissingCommandTestsfail withWinError 1314, because this user cannot create symbolic links.agc_driver_direct_write_completion,agc_driver_image_plane_address_on_line,agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_laneare GPU tests on an NVIDIA card.check_skips.pyreports one skip,guest_fopen_errors, which skips itself here because this user cannot create symbolic links.macOS: not tested. Apple's libc follows BSD stdio here (
__srefillandungetcas above), so the checks that are no longer limited to Windows are expected to pass there. The#elsebranch is unchanged.Overlaps: of the open PRs that touch
FileStream.hpp, only #12036 (mine) changesSwitchToReadingUnlocked, in its Windows branch; a trial merge with this branch has no conflicts (git merge-tree). #11831 already conflicts withmaininFileStream.hpp,FileAndHeap.cppandlibc.md; this branch adds no other file to that list.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)