- /* clean up */
- FL_apply(tee_fclose, 0);
- /* Don't bother to close files Exit does that
- * automagically, so we can save a few bytes */
- /* free(FileList); */
- exit(0);
+ /* Now we need to check for i/o errors on stdin and the various
+ * output files. Since we know that the first entry in the output
+ * file table is stdout, we can save one "if ferror" test by
+ * setting the first entry to stdin and checking stdout error
+ * status with bb_fflush_stdout_and_exit()... although fflush()ing
+ * is unnecessary here. */
+
+ p = files;
+ *p = stdin;
+ do { /* Now check for (input and) output errors. */
+ /* Checking ferror should be sufficient, but we may want to fclose.
+ * If we do, remember not to close stdin! */
+ bb_xferror(*p, filenames[(int)(p - files)]);
+ } while (*++p);
+
+ bb_fflush_stdout_and_exit(retval);