- ssize_t bytes_remaining = msg->total_out_bytes;
- struct iovec *vecs = msg->out_chunks;
- unsigned nvecs = msg->num_chunks;
- int ret;
-
- wimlib_assert(nvecs != 0);
- wimlib_assert(msg->total_out_bytes != 0);
-
- for (unsigned i = 0; i < msg->num_chunks; i++) {
- *chunk_tab->cur_offset_p++ = chunk_tab->cur_offset;
- chunk_tab->cur_offset += vecs[i].iov_len;
- }
- for (;;) {
- ssize_t bytes_written;
-
- bytes_written = writev(out_fd, vecs, nvecs);
- if (bytes_written <= 0) {
- if (bytes_written < 0 && errno == EINTR)
- continue;
- else if (bytes_written == 0)
- errno = EIO;
- ERROR_WITH_ERRNO("Failed to write WIM chunks");
- ret = WIMLIB_ERR_WRITE;
- break;
- }
- bytes_remaining -= bytes_written;
- if (bytes_remaining <= 0) {
- ret = 0;
- break;
- }
- while (bytes_written >= 0) {
- wimlib_assert(nvecs != 0);
- if (bytes_written >= vecs[0].iov_len) {
- vecs++;
- nvecs--;
- bytes_written -= vecs[0].iov_len;
- } else {
- vecs[0].iov_base += bytes_written;
- vecs[0].iov_len -= bytes_written;
- bytes_written = 0;
- }
- }
+ for (unsigned i = 0; i < msg->num_chunks; i++)
+ chunk_tab_record_chunk(chunk_tab, msg->out_chunks[i].iov_len);
+ if (full_writev(out_fd, msg->out_chunks,
+ msg->num_chunks) != msg->total_out_bytes)
+ {
+ ERROR_WITH_ERRNO("Failed to write WIM chunks");
+ return WIMLIB_ERR_WRITE;