X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2F__stdio_write.c;h=63d9c858db371486dcffb75279dbca559c2ca5ce;hb=aed707f679cce80afd929f0efaf080f1e8481330;hp=d4264eff29b10a27adc1709e67dc3bd4bf763a79;hpb=aa398f56fa398f2202b04e82c67f822f3233786f;p=musl diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c index d4264eff..63d9c858 100644 --- a/src/stdio/__stdio_write.c +++ b/src/stdio/__stdio_write.c @@ -2,8 +2,29 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) { - const unsigned char *stop = buf+len; - ssize_t cnt = 1; - for (; buffd, buf, len))>0; buf+=cnt); - return len-(stop-buf); + struct iovec iovs[2] = { + { .iov_base = f->wbase, .iov_len = f->wpos-f->wbase }, + { .iov_base = (void *)buf, .iov_len = len } + }; + struct iovec *iov = iovs; + size_t rem = iov[0].iov_len + iov[1].iov_len; + int iovcnt = 2; + ssize_t cnt; + f->wpos = f->wbase; + for (;;) { + cnt = syscall(SYS_writev, f->fd, iov, iovcnt); + if (cnt == rem) return len; + if (cnt < 0) { + f->wpos = f->wbase = f->wend = 0; + f->flags |= F_ERR; + return iovcnt == 2 ? 0 : len-iov[0].iov_len; + } + rem -= cnt; + if (cnt > iov[0].iov_len) { + cnt -= iov[0].iov_len; + iov++; iovcnt--; + } + iov[0].iov_base = (char *)iov[0].iov_base + cnt; + iov[0].iov_len -= cnt; + } }