mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 00:38:31 +00:00
Fix writev() on the New Technology (#117)
This commit is contained in:
parent
6cd1037692
commit
83d0c3b870
8 changed files with 113 additions and 31 deletions
|
@ -26,35 +26,37 @@
|
|||
#include "libc/nt/struct/overlapped.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static textwindows ssize_t sys_read_nt_impl(struct Fd *fd, void *data,
|
||||
size_t size, ssize_t offset) {
|
||||
uint32_t got;
|
||||
struct NtOverlapped overlap;
|
||||
if (ReadFile(fd->handle, data, clampio(size), &got,
|
||||
offset2overlap(offset, &overlap))) {
|
||||
return got;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
}
|
||||
|
||||
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
ssize_t rc;
|
||||
uint32_t size;
|
||||
size_t i, total;
|
||||
uint32_t got, size;
|
||||
struct NtOverlapped overlap;
|
||||
while (iovlen && !iov[0].iov_len) iov++, iovlen--;
|
||||
if (iovlen) {
|
||||
for (total = i = 0; i < iovlen; ++i) {
|
||||
size = clampio(iov[i].iov_len);
|
||||
if (ReadFile(fd->handle, iov[i].iov_base, size, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
total += got;
|
||||
if (opt_offset != -1) opt_offset += got;
|
||||
if (got < iov[i].iov_len) break;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
break; /* read() doesn't EPIPE lool */
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
if (!iov[i].iov_len) continue;
|
||||
rc = sys_read_nt_impl(fd, iov[i].iov_base, iov[i].iov_len, opt_offset);
|
||||
if (rc == -1) return -1;
|
||||
total += rc;
|
||||
if (opt_offset != -1) opt_offset += rc;
|
||||
if (rc < iov[i].iov_len) break;
|
||||
}
|
||||
return total;
|
||||
} else {
|
||||
if (ReadFile(fd->handle, NULL, 0, &got,
|
||||
offset2overlap(opt_offset, &overlap))) {
|
||||
return got;
|
||||
} else if (GetLastError() == kNtErrorBrokenPipe) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
return sys_read_nt_impl(fd, NULL, 0, opt_offset);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue