Opened 14 years ago

Last modified 6 years ago

#202 new enhancement

fgetc() should be smarter about buffer flushing

Reported by: Jiri Svoboda Owned by:
Priority: major Milestone:
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 (6)

comment:1 by Jakub Jermář, 13 years ago


comment:2 by Martin Decky, 13 years ago

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 by Jakub Jermář, 13 years ago

Type: defectenhancement

comment:4 by Jakub Jermář, 12 years ago


comment:5 by Jakub Jermář, 10 years ago


comment:6 by Jakub Jermář, 6 years ago

Milestone: 0.7.1
Note: See TracTickets for help on using tickets.