aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-04-16 16:53:27 -0500
committerRob Landley <rob@landley.net>2019-04-16 16:53:27 -0500
commit2a1f89e5d941a77e8c93ad0a5fe78229a4207d61 (patch)
treef54c6364e70eafb604bff6e078728e6faf66a57d /lib/xwrap.c
parent63a0e7afff271ac1b1df3309bbf35f52e4771419 (diff)
downloadtoybox-2a1f89e5d941a77e8c93ad0a5fe78229a4207d61.tar.gz
Add argument to xflush() so it can test for stdout err without flushing.
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 12170ada..a242cd53 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -54,7 +54,7 @@ void xexit(void)
free(al);
}
- if (fflush(0) || ferror(stdout)) if (!toys.exitval) perror_msg("write");
+ xflush(1);
_xexit();
}
@@ -139,9 +139,11 @@ char *xmprintf(char *format, ...)
return ret;
}
-void xflush(void)
+// if !flush just check for error on stdout without flushing
+void xflush(int flush)
{
- if (fflush(stdout) || ferror(stdout)) perror_exit("write");
+ if ((flush && fflush(0)) || ferror(stdout))
+ if (!toys.exitval) perror_msg("write");
}
void xprintf(char *format, ...)
@@ -151,7 +153,7 @@ void xprintf(char *format, ...)
vprintf(format, va);
va_end(va);
- xflush();
+ xflush(0);
}
// Put string with length (does not append newline)
@@ -164,7 +166,7 @@ void xputsl(char *s, int len)
len -= out;
s += out;
}
- xflush();
+ xflush(0);
}
// xputs with no newline
@@ -177,13 +179,13 @@ void xputsn(char *s)
void xputs(char *s)
{
puts(s);
- xflush();
+ xflush(0);
}
void xputc(char c)
{
if (EOF == fputc(c, stdout)) perror_exit("write");
- xflush();
+ xflush(0);
}
// This is called through the XVFORK macro because parent/child of vfork