aha
aha copied to clipboard
Buffering, and blocking
Apparently, by default, in the terminal, it makes a program line-buffered, whereas outside that it is fully buffered.
aha
you can just type and immediately see output, whereas aha | cat
, you do not.
This led to some confusion when i was trying to re-use a few piped programs to reduce overhead by inserting a pattern i'd recognize and stop reading at, but the stream just blocked. (Here is a bit of discussion about that.) eklitzke.org/stdout-buffering indicates some other ways it could give people some trouble. @zseri also provides a command stdbuf -o L aha
to avoid this issue.
I am not sure if it is the aha-program's responsibility. See that, for instance, bat
syntax highlighting disables buffering entirely, seems to me that efficiency does kindah matter. Based on what zseri says setvbuf(stream, NULL, _IOLBF, 0);
disables it setlinebuf
makes it line-buffered. I don't think this complexity will bite users/devs in the ass, since it's just setting about the stream?
setvbuf(stream, NULL, _IOLBF, 0);
note the L
in _IOLBF
means that it is equivalent to setlinebuf
.