#include #include // for perror #include // for open #include // for open #include // for read/write const int BUF_SIZE = 1024; using namespace std; int main(int argc, char * argv[]) { int inFD, outFD; int outFlags = O_CREAT| O_WRONLY | O_TRUNC; int perms = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH; int readSize, writeSize; char word[BUF_SIZE]; string tmp; if (argc != 3) { cerr << " Usage: " << argv[0] << " inputfile outputfile" << endl; } inFD = open(argv[1], O_RDONLY) ; if (inFD <0) { tmp = argv[1]; tmp = "Failed to open " + tmp + " for input :"; perror(tmp.c_str()); exit(1); } outFD = open(argv[2], outFlags, perms); if (outFD < 0) { tmp = argv[2]; tmp = "Failed to open " + tmp + " for output :"; perror(tmp.c_str()); exit(1); } while((readSize = read(inFD, word, BUF_SIZE)) > 0) { writeSize = write(outFD, word, readSize); if ( readSize != writeSize) { perror("Write Failed :"); exit(0); } } close(inFD); close(outFD); return 0; }