aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-07-14 08:49:53 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-07-14 08:49:53 +0000
commit573b51bdf62e5dfa02b38ebb89059e2c7e1739fb (patch)
treefe1823623d327a9954d6c09e57c9d42f4fb575b1
parentc9d8d565e8c924528af3c682491f0b0963b5c2e0 (diff)
downloadbusybox-w32-573b51bdf62e5dfa02b38ebb89059e2c7e1739fb.tar.gz
busybox-w32-573b51bdf62e5dfa02b38ebb89059e2c7e1739fb.tar.bz2
busybox-w32-573b51bdf62e5dfa02b38ebb89059e2c7e1739fb.zip
Allow the unarchive() extract_list variable to be NULL, meaning extract all
git-svn-id: svn://busybox.net/trunk/busybox@3097 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--ar.c10
-rw-r--r--archival/ar.c10
-rw-r--r--archival/cpio.c15
-rw-r--r--cpio.c15
-rw-r--r--libbb/unarchive.c28
5 files changed, 40 insertions, 38 deletions
diff --git a/ar.c b/ar.c
index 2a764ff5e..7f3396c8c 100644
--- a/ar.c
+++ b/ar.c
@@ -70,17 +70,17 @@ extern int ar_main(int argc, char **argv)
70 70
71 /* check ar magic */ 71 /* check ar magic */
72 fread(ar_magic, 1, 8, src_stream); 72 fread(ar_magic, 1, 8, src_stream);
73 archive_offset = 8;
73 if (strncmp(ar_magic,"!<arch>",7) != 0) { 74 if (strncmp(ar_magic,"!<arch>",7) != 0) {
74 error_msg_and_die("invalid magic"); 75 error_msg_and_die("invalid magic");
75 } 76 }
76 archive_offset = 8;
77 77
78 extract_names = malloc(sizeof(char *)); 78 /* Create a list of files to extract */
79 extract_names[0] = NULL;
80 while (optind < argc) { 79 while (optind < argc) {
80 extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
81 extract_names[num_of_entries] = xstrdup(argv[optind]);
81 num_of_entries++; 82 num_of_entries++;
82 *extract_names = realloc(*extract_names, num_of_entries); 83 extract_names[num_of_entries] = NULL;
83 extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
84 optind++; 84 optind++;
85 } 85 }
86 86
diff --git a/archival/ar.c b/archival/ar.c
index 2a764ff5e..7f3396c8c 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -70,17 +70,17 @@ extern int ar_main(int argc, char **argv)
70 70
71 /* check ar magic */ 71 /* check ar magic */
72 fread(ar_magic, 1, 8, src_stream); 72 fread(ar_magic, 1, 8, src_stream);
73 archive_offset = 8;
73 if (strncmp(ar_magic,"!<arch>",7) != 0) { 74 if (strncmp(ar_magic,"!<arch>",7) != 0) {
74 error_msg_and_die("invalid magic"); 75 error_msg_and_die("invalid magic");
75 } 76 }
76 archive_offset = 8;
77 77
78 extract_names = malloc(sizeof(char *)); 78 /* Create a list of files to extract */
79 extract_names[0] = NULL;
80 while (optind < argc) { 79 while (optind < argc) {
80 extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
81 extract_names[num_of_entries] = xstrdup(argv[optind]);
81 num_of_entries++; 82 num_of_entries++;
82 *extract_names = realloc(*extract_names, num_of_entries); 83 extract_names[num_of_entries] = NULL;
83 extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
84 optind++; 84 optind++;
85 } 85 }
86 86
diff --git a/archival/cpio.c b/archival/cpio.c
index 12a4340bd..7f68715eb 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -68,25 +68,28 @@ extern int cpio_main(int argc, char **argv)
68 } 68 }
69 } 69 }
70 70
71 if (extract_function & extract_all_to_fs && extract_function & extract_list) { 71 if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
72 extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/ 72 extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
73 } 73 }
74 74
75 if (extract_function & extract_all_to_fs && extract_function & extract_verbose_list) { /* The meaning of v changes on extract */ 75 if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
76 /* The meaning of v changes on extract */
76 extract_function ^= extract_verbose_list; 77 extract_function ^= extract_verbose_list;
77 extract_function |= extract_list; 78 extract_function |= extract_list;
78 } 79 }
79 80
80 extract_names = malloc(4);
81 while (optind < argc) { 81 while (optind < argc) {
82 extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
83 extract_names[num_of_entries] = xstrdup(argv[optind]);
82 num_of_entries++; 84 num_of_entries++;
83 *extract_names = realloc(*extract_names, num_of_entries); 85 extract_names[num_of_entries] = NULL;
84 extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
85 optind++; 86 optind++;
86 } 87 }
87 88
88 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names); 89 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
89 if (oldmask) umask(oldmask); /* Restore umask if we changed it */ 90 if (oldmask) {
91 umask(oldmask); /* Restore umask if we changed it */
92 }
90 return EXIT_SUCCESS; 93 return EXIT_SUCCESS;
91} 94}
92 95
diff --git a/cpio.c b/cpio.c
index 12a4340bd..7f68715eb 100644
--- a/cpio.c
+++ b/cpio.c
@@ -68,25 +68,28 @@ extern int cpio_main(int argc, char **argv)
68 } 68 }
69 } 69 }
70 70
71 if (extract_function & extract_all_to_fs && extract_function & extract_list) { 71 if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
72 extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/ 72 extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
73 } 73 }
74 74
75 if (extract_function & extract_all_to_fs && extract_function & extract_verbose_list) { /* The meaning of v changes on extract */ 75 if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
76 /* The meaning of v changes on extract */
76 extract_function ^= extract_verbose_list; 77 extract_function ^= extract_verbose_list;
77 extract_function |= extract_list; 78 extract_function |= extract_list;
78 } 79 }
79 80
80 extract_names = malloc(4);
81 while (optind < argc) { 81 while (optind < argc) {
82 extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
83 extract_names[num_of_entries] = xstrdup(argv[optind]);
82 num_of_entries++; 84 num_of_entries++;
83 *extract_names = realloc(*extract_names, num_of_entries); 85 extract_names[num_of_entries] = NULL;
84 extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
85 optind++; 86 optind++;
86 } 87 }
87 88
88 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names); 89 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
89 if (oldmask) umask(oldmask); /* Restore umask if we changed it */ 90 if (oldmask) {
91 umask(oldmask); /* Restore umask if we changed it */
92 }
90 return EXIT_SUCCESS; 93 return EXIT_SUCCESS;
91} 94}
92 95
diff --git a/libbb/unarchive.c b/libbb/unarchive.c
index d10e60cbb..78260d2d6 100644
--- a/libbb/unarchive.c
+++ b/libbb/unarchive.c
@@ -232,25 +232,24 @@ char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers
232 int i; 232 int i;
233 char *buffer = NULL; 233 char *buffer = NULL;
234 234
235 if (extract_names == NULL) {
236 return(NULL);
237 }
238 archive_offset = 0; 235 archive_offset = 0;
239 while ((file_entry = get_headers(src_stream)) != NULL) { 236 while ((file_entry = get_headers(src_stream)) != NULL) {
240 found = FALSE; 237 found = FALSE;
241 if (extract_names[0] != NULL) { 238 if (extract_names == NULL) {
239 found = TRUE;
240 } else {
242 for(i = 0; extract_names[i] != 0; i++) { 241 for(i = 0; extract_names[i] != 0; i++) {
243 if (strcmp(extract_names[i], file_entry->name) == 0) { 242 if (strcmp(extract_names[i], file_entry->name) == 0) {
244 found = TRUE; 243 found = TRUE;
245 } 244 }
246 } 245 }
247 if (!found) {
248 /* seek past the data entry */
249 seek_sub_file(src_stream, file_entry->size);
250 continue;
251 }
252 } 246 }
253 buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix); 247 if (found) {
248 buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
249 } else {
250 /* seek past the data entry */
251 seek_sub_file(src_stream, file_entry->size);
252 }
254 } 253 }
255 return(buffer); 254 return(buffer);
256} 255}
@@ -544,17 +543,14 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
544 FILE *deb_stream; 543 FILE *deb_stream;
545 FILE *uncompressed_stream = NULL; 544 FILE *uncompressed_stream = NULL;
546 file_header_t *ar_header = NULL; 545 file_header_t *ar_header = NULL;
546 char **file_list = NULL;
547 char *output_buffer = NULL; 547 char *output_buffer = NULL;
548 char *ared_file = NULL; 548 char *ared_file = NULL;
549 char ar_magic[8]; 549 char ar_magic[8];
550 char **file_list;
551 int gunzip_pid; 550 int gunzip_pid;
552 551
553 if (filename == NULL) { 552 if (filename != NULL) {
554 file_list = xmalloc(sizeof(char *)); 553 file_list = xmalloc(sizeof(char *) * 2);
555 file_list[0] = NULL;
556 } else {
557 file_list = xmalloc(sizeof(char *) * 3);
558 file_list[0] = xstrdup(filename); 554 file_list[0] = xstrdup(filename);
559 file_list[1] = NULL; 555 file_list[1] = NULL;
560 } 556 }