diff options
Diffstat (limited to 'ar.c')
-rw-r--r-- | ar.c | 42 |
1 files changed, 21 insertions, 21 deletions
@@ -24,6 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | #include <fcntl.h> | 25 | #include <fcntl.h> |
26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
27 | #include <string.h> | ||
27 | #include <getopt.h> | 28 | #include <getopt.h> |
28 | #include <unistd.h> | 29 | #include <unistd.h> |
29 | #include "busybox.h" | 30 | #include "busybox.h" |
@@ -31,9 +32,12 @@ | |||
31 | extern int ar_main(int argc, char **argv) | 32 | extern int ar_main(int argc, char **argv) |
32 | { | 33 | { |
33 | FILE *src_stream = NULL; | 34 | FILE *src_stream = NULL; |
34 | int extract_function = 0, opt = 0; | 35 | char **extract_names = NULL; |
35 | file_headers_t *head; | 36 | char ar_magic[8]; |
36 | file_headers_t *ar_extract_list = NULL; | 37 | int extract_function = 0; |
38 | int opt; | ||
39 | int num_of_entries = 0; | ||
40 | extern off_t archive_offset; | ||
37 | 41 | ||
38 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { | 42 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { |
39 | switch (opt) { | 43 | switch (opt) { |
@@ -63,27 +67,23 @@ extern int ar_main(int argc, char **argv) | |||
63 | } | 67 | } |
64 | 68 | ||
65 | src_stream = xfopen(argv[optind++], "r"); | 69 | src_stream = xfopen(argv[optind++], "r"); |
66 | head = get_ar_headers(src_stream); | ||
67 | 70 | ||
68 | /* find files to extract or display */ | 71 | /* check ar magic */ |
69 | /* search through argv and build extract list */ | 72 | fread(ar_magic, 1, 8, src_stream); |
70 | ar_extract_list = (file_headers_t *) xcalloc(1, sizeof(file_headers_t)); | 73 | if (strncmp(ar_magic,"!<arch>",7) != 0) { |
71 | if (optind < argc) { | 74 | error_msg_and_die("invalid magic"); |
72 | while (optind < argc) { | ||
73 | ar_extract_list = add_from_archive_list(head, ar_extract_list, argv[optind]); | ||
74 | optind++; | ||
75 | } | ||
76 | } else { | ||
77 | ar_extract_list = head; | ||
78 | } | 75 | } |
76 | archive_offset = 8; | ||
79 | 77 | ||
80 | /* If there isnt even one possible entry then abort */ | 78 | extract_names = malloc(sizeof(char *)); |
81 | if (ar_extract_list->name == NULL) { | 79 | extract_names[0] = NULL; |
82 | error_msg_and_die("No files to extract"); | 80 | while (optind < argc) { |
83 | } | 81 | num_of_entries++; |
84 | 82 | *extract_names = realloc(*extract_names, num_of_entries); | |
85 | fseek(src_stream, 0, SEEK_SET); | 83 | extract_names[num_of_entries - 1] = xstrdup(argv[optind]); |
86 | extract_archive(src_stream, stdout, ar_extract_list, extract_function, "./"); | 84 | optind++; |
85 | } | ||
87 | 86 | ||
87 | unarchive(src_stream, &get_header_ar, extract_function, "./", extract_names); | ||
88 | return EXIT_SUCCESS; | 88 | return EXIT_SUCCESS; |
89 | } | 89 | } |