From: Tim Kientzle Date: Sun, 19 Jul 2009 07:04:26 +0000 (-0400) Subject: More code simplifications on the seek implementation. X-Git-Tag: v2.8.0~524 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=864ba4d7eb3d3ef5bdfc3f112247d93529974ee3;p=thirdparty%2Flibarchive.git More code simplifications on the seek implementation. SVN-Revision: 1237 --- diff --git a/tar/write.c b/tar/write.c index d93b2ec38..a0d681e81 100644 --- a/tar/write.c +++ b/tar/write.c @@ -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))