#include #include #include #include #include #include #ifndef MAP_FILE # define MAP_FILE 0 #endif int main(argc, argv) int argc; char *argv[]; { int fdin, fdout; char *src, *dst; struct stat statbuf; if (argc!=3) { fprintf(stderr, "bad boy, need 2 args (in, out)\b"); exit(27); } if ((fdin = open(argv[1], O_RDONLY)) < 0) { perror("input vomit"); exit(31); } if ((fdout = open(argv[2], O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) { fprintf(stderr, "output sodomy"); exit(119); } if (fstat(fdin, &statbuf) < 0) { perror("stat misthap"); exit(311); } /* set size of output file */ if (lseek(fdout, statbuf.st_size -1, SEEK_SET) < 0) { perror("seek him far and wide"); exit(7); } if (write(fdout, "", 1) != 1) { perror("write home again"); exit(19); } if ((src = mmap( 0, statbuf.st_size, PROT_READ, MAP_FILE|MAP_SHARED, fdin, 0 )) == (caddr_t) -1) { perror("lost reading input"); exit(13); } if ((dst = mmap( 0, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fdout, 0 )) == (caddr_t) -1) { perror("lost my way"); exit(17); } memcpy(dst, src, statbuf.st_size); exit(0); }