From eb1c94078f35d1b6e48741122c8bb9426befc5eb Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Wed, 20 Jun 2001 07:48:00 +0000 Subject: Reorganise unarchiving functions, more code re-use, only does single pass(no more linked lists), basis for supporting a cpio (and cheaper untar) applet, but cpio applet isnt included in this. It effects ar, dpkg-deb applets only --- archival/ar.c | 42 +++++++++++++++++++++--------------------- archival/dpkg_deb.c | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'archival') diff --git a/archival/ar.c b/archival/ar.c index 7359f4910..fd98d86f5 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -24,6 +24,7 @@ */ #include #include +#include #include #include #include "busybox.h" @@ -31,9 +32,12 @@ extern int ar_main(int argc, char **argv) { FILE *src_stream = NULL; - int extract_function = 0, opt = 0; - file_headers_t *head; - file_headers_t *ar_extract_list = NULL; + char **extract_names = NULL; + char ar_magic[8]; + int extract_function = 0; + int opt; + int num_of_entries = 0; + extern off_t archive_offset; while ((opt = getopt(argc, argv, "ovtpx")) != -1) { switch (opt) { @@ -63,27 +67,23 @@ extern int ar_main(int argc, char **argv) } src_stream = xfopen(argv[optind++], "r"); - head = get_ar_headers(src_stream); - /* find files to extract or display */ - /* search through argv and build extract list */ - ar_extract_list = (file_headers_t *) xcalloc(1, sizeof(file_headers_t)); - if (optind < argc) { - while (optind < argc) { - ar_extract_list = add_from_archive_list(head, ar_extract_list, argv[optind]); - optind++; - } - } else { - ar_extract_list = head; + /* check ar magic */ + fread(ar_magic, 1, 8, src_stream); + if (strncmp(ar_magic,"!",7) != 0) { + error_msg_and_die("invalid magic"); } + archive_offset = 8; - /* If there isnt even one possible entry then abort */ - if (ar_extract_list->name == NULL) { - error_msg_and_die("No files to extract"); - } - - fseek(src_stream, 0, SEEK_SET); - extract_archive(src_stream, stdout, ar_extract_list, extract_function, "./"); + extract_names = malloc(sizeof(char *)); + extract_names[0] = NULL; + while (optind < argc) { + num_of_entries++; + *extract_names = realloc(*extract_names, num_of_entries); + extract_names[num_of_entries - 1] = xstrdup(argv[optind]); + optind++; + } + unarchive(src_stream, &get_header_ar, extract_function, "./", extract_names); return EXIT_SUCCESS; } diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 400f2385a..77172b0f6 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -26,7 +26,7 @@ extern int dpkg_deb_main(int argc, char **argv) char *output_buffer = NULL; int opt = 0; int arg_type = 0; - int deb_extract_funct = 0; + int deb_extract_funct = extract_create_dirs; const int arg_type_prefix = 1; const int arg_type_field = 2; -- cgit v1.2.3