source:
EcnlProtoTool/trunk/musl-1.1.18/src/stdio/__stdio_read.c
Last change on this file was 444, checked in by , 4 years ago | |
---|---|
|
|
File size: 544 bytes |
Line | |
---|---|
1 | #include "stdio_impl.h" |
2 | #include <sys/uio.h> |
3 | |
4 | size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) |
5 | { |
6 | struct iovec iov[2] = { |
7 | { .iov_base = buf, .iov_len = len - !!f->buf_size }, |
8 | { .iov_base = f->buf, .iov_len = f->buf_size } |
9 | }; |
10 | ssize_t cnt; |
11 | |
12 | cnt = syscall(SYS_readv, f->fd, iov, 2); |
13 | if (cnt <= 0) { |
14 | f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt); |
15 | return cnt; |
16 | } |
17 | if (cnt <= iov[0].iov_len) return cnt; |
18 | cnt -= iov[0].iov_len; |
19 | f->rpos = f->buf; |
20 | f->rend = f->buf + cnt; |
21 | if (f->buf_size) buf[len-1] = *f->rpos++; |
22 | return len; |
23 | } |
Note:
See TracBrowser
for help on using the repository browser.