summaryrefslogtreecommitdiff
path: root/archival/cpio.c
diff options
context:
space:
mode:
authorGlenn L McGrath2002-11-03 14:05:15 +0000
committerGlenn L McGrath2002-11-03 14:05:15 +0000
commit237ae42fc96ede945d28d9054f045b73e419d089 (patch)
tree3fb6a9c10150303aca3c218b47aaf327a186382a /archival/cpio.c
parent2fc54a9258c3aa5dad2ce9807ba85cf29af2668e (diff)
downloadbusybox-237ae42fc96ede945d28d9054f045b73e419d089.zip
busybox-237ae42fc96ede945d28d9054f045b73e419d089.tar.gz
Abstract read and seek in unarchiving code, convert bunzip to file descriptors, support tar -j
Diffstat (limited to 'archival/cpio.c')
-rw-r--r--archival/cpio.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index 7615175..0d06149 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -45,6 +45,7 @@ extern int cpio_main(int argc, char **argv)
/* Initialise */
archive_handle = init_handle();
archive_handle->src_fd = fileno(stdin);
+ archive_handle->seek = seek_by_char;
archive_handle->action_header = header_list;
while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
@@ -69,6 +70,7 @@ extern int cpio_main(int argc, char **argv)
break;
case 'F':
archive_handle->src_fd = xopen(optarg, O_RDONLY);
+ archive_handle->seek = seek_by_jump;
break;
default:
show_usage();
@@ -117,9 +119,9 @@ extern int cpio_main(int argc, char **argv)
}
/* There can be padding before archive header */
- archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 4);
+ data_align(archive_handle, 4);
- if (xread_all_eof(archive_handle->src_fd, cpio_header, 110) == 0) {
+ if (archive_xread_all_eof(archive_handle, cpio_header, 110) == 0) {
return(EXIT_FAILURE);
}
archive_handle->offset += 110;
@@ -145,12 +147,12 @@ extern int cpio_main(int argc, char **argv)
dummy, &major, &minor, &namesize, dummy);
file_header->name = (char *) xmalloc(namesize + 1);
- xread(archive_handle->src_fd, file_header->name, namesize); /* Read in filename */
+ archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */
file_header->name[namesize] = '\0';
archive_handle->offset += namesize;
/* Update offset amount and skip padding before file contents */
- archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 4);
+ data_align(archive_handle, 4);
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
printf("%d blocks\n", (int) (archive_handle->offset % 512 ? (archive_handle->offset / 512) + 1 : archive_handle->offset / 512)); /* Always round up */
@@ -173,7 +175,7 @@ extern int cpio_main(int argc, char **argv)
if (S_ISLNK(file_header->mode)) {
file_header->link_name = (char *) xmalloc(file_header->size + 1);
- xread(archive_handle->src_fd, file_header->link_name, file_header->size);
+ archive_xread_all(archive_handle, file_header->link_name, file_header->size);
file_header->link_name[file_header->size] = '\0';
archive_handle->offset += file_header->size;
file_header->size = 0; /* Stop possible seeks in future */