readv(2) System Calls Manual readv(2) readv, writev, preadv, pwritev, preadv2, pwritev2 - C (libc, -lc) #include ssize_t readv(int fd, const struct iovec *iov, int iovcnt); ssize_t writev(int fd, const struct iovec *iov, int iovcnt); ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset); ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset); ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); glibc (. feature_test_macros(7)): preadv(), pwritev(): glibc 2.19: _DEFAULT_SOURCE glibc 2.19 : _BSD_SOURCE readv() iovcnt , fd, , iov (<< >>). writev() iovcnt , iov, , fd (<< >>). The pointer iov points to an array of iovec structures, described in iovec(3type). readv() read(2), . writev() write(2), . , . , readv() iov[0], iov[1], . ( , , iov.) writev() iov[0], iov[1], . readv() writev() : writev() , ; , readv() , , , (. open(2)). preadv() pwritev() preadv() readv() pread(2). readv(), offset, , . pwritev() readv() pwrite(2). writev(), offset, , . . , fd, . preadv2() pwritev2() preadv() pwritev(), flags, . preadv() pwritev(), offset -1, . flags : RWF_DSYNC ( Linux 4.7) O_DSYNC open(2), . pwritev2(), , . RWF_HIPRI ( Linux 4.6) /. , ( , O_DIRECT). RWF_SYNC ( Linux 4.7) O_SYNC open(2), . pwritev2(), , . RWF_NOWAIT ( Linux 4.14) Do not wait for data which is not immediately available. If this flag is specified, the preadv2() system call will return instantly if it would have to read data from the backing storage or wait for a lock. If some data was successfully read, it will return the number of bytes read. If no bytes were read, it will return -1 and set errno to EAGAIN (but see BUGS). Currently, this flag is meaningful only for preadv2(). RWF_APPEND ( Linux 4.16) O_APPEND open(2) . pwritev2(), , . offset ; . , offset -1, . readv(), preadv() preadv2() ; writev(), pwritev() and pwritev2() . , ( read(2) write(2)). -1, errno . read(2) write(2). , preadv(), preadv2(), pwritev() pwritev2() lseek(2). : EINVAL iov_len ssize_t. EINVAL iovcnt . EOPNOTSUPP flags . C preadv() pwritev() GNU C; . , offset, : unsigned long pos_l, unsigned long pos 32- offset, . readv() writev() POSIX.1-2008. preadv() pwritev() BSD. preadv2() pwritev2() Linux. readv() writev() POSIX.1-2001, 4.4BSD ( 4.2BSD). preadv(), pwritev(): Linux 2.6.30, glibc 2.10. preadv2(), pwritev2(): Linux 4.6, glibc 2.26. C , IOV_MAX Linux, glibc readv() writev() , , - . readv(), , , iov, read(2), , iov_base iov, . writev() write(2). The need for this extra effort in the glibc wrapper functions went away with Linux 2.2 and later. However, glibc continued to provide this behavior until glibc 2.10. Starting with glibc 2.9, the wrapper functions provide this behavior only if the library detects that the system is running a Linux kernel older than Linux 2.6.18 (an arbitrarily selected kernel version). And since glibc 2.20 (which requires a minimum of Linux 2.6.32), the glibc wrapper functions always just directly invoke the system calls. POSIX1, , iov. IOV_MAX ( ) sysconf(_SC_IOV_MAX). Linux 1024. Linux 2.0 16. Linux 5.9 and Linux 5.10 have a bug where preadv2() with the RWF_NOWAIT flag may return 0 even when not at end of file. writev(): char *str0 = "hello "; char *str1 = "world\n"; ssize_t nwritten; struct iovec iov[2]; iov[0].iov_base = str0; iov[0].iov_len = strlen(str0); iov[1].iov_base = str1; iov[1].iov_len = strlen(str1); nwritten = writev(STDOUT_FILENO, iov, 2); pread(2), read(2), write(2) () aereiae , Azamat Hackimov , Dmitriy S. Seregin , Katrin Kutepova , Lockal , Yuri Kozlov , ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 15 2024 . readv(2)