diff --git a/builtin.c b/builtin.c index 386b6ed..da457e2 100644 --- a/builtin.c +++ b/builtin.c @@ -98,7 +98,7 @@ fatal(_("attempt to use array `%s' in a scalar context"), array_vname(s1)); \ /* efwrite --- like fwrite, but with error checking */ -static void +void efwrite(const void *ptr, size_t size, size_t count, @@ -108,11 +108,13 @@ efwrite(const void *ptr, bool flush) { errno = 0; - if (rp != NULL) { - if (rp->output.gawk_fwrite(ptr, size, count, fp, rp->output.opaque) != count) + if (count) { + if (rp != NULL) { + if (rp->output.gawk_fwrite(ptr, size, count, fp, rp->output.opaque) != count) + goto wrerror; + } else if (fwrite(ptr, size, count, fp) != count) goto wrerror; - } else if (fwrite(ptr, size, count, fp) != count) - goto wrerror; + } if (flush && ((fp == stdout && output_is_tty) || (rp != NULL && (rp->flag & RED_NOBUF) != 0))) {