Diffstat (limited to 'cache.c')
| -rw-r--r-- | cache.c | 47 |
1 files changed, 20 insertions, 27 deletions
@@ -85,45 +85,40 @@ static int close_slot(struct cache_slot *slot) /* Print the content of the active cache slot (but skip the key). */ static int print_slot(struct cache_slot *slot) { - off_t off; #ifdef HAVE_LINUX_SENDFILE - off_t size; -#endif - - off = slot->keylen + 1; + off_t start_off; + int ret; -#ifdef HAVE_LINUX_SENDFILE - size = slot->cache_st.st_size; + start_off = slot->keylen + 1; do { - ssize_t ret; - ret = sendfile(STDOUT_FILENO, slot->cache_fd, &off, size - off); + ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off, + slot->cache_st.st_size - start_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; + return 0; } while (1); -#endif +#else + ssize_t i, j; - if (lseek(slot->cache_fd, off, SEEK_SET) != off) + i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); + if (i != slot->keylen + 1) return errno; do { - ssize_t ret; - ret = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); - if (ret < 0) - return errno; - if (ret == 0) - return 0; - if (write_in_full(STDOUT_FILENO, slot->buf, ret) < 0) - return errno; - } while (1); + 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); + + if (i < 0 || j != i) + return errno; + else + return 0; +#endif } /* Check if the slot has expired */ @@ -185,8 +180,6 @@ static int lock_slot(struct cache_slot *slot) slot->lock_fd = -1; return saved_errno; } - if (ftruncate(slot->lock_fd, 0) < 0) - return errno; if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0) return errno; return 0; |