aboutsummaryrefslogtreecommitdiffstats
path: root/cpio/cpio.c
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2013-03-21 18:59:02 +0000
committerMartin Matuska <mm@FreeBSD.org>2013-03-21 18:59:02 +0000
commit6a316f322a46b3e531726dd2a7de63b9e245878d (patch)
tree45c2c8840d99cc81725a3970fd3beee587313cf5 /cpio/cpio.c
parent81418b36c02b6434acd4b8ae4cfb8c80a3742fd4 (diff)
downloadsrc-6a316f322a46b3e531726dd2a7de63b9e245878d.tar.gz
src-6a316f322a46b3e531726dd2a7de63b9e245878d.zip
Update libarchive's vendor dist to version 3.1.2 from release branch.
Git branch: release Git commit: 19f23e191f9d3e1dd2a518735046100419965804 Obtained from: https://github.com/libarchive/libarchive.git
Notes
Notes: svn path=/vendor/libarchive/dist/; revision=248590
Diffstat (limited to 'cpio/cpio.c')
-rw-r--r--cpio/cpio.c79
1 files changed, 59 insertions, 20 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c
index 7095b6207e4f..6f57d95d616e 100644
--- a/cpio/cpio.c
+++ b/cpio/cpio.c
@@ -207,6 +207,9 @@ main(int argc, char *argv[])
case 'B': /* POSIX 1997 */
cpio->bytes_per_block = 5120;
break;
+ case OPTION_B64ENCODE:
+ cpio->add_filter = opt;
+ break;
case 'C': /* NetBSD/OpenBSD */
cpio->bytes_per_block = atoi(cpio->argument);
if (cpio->bytes_per_block <= 0)
@@ -234,6 +237,9 @@ main(int argc, char *argv[])
lafe_errc(1, 0, "Error : %s",
archive_error_string(cpio->matching));
break;
+ case OPTION_GRZIP:
+ cpio->compress = opt;
+ break;
case 'H': /* GNU cpio (also --format) */
cpio->format = cpio->argument;
break;
@@ -265,7 +271,9 @@ main(int argc, char *argv[])
case 'l': /* POSIX 1997 */
cpio->option_link = 1;
break;
+ case OPTION_LRZIP:
case OPTION_LZMA: /* GNU tar, others */
+ case OPTION_LZOP: /* GNU tar, others */
cpio->compress = opt;
break;
case 'm': /* POSIX 1997 */
@@ -326,6 +334,9 @@ main(int argc, char *argv[])
cpio->extract_flags
&= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
break;
+ case OPTION_UUENCODE:
+ cpio->add_filter = opt;
+ break;
case 'v': /* POSIX 1997 */
cpio->verbose++;
break;
@@ -417,6 +428,7 @@ main(int argc, char *argv[])
archive_match_free(cpio->matching);
free_cache(cpio->gname_cache);
free_cache(cpio->uname_cache);
+ free(cpio->destdir);
return (cpio->return_value);
}
@@ -516,27 +528,49 @@ mode_out(struct cpio *cpio)
if (cpio->archive == NULL)
lafe_errc(1, 0, "Failed to allocate archive object");
switch (cpio->compress) {
+ case OPTION_GRZIP:
+ r = archive_write_add_filter_grzip(cpio->archive);
+ break;
case 'J':
- r = archive_write_set_compression_xz(cpio->archive);
+ r = archive_write_add_filter_xz(cpio->archive);
+ break;
+ case OPTION_LRZIP:
+ r = archive_write_add_filter_lrzip(cpio->archive);
break;
case OPTION_LZMA:
- r = archive_write_set_compression_lzma(cpio->archive);
+ r = archive_write_add_filter_lzma(cpio->archive);
+ break;
+ case OPTION_LZOP:
+ r = archive_write_add_filter_lzop(cpio->archive);
break;
case 'j': case 'y':
- r = archive_write_set_compression_bzip2(cpio->archive);
+ r = archive_write_add_filter_bzip2(cpio->archive);
break;
case 'z':
- r = archive_write_set_compression_gzip(cpio->archive);
+ r = archive_write_add_filter_gzip(cpio->archive);
break;
case 'Z':
- r = archive_write_set_compression_compress(cpio->archive);
+ r = archive_write_add_filter_compress(cpio->archive);
break;
default:
- r = archive_write_set_compression_none(cpio->archive);
+ r = archive_write_add_filter_none(cpio->archive);
break;
}
if (r < ARCHIVE_WARN)
lafe_errc(1, 0, "Requested compression not available");
+ switch (cpio->add_filter) {
+ case 0:
+ r = ARCHIVE_OK;
+ break;
+ case OPTION_B64ENCODE:
+ r = archive_write_add_filter_b64encode(cpio->archive);
+ break;
+ case OPTION_UUENCODE:
+ r = archive_write_add_filter_uuencode(cpio->archive);
+ break;
+ }
+ if (r < ARCHIVE_WARN)
+ lafe_errc(1, 0, "Requested filter not available");
r = archive_write_set_format_by_name(cpio->archive, cpio->format);
if (r != ARCHIVE_OK)
lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
@@ -548,7 +582,7 @@ mode_out(struct cpio *cpio)
/*
* The main loop: Copy each file into the output archive.
*/
- r = archive_write_open_file(cpio->archive, cpio->filename);
+ r = archive_write_open_filename(cpio->archive, cpio->filename);
if (r != ARCHIVE_OK)
lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
lr = lafe_line_reader("-", cpio->option_null);
@@ -577,7 +611,7 @@ mode_out(struct cpio *cpio)
if (!cpio->quiet) {
int64_t blocks =
- (archive_position_uncompressed(cpio->archive) + 511)
+ (archive_filter_bytes(cpio->archive, 0) + 511)
/ 512;
fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
blocks == 1 ? "block" : "blocks");
@@ -806,18 +840,21 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry)
exit(1);
if (r >= ARCHIVE_WARN && archive_entry_size(entry) > 0 && fd >= 0) {
- bytes_read = read(fd, cpio->buff, cpio->buff_size);
+ bytes_read = read(fd, cpio->buff, (unsigned)cpio->buff_size);
while (bytes_read > 0) {
- r = archive_write_data(cpio->archive,
+ ssize_t bytes_write;
+ bytes_write = archive_write_data(cpio->archive,
cpio->buff, bytes_read);
- if (r < 0)
+ if (bytes_write < 0)
lafe_errc(1, archive_errno(cpio->archive),
"%s", archive_error_string(cpio->archive));
- if (r < bytes_read) {
+ if (bytes_write < bytes_read) {
lafe_warnc(0,
- "Truncated write; file may have grown while being archived.");
+ "Truncated write; file may have "
+ "grown while being archived.");
}
- bytes_read = read(fd, cpio->buff, cpio->buff_size);
+ bytes_read = read(fd, cpio->buff,
+ (unsigned)cpio->buff_size);
}
}
@@ -908,7 +945,8 @@ mode_in(struct cpio *cpio)
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
- if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block))
+ if (archive_read_open_filename(a, cpio->filename,
+ cpio->bytes_per_block))
lafe_errc(1, archive_errno(a),
"%s", archive_error_string(a));
for (;;) {
@@ -957,7 +995,7 @@ mode_in(struct cpio *cpio)
if (r != ARCHIVE_OK)
lafe_errc(1, 0, "%s", archive_error_string(ext));
if (!cpio->quiet) {
- int64_t blocks = (archive_position_uncompressed(a) + 511)
+ int64_t blocks = (archive_filter_bytes(a, 0) + 511)
/ 512;
fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
blocks == 1 ? "block" : "blocks");
@@ -988,7 +1026,7 @@ extract_data(struct archive *ar, struct archive *aw)
"%s", archive_error_string(ar));
exit(1);
}
- r = archive_write_data_block(aw, block, size, offset);
+ r = (int)archive_write_data_block(aw, block, size, offset);
if (r != ARCHIVE_OK) {
lafe_warnc(archive_errno(aw),
"%s", archive_error_string(aw));
@@ -1010,7 +1048,8 @@ mode_list(struct cpio *cpio)
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
- if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block))
+ if (archive_read_open_filename(a, cpio->filename,
+ cpio->bytes_per_block))
lafe_errc(1, archive_errno(a),
"%s", archive_error_string(a));
for (;;) {
@@ -1032,7 +1071,7 @@ mode_list(struct cpio *cpio)
if (r != ARCHIVE_OK)
lafe_errc(1, 0, "%s", archive_error_string(a));
if (!cpio->quiet) {
- int64_t blocks = (archive_position_uncompressed(a) + 511)
+ int64_t blocks = (archive_filter_bytes(a, 0) + 511)
/ 512;
fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
blocks == 1 ? "block" : "blocks");
@@ -1167,7 +1206,7 @@ mode_pass(struct cpio *cpio, const char *destdir)
if (!cpio->quiet) {
int64_t blocks =
- (archive_position_uncompressed(cpio->archive) + 511)
+ (archive_filter_bytes(cpio->archive, 0) + 511)
/ 512;
fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
blocks == 1 ? "block" : "blocks");