Repository navigation
fs: clear the end-of-file indicator before every read - #519
Open
The1TrueJoe wants to merge 1 commit into
Open
The1TrueJoe wants to merge 1 commit into
The1TrueJoe wants to merge 1 commit into
Conversation
Commit d075095 ("fs: keep the bytes a short read already delivered") clears the stream's indicators after read(<length>), but read("line"), read("all") and read(<delimiter>) still leave the end-of-file indicator set once they reach the end. stdio keeps it set (musl, glibc since 2.28, the BSDs), so every later read of those kinds on the handle returns nothing, even after more data has arrived: a file that grew, a tty in non-canonical mode with VMIN 0, a FIFO that got a new writer. let r = fs.open('/tmp/f', 'r'), w = fs.open('/tmp/f', 'a'); r.read('line'); // "first\n" r.read('line'); // null, at the end of the file w.write('second\n'); w.flush(); r.read('line'); // null, where "second\n" is expected Clear the indicators on entry, so that no read starts from a state an earlier one left behind. Signed-off-by: Joseph Telaak <joseph@telaak.dev>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
d075095 ("fs: keep the bytes a short read already delivered") clears the stream's indicators after
read(<length>), butread("line"),read("all")andread(<delimiter>)still leave the end-of-file indicator set once they reach the end. stdio keeps it set (musl, glibc since 2.28, the BSDs), so every later read of those kinds on the handle returns nothing, even after more data has arrived: a file that grew, a tty in non-canonical mode with VMIN 0, a FIFO that got a new writer.This clears the indicators on entry to
uc_fs_read_common(), so no read starts from a state an earlier one left behind.tests/custom/99_bugs/65_fs_read_sticky_eofcovers all four modes; it fails without the change and passes with it.Related: #514 handles an interrupted
read("all")and clears the indicators in that branch. The two touch nearby lines but apply cleanly in either order.