1 #include "stdio_impl.h"
4 static void cleanup(void *p)
7 if (!f->lockcount) __unlockfile(f);
10 size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
12 struct iovec iovs[2] = {
13 { .iov_base = f->wbase, .iov_len = f->wpos-f->wbase },
14 { .iov_base = (void *)buf, .iov_len = len }
16 struct iovec *iov = iovs;
17 size_t rem = iov[0].iov_len + iov[1].iov_len;
21 pthread_cleanup_push(cleanup, f);
22 cnt = syscall_cp(SYS_writev, f->fd, iov, iovcnt);
23 pthread_cleanup_pop(0);
25 f->wpos = f->wbase = f->buf;
29 f->wpos = f->wbase = f->wend = 0;
31 return iovcnt == 2 ? 0 : len-iov[0].iov_len;
34 if (cnt > iov[0].iov_len) {
35 f->wpos = f->wbase = f->buf;
36 cnt -= iov[0].iov_len;
38 } else if (iovcnt == 2) {
41 iov[0].iov_base = (char *)iov[0].iov_base + cnt;
42 iov[0].iov_len -= cnt;