Follow us on Google+ Follow us on Facebook Follow us on Twitter

Opened 7 years ago

Last modified 3 years ago

#202 new enhancement

fgetc() should be smarter about buffer flushing

Reported by: Jiri Svoboda Owned by:
Priority: major Milestone: 0.7.1
Component: helenos/unspecified Version: mainline
Keywords: Cc:
Blocker for: Depends on:
See also:


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 (5)

comment:1 Changed 7 years ago by Jakub Jermář


comment:2 Changed 6 years ago by Martin Decky

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.

comment:3 Changed 6 years ago by Jakub Jermář

Type: defectenhancement

comment:4 Changed 5 years ago by Jakub Jermář


comment:5 Changed 3 years ago by Jakub Jermář

Note: See TracTickets for help on using tickets.