- ssize_t bytes_written;
- size_t bytes_remaining;
-
- for (bytes_remaining = count;
- bytes_remaining != 0;
- bytes_remaining -= bytes_written, buf += bytes_written)
- {
- bytes_written = write(fd, buf, bytes_remaining);
- if (bytes_written < 0) {
- if (errno == EINTR)
- continue;
- break;
- }
+ int ret;
+
+ /* Verify the offset. */
+ if (offset < fd->offset) {
+ ERROR("Can't seek backwards in pipe "
+ "(offset %"PRIu64" => %"PRIu64").\n"
+ " Make sure the WIM was captured as "
+ "pipable.", fd->offset, offset);
+ errno = ESPIPE;
+ return WIMLIB_ERR_RESOURCE_ORDER;
+ }
+
+ /* Manually seek to the requested position. */
+ while (fd->offset != offset) {
+ size_t bytes_to_read = min(offset - fd->offset, BUFFER_SIZE);
+ u8 dummy[bytes_to_read];
+
+ ret = full_read(fd, dummy, bytes_to_read);
+ if (ret)
+ return ret;