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
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))
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))