Jeffrey Walton <[email protected]> writes:
> Should you do the same for stderr? I _think_ C does not require
> stderr to be unbuffered. Rather, C requires stderr to be not fully
> buffered, which is a bit different than unbuffered. For example,
> stderr could be in a line-buffered state while not being fully
> buffered based on a block size.
POSIX just requires that "When opened, stderr shall not be fully
buffered..." [1]. C23 says the same thing worded a bit differently in §
7.23.3.
I don't think the buffering of standard error matters much here, since
'tr' will always emit full lines to standard error. Therefore, whether
it is unbuffered or line-buffered, the output would be the same.
E.g., we wouldn't run into the following situation:
$ cat main.c
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
fprintf (stderr, "hello");
printf ("hello stdout\n");
fprintf (stderr, " stderr\n");
return EXIT_SUCCESS;
}
$ gcc main.c
$ stdbuf -eL ./a.out
hello stdout
hello stderr
$ stdbuf -e0 ./a.out
hellohello stdout
stderr
Thanks,
Collin
[1]
https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_05