diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-06-20 11:48:00 +0400 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-06-20 11:48:00 +0400 |
commit | eb1c94078f35d1b6e48741122c8bb9426befc5eb (patch) | |
tree | 48535c1f250f98707e595cfb83f47c83332c4fc9 /archival/ar.c | |
parent | b4a26e6fc09e9dd14ca206f8d9ed2c6e8976df1b (diff) |
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
Diffstat (limited to 'archival/ar.c')
-rw-r--r-- | archival/ar.c | 42 |
1 files changed, 21 insertions, 21 deletions
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 <fcntl.h> #include <stdlib.h> +#include <string.h> #include <getopt.h> #include <unistd.h> #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,"!<arch>",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; } |