Set buffering on stdout and stderr to line-buffered.

Previously stdout would be block buffered and stderr unbuffered when writing to a non-terminal.
This code works on Debian with libc 2.11.2. The man page of setvbuf mentions that NULL can be used to avoid affecting the used buffer, but doesn't mention whether the size argument is then ignored; testing on Debian has revealed that this code works as intended, but I don't know whether that's standard.
(Christian Jaeger)
This commit is contained in:
Jon Lund Steffensen
2011-10-18 16:45:03 +02:00
parent 3bd88a4307
commit f7d0b5fe72
+7
View File
@@ -657,6 +657,13 @@ main(int argc, char *argv[])
int verbose = 0;
char *s;
/* Flush messages consistently even if redirected to a pipe or
file. Change the flush behaviour to line-buffered, without
changing the actual buffers being used.
*/
setvbuf (stdout, NULL, _IOLBF, 0);
setvbuf (stderr, NULL, _IOLBF, 0);
/* Parse command line arguments. */
int opt;
while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:rt:vVx")) != -1) {