Mercurial > hg > toybox
changeset 1318:955169e818d0 draft
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.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 26 May 2014 12:25:47 -0500 |
parents | 94e143a0089f |
children | 1fa185766188 |
files | lib/xwrap.c |
diffstat | 1 files changed, 5 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/xwrap.c Sun May 25 20:49:51 2014 -0500 +++ b/lib/xwrap.c Mon May 26 12:25:47 2014 -0500 @@ -94,22 +94,23 @@ 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