diff options
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r-- | lib/xwrap.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c index b2416a4e..7e602d5f 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -141,6 +141,11 @@ char *xmprintf(char *format, ...) return ret; } +void xflush(void) +{ + if (fflush(0) || ferror(stdout)) perror_exit("write"); +} + void xprintf(char *format, ...) { va_list va; @@ -148,23 +153,39 @@ void xprintf(char *format, ...) vprintf(format, va); va_end(va); - if (fflush(stdout) || ferror(stdout)) perror_exit("write"); + xflush(); } -void xputs(char *s) +// Put string with length (does not append newline) +void xputsl(char *s, int len) +{ + int out; + + while (len != (out = fwrite(s, 1, len, stdout))) { + if (out<1) perror_exit("write"); + len -= out; + s += out; + } + xflush(); +} + +// xputs with no newline +void xputsn(char *s) { - if (EOF == puts(s) || fflush(stdout) || ferror(stdout)) perror_exit("write"); + xputsl(s, strlen(s)); } -void xputc(char c) +// Write string to stdout with newline, flushing and checking for errors +void xputs(char *s) { - if (EOF == fputc(c, stdout) || fflush(stdout) || ferror(stdout)) - perror_exit("write"); + puts(s); + xflush(); } -void xflush(void) +void xputc(char c) { - if (fflush(stdout) || ferror(stdout)) perror_exit("write");; + if (EOF == fputc(c, stdout)) perror_exit("write"); + xflush(); } // This is called through the XVFORK macro because parent/child of vfork |