- i = j = xread(slot->cache_fd, slot->buf, sizeof(slot->buf));
- if (i > 0)
- j = xwrite(STDOUT_FILENO, slot->buf, i);
- } while (i > 0 && j == i);
+ ssize_t ret;
+ ret = sendfile(STDOUT_FILENO, slot->cache_fd, &off, size - off);
+ if (ret < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
+ /* Fall back to read/write on EINVAL or ENOSYS */
+ if (errno == EINVAL || errno == ENOSYS)
+ break;
+ return errno;
+ }
+ if (off == size)
+ return 0;
+ } while (1);
+#endif