From: Tim Kientzle Date: Mon, 31 May 2010 19:01:37 +0000 (-0400) Subject: Eliminate some more off_t usage; mark some that are okay because X-Git-Tag: v3.0.0a~984 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1cc924729dab2d656141aaa3f220fde18aff8ba8;p=thirdparty%2Flibarchive.git Eliminate some more off_t usage; mark some that are okay because they're only used on specific platforms where off_t is required. SVN-Revision: 2437 --- diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c index 453efc8a7..4447aeecb 100644 --- a/libarchive/archive_read_disk_entry_from_file.c +++ b/libarchive/archive_read_disk_entry_from_file.c @@ -705,8 +705,8 @@ setup_sparse(struct archive_read_disk *a, { int64_t size; int initial_fd = fd; - off_t initial_off; - off_t off_s, off_e; + off_t initial_off; // FreeBSD/Solaris only, so off_t okay here + off_t off_s, off_e; // FreeBSD/Solaris only, so off_t okay here int exit_sts = ARCHIVE_OK; /* Does filesystem support the reporting of hole ? */ diff --git a/libarchive/archive_read_open_fd.c b/libarchive/archive_read_open_fd.c index bc547a57c..4b9dba308 100644 --- a/libarchive/archive_read_open_fd.c +++ b/libarchive/archive_read_open_fd.c @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_fd.c 201103 2009-12-28 struct read_fd_data { int fd; size_t block_size; - char can_skip; + char use_lseek; void *buffer; }; @@ -78,7 +78,7 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size) return (ARCHIVE_FATAL); } - mine = (struct read_fd_data *)malloc(sizeof(*mine)); + mine = (struct read_fd_data *)calloc(1, sizeof(*mine)); b = malloc(block_size); if (mine == NULL || b == NULL) { archive_set_error(a, ENOMEM, "No memory"); @@ -98,9 +98,8 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size) */ if (S_ISREG(st.st_mode)) { archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - mine->can_skip = 1; - } else - mine->can_skip = 0; + mine->use_lseek = 1; + } #if defined(__CYGWIN__) || defined(_WIN32) setmode(mine->fd, O_BINARY); #endif @@ -138,7 +137,7 @@ file_skip(struct archive *a, void *client_data, int64_t request) struct read_fd_data *mine = (struct read_fd_data *)client_data; off_t old_offset, new_offset; - if (!mine->can_skip) + if (!mine->use_lseek) return (0); /* Reduce request to the next smallest multiple of block_size */ @@ -146,36 +145,24 @@ file_skip(struct archive *a, void *client_data, int64_t request) if (request == 0) return (0); + if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) >= 0) && + ((new_offset = lseek(mine->fd, request, SEEK_CUR)) >= 0)) + return (new_offset - old_offset); + + /* If seek failed once, it will probably fail again. */ + mine->use_lseek = 0; + + /* Let libarchive recover with read+discard. */ + if (errno == ESPIPE) + return (0); + /* - * Hurray for lazy evaluation: if the first lseek fails, the second - * one will not be executed. + * There's been an error other than ESPIPE. This is most + * likely caused by a programmer error (too large request) + * or a corrupted archive file. */ - if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) || - ((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0)) - { - /* If seek failed once, it will probably fail again. */ - mine->can_skip = 0; - - if (errno == ESPIPE) - { - /* - * Failure to lseek() can be caused by the file - * descriptor pointing to a pipe, socket or FIFO. - * Return 0 here, so the compression layer will use - * read()s instead to advance the file descriptor. - * It's slower of course, but works as well. - */ - return (0); - } - /* - * There's been an error other than ESPIPE. This is most - * likely caused by a programmer error (too large request) - * or a corrupted archive file. - */ - archive_set_error(a, errno, "Error seeking"); - return (-1); - } - return (new_offset - old_offset); + archive_set_error(a, errno, "Error seeking"); + return (-1); } static int diff --git a/libarchive/archive_read_open_filename.c b/libarchive/archive_read_open_filename.c index 701cb4b56..34412e401 100644 --- a/libarchive/archive_read_open_filename.c +++ b/libarchive/archive_read_open_filename.c @@ -100,7 +100,7 @@ archive_read_open_filename(struct archive *a, const char *filename, int fd; int is_disk_like = 0; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - off_t mediasize = 0; + off_t mediasize = 0; // FreeBSD-specific, so off_t okay here. #elif defined(__NetBSD__) || defined(__OpenBSD__) struct disklabel dl; #elif defined(__DragonFly__) diff --git a/libarchive/archive_read_open_memory.c b/libarchive/archive_read_open_memory.c index 559781fe1..e816edd3d 100644 --- a/libarchive/archive_read_open_memory.c +++ b/libarchive/archive_read_open_memory.c @@ -134,7 +134,7 @@ memory_read_skip(struct archive *a, void *client_data, int64_t skip) struct read_memory_data *mine = (struct read_memory_data *)client_data; (void)a; /* UNUSED */ - if ((off_t)skip > (off_t)(mine->end - mine->buffer)) + if ((int64_t)skip > (int64_t)(mine->end - mine->buffer)) skip = mine->end - mine->buffer; /* Round down to block size. */ skip /= mine->read_size;