/* * Splice argument file to stdout */ #include #include #include #include #define SPLICE_SIZE (64*1024) #if defined(__i386__) #define __NR_splice 294 #elif defined(__x86_64__) #define __NR_splice 256 #elif defined(__powerpc__) || defined(__powerpc64__) #define __NR_splice 278 #else #error unsupported arch #endif static inline int splice(int fdin, int fdout, size_t len, unsigned long flags) { return syscall(__NR_splice, fdin, fdout, len, flags); } int main(int argc, char *argv[]) { int fd; if (argc < 2) { printf("%s: outfile\n", argv[0]); return 1; } fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd < 0) { perror("open"); return 1; } do { int ret = splice(STDIN_FILENO, fd, SPLICE_SIZE, 0); if (ret < 0) { perror("splice"); break; } else if (!ret) break; } while (1); close(fd); return 0; }