What part of the system sets up the buffering of the three standard streams when a program is started?
Is this part of linux, or glibc, or maybe bash? Does POSIX define the behaviour, or is it part of C?
Posix has some answers:
At program start-up, three streams are predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output). When opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device.
So if the system can determine that streams are NOT interactive, they CAN be fully buffered (except stderr), but in practice what part of the system does this determining?