if (bsdtar->filename == NULL)
bsdtar->filename = _PATH_DEFTAPE;
+ /* Default block size settings. */
+ bsdtar->bytes_per_block = DEFAULT_BYTES_PER_BLOCK;
+ /* Allow library to default this unless user specifies -b. */
+ bsdtar->bytes_in_last_block = -1;
+
/* Default: preserve mod time on extract */
bsdtar->extract_flags = ARCHIVE_EXTRACT_TIME;
lafe_errc(1, 0,
"Argument to -b is out of range (1..8192)");
bsdtar->bytes_per_block = 512 * t;
+ /* Explicit -b forces last block size. */
+ bsdtar->bytes_in_last_block = bsdtar->bytes_per_block;
break;
case 'C': /* GNU tar */
set_chdir(bsdtar, bsdtar->optarg);
archive_read_support_format_all(a);
if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options))
lafe_errc(1, 0, "%s", archive_error_string(a));
- if (archive_read_open_file(a, bsdtar->filename,
- bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
- DEFAULT_BYTES_PER_BLOCK))
+ if (archive_read_open_file(a, bsdtar->filename, bsdtar->bytes_per_block))
lafe_errc(1, 0, "Error opening archive: %s",
archive_error_string(a));
usage();
}
- /*
- * If user explicitly set the block size, then assume they
- * want the last block padded as well. Otherwise, use the
- * default block size and accept archive_write_open_file()'s
- * default padding decisions.
- */
- if (bsdtar->bytes_per_block != 0) {
- archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
- archive_write_set_bytes_in_last_block(a,
- bsdtar->bytes_per_block);
- } else
- archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
+ archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
+ archive_write_set_bytes_in_last_block(a, bsdtar->bytes_in_last_block);
if (bsdtar->compress_program) {
archive_write_set_compression_program(a, bsdtar->compress_program);
archive_read_support_compression_all(a);
archive_read_support_format_tar(a);
archive_read_support_format_gnutar(a);
- if (archive_read_open_fd(a, bsdtar->fd,
- bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
- DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
+ if (archive_read_open_fd(a, bsdtar->fd, bsdtar->bytes_per_block)
+ != ARCHIVE_OK) {
lafe_errc(1, 0,
"Can't open %s: %s", bsdtar->filename,
archive_error_string(a));
if (format == ARCHIVE_FORMAT_TAR_GNUTAR)
format = ARCHIVE_FORMAT_TAR_USTAR;
archive_write_set_format(a, format);
- if (bsdtar->bytes_per_block != 0) {
- archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
- archive_write_set_bytes_in_last_block(a,
- bsdtar->bytes_per_block);
- } else
- archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
+ archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
+ archive_write_set_bytes_in_last_block(a, bsdtar->bytes_in_last_block);
+
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))
ina = archive_read_new();
archive_read_support_format_all(ina);
archive_read_support_compression_all(ina);
- if (archive_read_open_file(ina, filename, 10240)) {
+ if (archive_read_open_file(ina, filename, bsdtar->bytes_per_block)) {
lafe_warnc(0, "%s", archive_error_string(ina));
bsdtar->return_value = 1;
return (0);