| OLD | NEW |
| 1 #include "stdio_impl.h" | 1 #include "stdio_impl.h" |
| 2 #include <sys/uio.h> | 2 #include <sys/uio.h> |
| 3 | 3 |
| 4 size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) | 4 size_t __stdio_write(FILE* f, const unsigned char* buf, size_t len) { |
| 5 { | 5 struct iovec iovs[2] = {{.iov_base = f->wbase, .iov_len = f->wpos - f->wbase}, |
| 6 » struct iovec iovs[2] = { | 6 {.iov_base = (void*)buf, .iov_len = len}}; |
| 7 » » { .iov_base = f->wbase, .iov_len = f->wpos-f->wbase }, | 7 struct iovec* iov = iovs; |
| 8 » » { .iov_base = (void *)buf, .iov_len = len } | 8 size_t rem = iov[0].iov_len + iov[1].iov_len; |
| 9 » }; | 9 int iovcnt = 2; |
| 10 » struct iovec *iov = iovs; | 10 ssize_t cnt; |
| 11 » size_t rem = iov[0].iov_len + iov[1].iov_len; | 11 for (;;) { |
| 12 » int iovcnt = 2; | 12 cnt = syscall(SYS_writev, f->fd, iov, iovcnt); |
| 13 » ssize_t cnt; | 13 if (cnt == rem) { |
| 14 » for (;;) { | 14 f->wend = f->buf + f->buf_size; |
| 15 » » cnt = syscall(SYS_writev, f->fd, iov, iovcnt); | 15 f->wpos = f->wbase = f->buf; |
| 16 » » if (cnt == rem) { | 16 return len; |
| 17 » » » f->wend = f->buf + f->buf_size; | 17 } |
| 18 » » » f->wpos = f->wbase = f->buf; | 18 if (cnt < 0) { |
| 19 » » » return len; | 19 f->wpos = f->wbase = f->wend = 0; |
| 20 » » } | 20 f->flags |= F_ERR; |
| 21 » » if (cnt < 0) { | 21 return iovcnt == 2 ? 0 : len - iov[0].iov_len; |
| 22 » » » f->wpos = f->wbase = f->wend = 0; | 22 } |
| 23 » » » f->flags |= F_ERR; | 23 rem -= cnt; |
| 24 » » » return iovcnt == 2 ? 0 : len-iov[0].iov_len; | 24 if (cnt > iov[0].iov_len) { |
| 25 » » } | 25 cnt -= iov[0].iov_len; |
| 26 » » rem -= cnt; | 26 iov++; |
| 27 » » if (cnt > iov[0].iov_len) { | 27 iovcnt--; |
| 28 » » » cnt -= iov[0].iov_len; | 28 } |
| 29 » » » iov++; iovcnt--; | 29 iov[0].iov_base = (char*)iov[0].iov_base + cnt; |
| 30 » » } | 30 iov[0].iov_len -= cnt; |
| 31 » » iov[0].iov_base = (char *)iov[0].iov_base + cnt; | 31 } |
| 32 » » iov[0].iov_len -= cnt; | |
| 33 » } | |
| 34 } | 32 } |
| OLD | NEW |