splice(2) System Calls Manual splice(2) splice - / (libc -lc) #define _GNU_SOURCE /* feature_test_macros(7) */ #define _FILE_OFFSET_BITS 64 #include ssize_t splice(int fd_in, off_t *_Nullable off_in, int fd_out, off_t *_Nullable off_out, size_t size, unsigned int flags); splice() . size fd_in fd_out . fd_in off_in: o fd_in off_in NULL. o fd_in off_in NULL fd_in . o fd_in off_in NULL off_in fd_in fd_in off_in . fd_out off_out. flags (bit mask) OR : SPLICE_F_MOVE . : . : Linux 2.6.21 ( splice()) . SPLICE_F_NONBLOCK /. splice splice() / ( O_NONBLOCK). SPLICE_F_MORE splice . fd_out ( MSG_MORE send(2) TCP_CORK tcp(7)). SPLICE_F_GIFT splice() vmsplice(2). splice() . 0 . fd_in . splice() -1 errno . EAGAIN SPLICE_F_NONBLOCK flags (O_NONBLOCK) . EBADF - . EINVAL . EINVAL . EINVAL . EINVAL ( ). EINVAL fd_in fd_out . ENOMEM . ESPIPE off_in off_out NULL . . 2.6.17 glibc 2.5. Linux 2.6.30 fd_in fd_out . Linux 2.6.31 . splice() vmsplice(2) tee(2) . : splice() . tee(2) "" . vmsplice(2) "" . . . "" ( ) : . _FILE_OFFSET_BITS 64 off_in off_out splice x86 ARM 32 off_t 32 . tee(2) . #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include int main(void) { int fd; int pfd[2]; off_t off; [[gnu::nonstring]] const char s[12] = "Hello, world"; fd = open("out", O_WRONLY | O_CREAT | O_EXCL, 0666); if (fd == -1) err(EXIT_FAILURE, "open"); if (pipe(pfd) == -1) err(EXIT_FAILURE, "pipe"); if (write(pfd[1], s, sizeof(s)) != sizeof(s)) err(EXIT_FAILURE, "write"); if (close(pfd[1]) == -1) err(EXIT_FAILURE, "close"); off = 10; if (splice(pfd[0], NULL, fd, &off, sizeof(s), 0) != sizeof(s)) err(EXIT_FAILURE, "splice"); if (close(pfd[0]) == -1) err(EXIT_FAILURE, "close"); printf("New offset is %jd\n", (intmax_t) off); if (close(fd) == -1) err(EXIT_FAILURE, "close"); exit(EXIT_SUCCESS); } copy_file_range(2), sendfile(2), tee(2), vmsplice(2), pipe(7) 3 . . : . 6.18 8 2026 splice(2)