summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorGlenn L McGrath2001-07-14 08:49:53 +0000
committerGlenn L McGrath2001-07-14 08:49:53 +0000
commita868ec89e8272c0cdf27e062785c4b5c6dcf66c5 (patch)
treefe1823623d327a9954d6c09e57c9d42f4fb575b1 /archival
parent58a5bd187dd69ed9ba761e8ea755fd9ff4e97ce6 (diff)
downloadbusybox-a868ec89e8272c0cdf27e062785c4b5c6dcf66c5.zip
busybox-a868ec89e8272c0cdf27e062785c4b5c6dcf66c5.tar.gz
Allow the unarchive() extract_list variable to be NULL, meaning extract all
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c10
-rw-r--r--archival/cpio.c15
2 files changed, 14 insertions, 11 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 2a764ff..7f3396c 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -70,17 +70,17 @@ extern int ar_main(int argc, char **argv)
/* check ar magic */
fread(ar_magic, 1, 8, src_stream);
+ archive_offset = 8;
if (strncmp(ar_magic,"!<arch>",7) != 0) {
error_msg_and_die("invalid magic");
}
- archive_offset = 8;
- extract_names = malloc(sizeof(char *));
- extract_names[0] = NULL;
+ /* Create a list of files to extract */
while (optind < argc) {
+ extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
+ extract_names[num_of_entries] = xstrdup(argv[optind]);
num_of_entries++;
- *extract_names = realloc(*extract_names, num_of_entries);
- extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
+ extract_names[num_of_entries] = NULL;
optind++;
}
diff --git a/archival/cpio.c b/archival/cpio.c
index 12a4340..7f68715 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -68,25 +68,28 @@ extern int cpio_main(int argc, char **argv)
}
}
- if (extract_function & extract_all_to_fs && extract_function & extract_list) {
+ if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
}
- if (extract_function & extract_all_to_fs && extract_function & extract_verbose_list) { /* The meaning of v changes on extract */
+ if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
+ /* The meaning of v changes on extract */
extract_function ^= extract_verbose_list;
extract_function |= extract_list;
}
- extract_names = malloc(4);
while (optind < argc) {
+ extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
+ extract_names[num_of_entries] = xstrdup(argv[optind]);
num_of_entries++;
- *extract_names = realloc(*extract_names, num_of_entries);
- extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
+ extract_names[num_of_entries] = NULL;
optind++;
}
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
- if (oldmask) umask(oldmask); /* Restore umask if we changed it */
+ if (oldmask) {
+ umask(oldmask); /* Restore umask if we changed it */
+ }
return EXIT_SUCCESS;
}