1 #include "stdio_impl.h"
4 static void cleanup(void *p)
7 if (!f->lockcount) __unlockfile(f);
10 size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
12 struct iovec iov[2] = {
13 { .iov_base = buf, .iov_len = len - !!f->buf_size },
14 { .iov_base = f->buf, .iov_len = f->buf_size }
18 pthread_cleanup_push(cleanup, f);
19 cnt = syscall_cp(SYS_readv, f->fd, iov, 2);
20 pthread_cleanup_pop(0);
22 f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt);
23 f->rpos = f->rend = 0;
26 if (cnt <= iov[0].iov_len) return cnt;
27 cnt -= iov[0].iov_len;
29 f->rend = f->buf + cnt;
30 if (f->buf_size) buf[len-1] = *f->rpos++;