term_destination (j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr) cinfo->dest; size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; /* Write any data remaining in the buffer */ if (datacount > 0) { if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) ERREXIT(cinfo, JERR_FILE_WRITE); } _fflush(dest->outfile); /* Make sure we wrote the output file OK */ if (_ferror(dest->outfile)) ERREXIT(cinfo, JERR_FILE_WRITE); }
main(int argc, char *argv[]) { _FILE *fp; void filecopy(_FILE *, _FILE *); char *prog = argv[0]; if (argc == 1) /* no args stdin -> stdout */ filecopy(_stdin, _stdout); else while (--argc > 0) if ((fp = _fopen(*++argv, "r")) == NULL) { fprintf(stderr, "%s: can't open %s\n", prog, *argv); exit(1); } else { filecopy(fp, _stdout); //fclose(fp); } if (_ferror(_stdout)) { fprintf(stderr, "%s: error writing stdout\n", prog); exit(2); } exit(0); }