#include #include #include #include int main (int argc,char*argv[]) { int src_fd; int dest_fd; char filebuf[256]; /* a small buffer used to copy the file */ ssize_t readSize; src_fd = open(argv[1],O_RDONLY); if (src_fd<0) { printf("the source files does not exist\n"); } dest_fd = open(argv[2], O_CREAT | O_RDWR | O_EXCL | S_IRUSR | S_IWUSR | S_IXUSR | S_IXOTH); if (dest_fd<0) { printf("Sorry, Cant open the destination file\n"); } while (( readSize = read(src_fd, filebuf, sizeof(filebuf)-1)) > 0) { // I turn it into a string only because I'm using printf; // making a copy using "write" would not need this. filebuf[readSize] = '\0'; printf("%s",filebuf); write(dest_fd, filebuf, readSize); } close(src_fd); close(dest_fd); return 0; }