splice(2) System Calls Manual splice(2) splice - / C (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() moves data between two file descriptors without copying between kernel address space and user address space. It transfers up to size bytes of data from the file descriptor fd_in to the file descriptor fd_out, where one of the file descriptors must refer to a pipe. fd_in off_in : o fd_in , off_in NULL. o fd_in off_in NULL, fd_in . o If fd_in does not refer to a pipe and off_in is not NULL, then off_in must point to a buffer which specifies the starting offset from which bytes will be read from fd_in; in this case, the file offset of fd_in is not changed, and the offset pointed to by off_in is adjusted appropriately instead. fd_out off_out. flags , (OR) : SPLICE_F_MOVE , . : , , . : Linux 2.6.21 ( splice()); , . SPLICE_F_NONBLOCK -. , splice(), , , , , ( O_NONBLOCK). SPLICE_F_MORE . , fd_out ( MSG_MORE send(2) TCP_CORK tcp(7)). SPLICE_F_GIFT splice(); vmsplice(2). splice() , . 0 . fd_in , , , , . splice() -1, errno . EAGAIN flags SPLICE_F_NONBLOCK (O_NONBLOCK), . EBADF -. EINVAL (splicing). EINVAL . EINVAL . EINVAL (, ). EINVAL fd_in fd_out . ENOMEM . ESPIPE off_in off_out NULL, . Linux. Linux 2.6.17, glibc 2.5. Linux 2.6.30 , fd_in fd_out . Linux 2.6.31 . -- splice(), vmsplice(2), and tee(2), ; , . : splice() , . tee(2) <<>> . vmsplice(2) <<>> . , , , . . <<>> ( ), , : , . _FILE_OFFSET_BITS should be defined to be 64 in code that uses non-null off_in or off_out or that takes the address of splice, if the code is intended to be portable to traditional 32-bit x86 and ARM platforms where off_t's width defaults to 32 bits. See tee(2) for another example. #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) () Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . splice(2)