]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
More code simplifications on the seek implementation.
authorTim Kientzle <kientzle@gmail.com>
Sun, 19 Jul 2009 07:04:26 +0000 (03:04 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 19 Jul 2009 07:04:26 +0000 (03:04 -0400)
SVN-Revision: 1237

tar/write.c

index d93b2ec380ce214d261b4ad47543ed6ef9e70d52..a0d681e81a8fbba977a4346f3dc695e79c451ec9 100644 (file)
@@ -142,26 +142,20 @@ static void                write_hierarchy(struct bsdtar *, struct archive *,
                             const char *);
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
-#define open _open
-#define close _close
-#define read _read
-
-static void
-seek_file(int fd, int64_t length)
+/* Not a full lseek() emulation, but enough for our needs here. */
+static int
+seek_file(int fd, int64_t offset, int whence)
 {
        LARGE_INTEGER distance;
-       distance.QuadPart = length;
-       if (!SetFilePointerEx((HANDLE)_get_osfhandle(fd),
-               distance, NULL, FILE_BEGIN))
-               lafe_errc(1, 0, "Could not seek to archive end");
-}
-#else
-static void
-seek_file(int fd, int64_t length)
-{
-       if (lseek(fd, length, SEEK_SET) < 0)
-               lafe_errc(1, errno, "Could not seek to archive end");
+       (void)whence; /* UNUSED */
+       distance.QuadPart = offset;
+       return (SetFilePointerEx((HANDLE)_get_osfhandle(fd),
+               distance, NULL, FILE_BEGIN) ? 1 : -1);
 }
+#define open _open
+#define close _close
+#define read _read
+#define lseek seek_file
 #endif
 
 void
@@ -324,7 +318,8 @@ tar_mode_r(struct bsdtar *bsdtar)
                        format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
                archive_write_set_format(a, format);
        }
-       seek_file(bsdtar->fd, end_offset);
+       if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
+               lafe_errc(1, errno, "Could not seek to archive end");
        if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
                lafe_errc(1, 0, archive_error_string(a));
        if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
@@ -406,7 +401,8 @@ tar_mode_u(struct bsdtar *bsdtar)
                    bsdtar->bytes_per_block);
        } else
                archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
-       seek_file(bsdtar->fd, end_offset);
+       if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
+               lafe_errc(1, errno, "Could not seek to archive end");
        if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
                lafe_errc(1, 0, archive_error_string(a));
        if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))