Skip to content

fix(libc): keep EOF sticky across appended stream data - #5682

Closed
MarcZX10 wants to merge 4 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-sticky-eof-5279
Closed

MarcZX10 wants to merge 4 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-sticky-eof-5279

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5279.

What

A Windows host stream can resume reading after EOF when another handle appends bytes, while FreeBSD keeps returning EOF until clearerr, a seek, or ungetc. Keep the guest stream’s EOF behavior consistent across fgetc, fgets, fread, and fscanf, including the EOF return rules for formats that do or do not require input. The regression covers the reported append-after-EOF sequence and scanner format cases.

The change carries Hussein Kadhim’s reviewed fix commits with his original commit authorship preserved. The known %n-leading format limitation remains recorded in TechnicalDebt.md.

Tested

  • Linux, GCC 12.2, Release: guest_standard_streams and file_streams passed (2/2).
  • tools/check_conventions.py --base upstream/main passed.
  • Windows-specific test matrix from the issue was not rerun locally.

Checklist

…tioned

FreeBSD refills a stream only while its end-of-file indicator is clear, so fgetc, fgets and fread keep returning end-of-file after the first one until clearerr, a seek or ungetc. The Windows CRT reads again on every call, which returned bytes appended after the end was reached.
They are macros on macOS, so a global-scope qualifier does not compile there.
…repositioned

fscanf now returns end-of-file while the end-of-file indicator is set, like the other read paths. The debt entry also lists the host ungetc limits.
…format

A format that consumes nothing returns 0, a literal or a conversion that needs input returns end-of-file, and a leading %n stays with the host. This also replaces a stray NUL byte in the previous change with a decision made by the format.
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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
#4627 core/libs/prx/libc/src/StandardStreams.cpp L42

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Closing this duplicate: it carries the same EOF-sticky implementation already reviewed in #5330 (and #5222). The maintainer closed #5330 because no title-specific failure was identified and asked contributors to hold generic PRs while the queue is high. I should have found that history before opening this PR.

@MarcZX10 MarcZX10 closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: reads after end-of-file return newly appended data on Windows, where FreeBSD keeps returning EOF until clearerr; fix branch ready

2 participants