#include #include int main(int argc, char *argv[]) { FILE *src, *dst; void *buf; int rcount, wcount; if (argc != 3) { printf("Usage: %s from_file to_file\n", argv[0]); exit(1); } src = fopen(argv[1], "r"); if (src == NULL) { perror(argv[1]); exit(1); } dst = fopen(argv[2], "w"); if (dst == NULL) { perror(argv[2]); fclose(src); exit(1); } #if 0 buf = malloc(BUFSIZ); if (buf == NULL) { perror("malloc"); fclose(src); fclose(dst); exit(1); } #endif while (!feof(src)) { rcount = fread(buf, 1, BUFSIZ, src); if (ferror(src)) { perror("fread"); fclose(src); fclose(dst); exit(1); } wcount = fwrite(buf, 1, rcount, dst); if (ferror(dst)) { perror("fwrite"); fprintf(stderr, "tried to write %d bytes, " "but only %d bytes were written.\n", rcount, wcount); fclose(src); fclose(dst); exit(1); } } fclose(src); fclose(dst); return 0; }