From 5a4c35342642c1760ccea8be80e95d2f5dd47e03 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 23 Jan 2024 11:29:25 -0600 Subject: [PATCH] Consistently use xferror() instead of if (fflush()) perror_exit(); and yank an obsolete comment Elliott spotted. --- lib/xwrap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/xwrap.c b/lib/xwrap.c index d2e787e1..e39dfce6 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -142,10 +142,9 @@ char *xmprintf(char *format, ...) return ret; } -// if !flush just check for error on stdout without flushing void xferror(FILE *fp) { - if (ferror(fp)) perror_exit("write"); + if (ferror(fp)) perror_exit(fp==stdout ? "stdout" : "write"); } void xprintf(char *format, ...) @@ -156,14 +155,15 @@ void xprintf(char *format, ...) vprintf(format, va); va_end(va); - if (ferror(stdout)) perror_exit("stdout"); + xferror(stdout); } // Put string with length (does not append newline) with immediate flush void xputsl(char *s, int len) { fwrite(s, 1, len, stdout); - if (fflush(stdout) || ferror(stdout)) perror_exit("stdout"); + fflush(stdout); + xferror(stdout); } // xputs with no newline @@ -181,7 +181,8 @@ void xputs(char *s) void xputc(char c) { - if (EOF == fputc(c, stdout)) perror_exit("write"); + fputc(c, stdout); + xferror(stdout); } // daemonize via vfork(). Does not chdir("/"), caller should do that first -- 2.39.2