+/* Like pread(), but keep trying until everything has been read or we know for
+ * sure that there was an error. */
+static ssize_t
+full_pread(int fd, void *buf, size_t count, off_t offset)
+{
+ ssize_t bytes_remaining = count;
+ ssize_t bytes_read;
+
+ while (bytes_remaining > 0) {
+ bytes_read = pread(fd, buf, bytes_remaining, offset);
+ if (bytes_read <= 0) {
+ if (bytes_read < 0) {
+ if (errno == EINTR)
+ continue;
+ } else {
+ errno = EIO;
+ }
+ break;
+ }
+ bytes_remaining -= bytes_read;
+ buf += bytes_read;
+ offset += bytes_read;
+ }
+ return count - bytes_remaining;
+}
+
+/* Like pwrite(), but keep trying until everything has been written or we know
+ * for sure that there was an error. */
+static ssize_t
+full_pwrite(int fd, const void *buf, size_t count, off_t offset)
+{
+ ssize_t bytes_remaining = count;
+ ssize_t bytes_written;
+
+ while (bytes_remaining > 0) {
+ bytes_written = pwrite(fd, buf, bytes_remaining, offset);
+ if (bytes_written < 0) {
+ if (errno == EINTR)
+ continue;
+ break;
+ }
+ bytes_remaining -= bytes_written;
+ buf += bytes_written;
+ offset += bytes_written;
+ }
+ return count - bytes_remaining;
+}
+