From ddbaa718dbe3370786eae97000f4c1e8bb259a61 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 26 May 2014 12:25:47 -0500 Subject: Isaac Dunham suggested xprintf() should call fflush() instead of ferror(), and posix-2008 doesn't say if fflush() covers ferror() (or can return success when the stream's error state is set), so call both. --- lib/xwrap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/xwrap.c b/lib/xwrap.c index 5310506c..69682f65 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -94,22 +94,23 @@ void xprintf(char *format, ...) va_start(va, format); vprintf(format, va); - if (ferror(stdout)) perror_exit("write"); + if (fflush(stdout) || ferror(stdout)) perror_exit("write"); } void xputs(char *s) { - if (EOF == puts(s) || fflush(stdout)) perror_exit("write"); + if (EOF == puts(s) || fflush(stdout) || ferror(stdout)) perror_exit("write"); } void xputc(char c) { - if (EOF == fputc(c, stdout) || fflush(stdout)) perror_exit("write"); + if (EOF == fputc(c, stdout) || fflush(stdout) || ferror(stdout)) + perror_exit("write"); } void xflush(void) { - if (fflush(stdout)) perror_exit("write");; + if (fflush(stdout) || ferror(stdout)) perror_exit("write");; } // Call xexec with a chunk of optargs, starting at skip. (You can't just -- cgit v1.2.3