#include #include #include #include #include #include using namespace std; void FileCopy(char *fromFile, char *toFile) { int fromFD = open(fromFile, O_RDONLY); if (fromFD < 0) { cerr << "Error opening " << fromFile << "\n"; return; } int toFD = creat(toFile, 0666); if (toFD < 0) { cerr << "Error opening "<< toFile << "\n"; close(fromFD); return; } while (1) { char ch; int n = read (fromFD, &ch, 1); if (n <= 0) break; // end of file n = write(toFD, &ch, 1); if (n < 0) {cerr << "Error\n"; return;} } close(fromFD); close(toFD); } main(int argc, char * argv[]) { if (argc != 3) { cerr << "Usage: a.out srcfile dstfile\n"; exit(1); } FileCopy(argv[1], argv[2]); }