#include #include #include #include int main(int argc, char *argv[]) { int in; int out; int pagesize; void *buf; off_t pos; if (argc != 3) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } in = open(argv[1], O_RDONLY, 0); out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0666); posix_fadvise(in, 0, 0, POSIX_FADV_SEQUENTIAL); posix_fadvise(out, 0, 0, POSIX_FADV_SEQUENTIAL); pagesize = getpagesize(); buf = malloc(pagesize); pos = 0; for (;;) { ssize_t count; count = read(in, buf, pagesize); if (!count || count == -1) break; write(out, buf, count); /* right usage pattern? */ posix_fadvise(in, pos, count, POSIX_FADV_NOREUSE); posix_fadvise(out, pos, count, POSIX_FADV_NOREUSE); pos += count; } free(buf); close(in); close(out); return EXIT_SUCCESS; }