#include #include #define BUFFERS 1048576 FILE *fptr; int fd, fd2; char buf[BUFFERS+1], *filename[1000], *destname[1000]; size_t maxbuf; off_t offset; int main(int argc, char *argv[]) { if(argc !=3||argc!=4 ) { printf("%s", "Usage: hw1 ''input filename.ext'' ''output filename.ext'' [buf fer size]"); exit(0); } else { filename = argv[1]; destname = argv[2]; if((fd = open(filename, O_RDONLY)) == -1) { fprintf("%s", "Error Code hw1-1, Can't open input file"); } else if((fd = open(destname, O_CREAT, 0644)) == -1) { fprintf("%s", "Error Code hw2-2, Can't open output file for writing"); } else { maxbuf = argc[3]; fd = open(filename, O_RDONLY); fd2 = open(destname, O_WRONLY); if(argc == 4) { int i = 0; int j = 0; lseek(fd, i, SEEK_END); for(i=maxbuf; i>0; i--) { read(fd, buf, 1) } } else { read(fd, buf, 1); write(fd2, buf); } } }