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