fgetc() should be smarter about buffer flushing
Currently fgetc() tries to flush stdout and stderr every time it's called. This is because if we are reading from stdin, the standard behavior is to actually display everything that was sent to stdout before.
Right now fgetc() is probably too conservative. Question is how smart it needs to be when deciding whether to flush (so that it's not overly progressive). Is it enough to check whether stream == stdin or do we need to check whether the underlying file descriptor is a console? (We probably should).
This problem contributes to slow reading of stdin. See also #200 and #201.
Change History
(6)
Type: |
defect → enhancement
|
The Linux manual page states about output streams flushing rules (for reference):
"Output streams that refer to terminal devices are always line buffered by default; pending output to such streams is written automatically whenever an input stream that refers to a terminal device is read."
This means that:
(a) Every output stream which is associated with a terminal should be flushed when you want to read the stream, this does not cover only stdin/out/err.
(b) There's no such requirement for streams which are not associated with a terminal, even if they are called stdin/out/err.
And as a side note: © stderr should be unbuffered by default.