diff --git a/usr.bin/bintrans/uudecode.c b/usr.bin/bintrans/uudecode.c --- a/usr.bin/bintrans/uudecode.c +++ b/usr.bin/bintrans/uudecode.c @@ -331,11 +331,21 @@ warnx("%s: %s: %s", infile, outfile, msg); return (1); } - if (fclose(outfp) != 0) { + return (0); +} + +static int +checkout(int rval) +{ + if (fflush(outfp) != 0) { warn("%s: %s", infile, outfile); - return (1); + rval = 1; } - return (0); + if (outfp != stdout) { + (void)fclose(outfp); + outfp = stdout; + } + return (rval); } static int @@ -349,9 +359,9 @@ for (;;) { switch (get_line(buf, sizeof(buf))) { case 0: - return (0); + return (checkout(0)); case 1: - return (1); + return (checkout(1)); } #define DEC(c) (((c) - ' ') & 077) /* single character decode */ @@ -408,11 +418,11 @@ } switch (get_line(buf, sizeof(buf))) { case 0: - return (0); + return (checkout(0)); case 1: - return (1); + return (checkout(1)); default: - return (checkend(buf, "end", "no \"end\" line")); + return (checkout(checkend(buf, "end", "no \"end\" line"))); } } @@ -430,9 +440,9 @@ switch (get_line(inbuf + strlen(inbuf), sizeof(inbuf) - strlen(inbuf))) { case 0: - return (0); + return (checkout(0)); case 1: - return (1); + return (checkout(1)); } count = 0; @@ -459,7 +469,7 @@ break; fwrite(outbuf, 1, n, outfp); } - return (checkend(inbuf, "====", "error decoding base64 input stream")); + return (checkout(checkend(inbuf, "====", "error decoding base64 input stream"))); } static void diff --git a/usr.bin/bintrans/uuencode.c b/usr.bin/bintrans/uuencode.c --- a/usr.bin/bintrans/uuencode.c +++ b/usr.bin/bintrans/uuencode.c @@ -74,7 +74,7 @@ if (w != NULL) columns = arg_to_col(w); base64_encode(); - if (ferror(output)) + if (fflush(output) != 0) errx(1, "write error"); exit(0); } @@ -144,7 +144,7 @@ base64_encode(); else encode(); - if (ferror(output)) + if (fflush(output) != 0) errx(1, "write error"); exit(0); }