diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-11 16:23:35 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-04-11 16:23:35 +0000 |
commit | 72c0e1ee41ad693a5ff11137579eb7c2a39f4e22 (patch) | |
tree | b292a499341d3c0314283e2822a93241a1c4e1dd /ar.c | |
parent | b4a1bdf087dcc1938cb93e5292512b7aa71fb569 (diff) | |
download | busybox-w32-72c0e1ee41ad693a5ff11137579eb7c2a39f4e22.tar.gz busybox-w32-72c0e1ee41ad693a5ff11137579eb7c2a39f4e22.tar.bz2 busybox-w32-72c0e1ee41ad693a5ff11137579eb7c2a39f4e22.zip |
copy_file_chunk uses streams now.
git-svn-id: svn://busybox.net/trunk/busybox@2315 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'ar.c')
-rw-r--r-- | ar.c | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -36,12 +36,13 @@ extern int ar_main(int argc, char **argv) | |||
36 | const int extract_to_file = 8; /* extract contents of archive */ | 36 | const int extract_to_file = 8; /* extract contents of archive */ |
37 | const int extract_to_stdout = 16; /* extract to stdout */ | 37 | const int extract_to_stdout = 16; /* extract to stdout */ |
38 | 38 | ||
39 | FILE *src_file = NULL, *dst_file = NULL; | ||
39 | int funct = 0, opt=0; | 40 | int funct = 0, opt=0; |
40 | int srcFd=0, dstFd=0; | ||
41 | 41 | ||
42 | ar_headers_t head, *extract_list=NULL; | 42 | ar_headers_t *head, *extract_list=NULL; |
43 | 43 | ||
44 | extract_list = (ar_headers_t *) xmalloc(sizeof(ar_headers_t)); | 44 | extract_list = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); |
45 | head = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); | ||
45 | 46 | ||
46 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { | 47 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { |
47 | switch (opt) { | 48 | switch (opt) { |
@@ -66,21 +67,22 @@ extern int ar_main(int argc, char **argv) | |||
66 | } | 67 | } |
67 | 68 | ||
68 | /* check the src filename was specified */ | 69 | /* check the src filename was specified */ |
69 | if (optind == argc) | 70 | if (optind == argc) { |
70 | show_usage(); | 71 | show_usage(); |
71 | 72 | } | |
72 | if ( (srcFd = open(argv[optind], O_RDONLY)) < 0) | 73 | |
74 | if ( (src_file = wfopen(argv[optind], "r")) < 0) { | ||
73 | error_msg_and_die("Cannot read %s", argv[optind]); | 75 | error_msg_and_die("Cannot read %s", argv[optind]); |
76 | } | ||
74 | 77 | ||
75 | optind++; | 78 | optind++; |
76 | head = get_ar_headers(srcFd); | 79 | head = get_ar_headers(src_file); |
77 | |||
78 | /* find files to extract or display */ | 80 | /* find files to extract or display */ |
79 | /* search through argv and build extract list */ | 81 | /* search through argv and build extract list */ |
80 | for (;optind<argc; optind++) { | 82 | for (;optind < argc; optind++) { |
81 | ar_headers_t *ar_entry; | 83 | ar_headers_t *ar_entry; |
82 | ar_entry = (ar_headers_t *) xmalloc(sizeof(ar_headers_t)); | 84 | ar_entry = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); |
83 | ar_entry = &head; | 85 | ar_entry = head; |
84 | while (ar_entry->next != NULL) { | 86 | while (ar_entry->next != NULL) { |
85 | if (strcmp(argv[optind], ar_entry->name) == 0) { | 87 | if (strcmp(argv[optind], ar_entry->name) == 0) { |
86 | ar_headers_t *tmp; | 88 | ar_headers_t *tmp; |
@@ -96,20 +98,20 @@ extern int ar_main(int argc, char **argv) | |||
96 | 98 | ||
97 | /* if individual files not found extract all files */ | 99 | /* if individual files not found extract all files */ |
98 | if (extract_list->next==NULL) { | 100 | if (extract_list->next==NULL) { |
99 | extract_list = &head; | 101 | extract_list = head; |
100 | } | 102 | } |
101 | 103 | ||
102 | /* find files to extract or display */ | 104 | /* find files to extract or display */ |
103 | while (extract_list->next != NULL) { | 105 | while (extract_list->next != NULL) { |
104 | if (funct & extract_to_file) { | 106 | if (funct & extract_to_file) { |
105 | dstFd = open(extract_list->name, O_WRONLY | O_CREAT, extract_list->mode); | 107 | dst_file = wfopen(extract_list->name, "w"); |
106 | } | 108 | } |
107 | else if (funct & extract_to_stdout) { | 109 | else if (funct & extract_to_stdout) { |
108 | dstFd = fileno(stdout); | 110 | dst_file = stdout; |
109 | } | 111 | } |
110 | if ((funct & extract_to_file) || (funct & extract_to_stdout)) { | 112 | if ((funct & extract_to_file) || (funct & extract_to_stdout)) { |
111 | lseek(srcFd, extract_list->offset, SEEK_SET); | 113 | fseek(src_file, extract_list->offset, SEEK_SET); |
112 | copy_file_chunk(srcFd, dstFd, (off_t) extract_list->size); | 114 | copy_file_chunk(src_file, dst_file, (off_t) extract_list->size); |
113 | } | 115 | } |
114 | if (funct & verbose) { | 116 | if (funct & verbose) { |
115 | printf("%s %d/%d %8d %s ", mode_string(extract_list->mode), | 117 | printf("%s %d/%d %8d %s ", mode_string(extract_list->mode), |