1
0
mirror of git://git.musl-libc.org/musl synced 2025-04-01 22:48:38 +00:00

avoid use of readv syscall in __stdio_read backend when not needed

formally, calling readv with a zero-length first iov component should
behave identically to calling read on just the second component, but
presence of a zero-length iov component has triggered bugs in some
kernels and performs significantly worse than a simple read on some
file types.
This commit is contained in:
Rich Felker 2018-02-24 11:19:54 -05:00
parent f92804188e
commit e7eeeb9f2a

View File

@ -9,7 +9,8 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
};
ssize_t cnt;
cnt = syscall(SYS_readv, f->fd, iov, 2);
cnt = iov[0].iov_len ? syscall(SYS_readv, f->fd, iov, 2)
: syscall(SYS_read, f->fd, iov[1].iov_base, iov[1].iov_len);
if (cnt <= 0) {
f->flags |= cnt ? F_ERR : F_EOF;
return 0;