summaryrefslogtreecommitdiff
path: root/libbb/untar.c
diff options
context:
space:
mode:
authorGlenn L McGrath2001-04-12 10:19:08 +0000
committerGlenn L McGrath2001-04-12 10:19:08 +0000
commit359c1068719c295b25b2d8b81a6aded5aeb6e23d (patch)
tree680864ee0a5e6782c4fdfa9906ff902a44411524 /libbb/untar.c
parent46079a1d7792dc3848667ddc875bd2467be1ddc1 (diff)
downloadbusybox-359c1068719c295b25b2d8b81a6aded5aeb6e23d.zip
busybox-359c1068719c295b25b2d8b81a6aded5aeb6e23d.tar.gz
Fix dpkg-deb, enum's are cool
Diffstat (limited to 'libbb/untar.c')
-rw-r--r--libbb/untar.c71
1 files changed, 31 insertions, 40 deletions
diff --git a/libbb/untar.c b/libbb/untar.c
index 1542e39..cb312d5 100644
--- a/libbb/untar.c
+++ b/libbb/untar.c
@@ -44,13 +44,6 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
char padding[12]; /* 500-512 */
} raw_tar_header_t;
-// const int dpkg_deb_contents = 1;
-// const int dpkg_deb_control = 2;
-// const int dpkg_deb_info = 4;
- const int untar_extract = 8;
-// const int dpkg_deb_verbose_extract = 16;
-// const int dpkg_deb_list = 32;
-
raw_tar_header_t raw_tar_header;
unsigned char *temp = (unsigned char *) &raw_tar_header;
long i;
@@ -61,7 +54,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
// signal(SIGCHLD, child_died);
- while (fread((char *) &raw_tar_header, 1, 512, src_tar_file)==512) {
+ while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) {
long sum = 0;
char *dir;
@@ -130,30 +123,41 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
* supposed to be a directory, and fall through
*/
if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') {
- if (untar_function & untar_extract) {
- int out_count=0;
- FILE *dst_file;
-
- dst_file = wfopen(dir, "w");
- if (copy_file_chunk(src_tar_file, dst_file, size) == FALSE) {
- error_msg_and_die("Couldnt extract file");
- }
- uncompressed_count += out_count;
- fclose(dst_file);
- break;
+ switch (untar_function) {
+ case (extract_verbose_extract):
+ printf("%s\n", raw_tar_header.name);
+ case (extract_extract): {
+ FILE *dst_file = wfopen(dir, "w");
+ copy_file_chunk(src_tar_file, dst_file, size);
+ fclose(dst_file);
+ }
+ break;
+ default: {
+ int remaining = size;
+ while (remaining-- > 0) {
+ fgetc(src_tar_file);
+ }
+ }
}
+ uncompressed_count += size;
+ break;
}
case '5':
- if (untar_function & untar_extract) {
- if (create_path(dir, mode) != TRUE) {
- free(dir);
- perror_msg("%s: Cannot mkdir", raw_tar_header.name);
- return(EXIT_FAILURE);
- }
+ switch (untar_function) {
+ case (extract_verbose_extract):
+ printf("%s\n", raw_tar_header.name);
+ case (extract_extract):
+ if (create_path(dir, mode) != TRUE) {
+ free(dir);
+ perror_msg("%s: Cannot mkdir", raw_tar_header.name);
+ return(EXIT_FAILURE);
+ }
+ break;
+ default:
}
break;
case '1':
- if (untar_function & untar_extract) {
+ if (untar_function & extract_extract) {
if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) {
free(dir);
perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname);
@@ -162,7 +166,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
}
break;
case '2':
- if (untar_function & untar_extract) {
+ if (untar_function & extract_extract) {
if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) {
free(dir);
perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname);
@@ -183,18 +187,5 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
}
free(dir);
}
- /* skip to start of next header */
- while(uncompressed_count < next_header_offset) {
- char ch[2];
- if (fread(ch, 1, 1, src_tar_file) != 1) {
- error_msg("read error\n");
- getchar();
- } else {
- uncompressed_count++;
- }
- }
- /*
- * TODO: Check that gunzip child hasnt finished
- */
return(EXIT_SUCCESS);
}