]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Eliminate some more off_t usage; mark some that are okay because
authorTim Kientzle <kientzle@gmail.com>
Mon, 31 May 2010 19:01:37 +0000 (15:01 -0400)
committerTim Kientzle <kientzle@gmail.com>
Mon, 31 May 2010 19:01:37 +0000 (15:01 -0400)
they're only used on specific platforms where off_t is
required.

SVN-Revision: 2437

libarchive/archive_read_disk_entry_from_file.c
libarchive/archive_read_open_fd.c
libarchive/archive_read_open_filename.c
libarchive/archive_read_open_memory.c

index 453efc8a7d0a0c4e17c419f39229c65e4d905f2e..4447aeecb7dcc6f91cc574f4c4e3a63dab8686bc 100644 (file)
@@ -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 ? */
index bc547a57c523b823c74c9ef471e44d3abdbadb07..4b9dba308ddb0b5898a587a683efe81714f09d8b 100644 (file)
@@ -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
index 701cb4b56b42b1076c48f1ccdb0de50787eb2a6d..34412e401df6888abcd27fe86dcb9a4e97ad68d4 100644 (file)
@@ -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__)
index 559781fe1ee5281643ca4e091a101d812cbe6c05..e816edd3d7b447c44e7609d6f9af9aadbd6fcbdd 100644 (file)
@@ -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;