From f7d0b5fe72c29de4c4f872d5a2c6578f0d68a462 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Tue, 18 Oct 2011 16:45:03 +0200 Subject: 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) --- src/redshift.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/redshift.c') diff --git a/src/redshift.c b/src/redshift.c index ad86d78..08f3e1d 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -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) { -- cgit v1.2.3-70-g09d2