summaryrefslogtreecommitdiff
path: root/busybox/archival
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2005-07-18 23:51:27 +0000
committerEric Andersen <andersen@codepoet.org>2005-07-18 23:51:27 +0000
commit164a716f964bba247c660bc70149234f95146871 (patch)
tree95a8a6f75cb2ed1bb07cb6019088db7348ebf4d4 /busybox/archival
parent8c59a0bf0e9e2d87b0ff273ea3f0bf05bbbf6373 (diff)
downloadbusybox-w32-164a716f964bba247c660bc70149234f95146871.tar.gz
busybox-w32-164a716f964bba247c660bc70149234f95146871.tar.bz2
busybox-w32-164a716f964bba247c660bc70149234f95146871.zip
busybox-1.0.1-rc1.patch
http://busybox.net/lists/busybox/2005-July/014974.html
Diffstat (limited to 'busybox/archival')
-rw-r--r--busybox/archival/ar.c11
-rw-r--r--busybox/archival/dpkg.c2
-rw-r--r--busybox/archival/dpkg_deb.c2
-rw-r--r--busybox/archival/gzip.c47
-rw-r--r--busybox/archival/libunarchive/archive_xread_all_eof.c2
-rw-r--r--busybox/archival/libunarchive/decompress_bunzip2.c25
-rw-r--r--busybox/archival/libunarchive/decompress_unzip.c5
-rw-r--r--busybox/archival/tar.c2
8 files changed, 43 insertions, 53 deletions
diff --git a/busybox/archival/ar.c b/busybox/archival/ar.c
index 44c5db035..8326aa6de 100644
--- a/busybox/archival/ar.c
+++ b/busybox/archival/ar.c
@@ -56,19 +56,21 @@ static void header_verbose_list_ar(const file_header_t *file_header)
56#define AR_OPT_PRESERVE_DATE 0x08 56#define AR_OPT_PRESERVE_DATE 0x08
57#define AR_OPT_VERBOSE 0x10 57#define AR_OPT_VERBOSE 0x10
58#define AR_OPT_CREATE 0x20 58#define AR_OPT_CREATE 0x20
59#define AR_OPT_INSERT 0x40
59 60
60extern int ar_main(int argc, char **argv) 61extern int ar_main(int argc, char **argv)
61{ 62{
62 archive_handle_t *archive_handle; 63 archive_handle_t *archive_handle;
63 unsigned long opt; 64 unsigned long opt;
65 char *msg_unsupported_err = "Archive %s not supported. Install binutils 'ar'.";
64 char magic[8]; 66 char magic[8];
65 67
66 archive_handle = init_handle(); 68 archive_handle = init_handle();
67 69
68 bb_opt_complementaly = "p~tx:t~px:x~pt"; 70 bb_opt_complementaly = "p~tx:t~px:x~pt";
69 opt = bb_getopt_ulflags(argc, argv, "ptxovc"); 71 opt = bb_getopt_ulflags(argc, argv, "ptxovcr");
70 72
71 if ((opt & 0x80000000UL) || (optind == argc)) { 73 if ((opt & BB_GETOPT_ERROR) || (opt == 0) || (optind == argc)) {
72 bb_show_usage(); 74 bb_show_usage();
73 } 75 }
74 76
@@ -88,7 +90,10 @@ extern int ar_main(int argc, char **argv)
88 archive_handle->action_header = header_verbose_list_ar; 90 archive_handle->action_header = header_verbose_list_ar;
89 } 91 }
90 if (opt & AR_OPT_CREATE) { 92 if (opt & AR_OPT_CREATE) {
91 bb_error_msg_and_die("Archive creation not supported. Install binutils 'ar'."); 93 bb_error_msg_and_die(msg_unsupported_err, "creation");
94 }
95 if (opt & AR_OPT_INSERT) {
96 bb_error_msg_and_die(msg_unsupported_err, "insertion");
92 } 97 }
93 98
94 archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY); 99 archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
diff --git a/busybox/archival/dpkg.c b/busybox/archival/dpkg.c
index c096518a2..d3b56e398 100644
--- a/busybox/archival/dpkg.c
+++ b/busybox/archival/dpkg.c
@@ -1327,7 +1327,7 @@ void free_array(char **array)
1327 * the status_hashtable to retrieve the info. This results in smaller code than 1327 * the status_hashtable to retrieve the info. This results in smaller code than
1328 * scanning the status file. The resulting list, however, is unsorted. 1328 * scanning the status file. The resulting list, however, is unsorted.
1329 */ 1329 */
1330void list_packages(void) 1330static void list_packages(void)
1331{ 1331{
1332 int i; 1332 int i;
1333 1333
diff --git a/busybox/archival/dpkg_deb.c b/busybox/archival/dpkg_deb.c
index 5aa9881d5..b95ec2d6e 100644
--- a/busybox/archival/dpkg_deb.c
+++ b/busybox/archival/dpkg_deb.c
@@ -88,7 +88,7 @@ extern int dpkg_deb_main(int argc, char **argv)
88 argcount = 2; 88 argcount = 2;
89 } 89 }
90 90
91 if ((optind + argcount != argc) || (opt & 0x80000000UL)) { 91 if ((optind + argcount != argc) || (opt & BB_GETOPT_ERROR)) {
92 bb_show_usage(); 92 bb_show_usage();
93 } 93 }
94 94
diff --git a/busybox/archival/gzip.c b/busybox/archival/gzip.c
index d494aa30e..6cf4b395e 100644
--- a/busybox/archival/gzip.c
+++ b/busybox/archival/gzip.c
@@ -51,12 +51,6 @@
51#include <time.h> 51#include <time.h>
52#include "busybox.h" 52#include "busybox.h"
53 53
54#define memzero(s, n) memset ((void *)(s), 0, (n))
55
56#ifndef RETSIGTYPE
57# define RETSIGTYPE void
58#endif
59
60typedef unsigned char uch; 54typedef unsigned char uch;
61typedef unsigned short ush; 55typedef unsigned short ush;
62typedef unsigned long ulg; 56typedef unsigned long ulg;
@@ -214,9 +208,6 @@ typedef int file_t; /* Do not use stdio */
214static int zip(int in, int out); 208static int zip(int in, int out);
215static int file_read(char *buf, unsigned size); 209static int file_read(char *buf, unsigned size);
216 210
217 /* from gzip.c */
218static RETSIGTYPE abort_gzip(void);
219
220 /* from deflate.c */ 211 /* from deflate.c */
221static void lm_init(ush * flags); 212static void lm_init(ush * flags);
222static ulg deflate(void); 213static ulg deflate(void);
@@ -335,7 +326,7 @@ static void put_short(ush w)
335/* ======================================================================== 326/* ========================================================================
336 * Signal and error handler. 327 * Signal and error handler.
337 */ 328 */
338static void abort_gzip() 329static void abort_gzip(int ignored)
339{ 330{
340 exit(ERROR); 331 exit(ERROR);
341} 332}
@@ -350,13 +341,6 @@ static void clear_bufs(void)
350 bytes_in = 0L; 341 bytes_in = 0L;
351} 342}
352 343
353static void write_bb_error_msg(void)
354{
355 fputc('\n', stderr);
356 bb_perror_nomsg();
357 abort_gzip();
358}
359
360/* =========================================================================== 344/* ===========================================================================
361 * Does the same as write(), but also handles partial pipe writes and checks 345 * Does the same as write(), but also handles partial pipe writes and checks
362 * for error return. 346 * for error return.
@@ -366,9 +350,7 @@ static void write_buf(int fd, void *buf, unsigned cnt)
366 unsigned n; 350 unsigned n;
367 351
368 while ((n = write(fd, buf, cnt)) != cnt) { 352 while ((n = write(fd, buf, cnt)) != cnt) {
369 if (n == (unsigned) (-1)) { 353 if (n == (unsigned) (-1)) bb_error_msg_and_die("can't write");
370 write_bb_error_msg();
371 }
372 cnt -= n; 354 cnt -= n;
373 buf = (void *) ((char *) buf + n); 355 buf = (void *) ((char *) buf + n);
374 } 356 }
@@ -559,7 +541,7 @@ static unsigned bi_reverse(unsigned code, int len)
559/* =========================================================================== 541/* ===========================================================================
560 * Write out any remaining bits in an incomplete byte. 542 * Write out any remaining bits in an incomplete byte.
561 */ 543 */
562static void bi_windup() 544static void bi_windup(void)
563{ 545{
564 if (bi_valid > 8) { 546 if (bi_valid > 8) {
565 put_short(bi_buf); 547 put_short(bi_buf);
@@ -846,7 +828,7 @@ static void lm_init(ush * flags)
846 register unsigned j; 828 register unsigned j;
847 829
848 /* Initialize the hash table. */ 830 /* Initialize the hash table. */
849 memzero((char *) head, HASH_SIZE * sizeof(*head)); 831 memset(head, 0, HASH_SIZE * sizeof(*head));
850 /* prev will be initialized on the fly */ 832 /* prev will be initialized on the fly */
851 833
852 *flags |= SLOW; 834 *flags |= SLOW;
@@ -996,7 +978,7 @@ static void check_match(IPos start, IPos match, int length)
996 * file reads are performed for at least two bytes (required for the 978 * file reads are performed for at least two bytes (required for the
997 * translate_eol option). 979 * translate_eol option).
998 */ 980 */
999static void fill_window() 981static void fill_window(void)
1000{ 982{
1001 register unsigned n, m; 983 register unsigned n, m;
1002 unsigned more = 984 unsigned more =
@@ -1060,7 +1042,7 @@ static void fill_window()
1060 * evaluation for matches: a match is finally adopted only if there is 1042 * evaluation for matches: a match is finally adopted only if there is
1061 * no better match at the next window position. 1043 * no better match at the next window position.
1062 */ 1044 */
1063static ulg deflate() 1045static ulg deflate(void)
1064{ 1046{
1065 IPos hash_head; /* head of hash chain */ 1047 IPos hash_head; /* head of hash chain */
1066 IPos prev_match; /* previous match */ 1048 IPos prev_match; /* previous match */
@@ -1188,8 +1170,6 @@ static ulg deflate()
1188 1170
1189typedef struct dirent dir_type; 1171typedef struct dirent dir_type;
1190 1172
1191typedef RETSIGTYPE(*sig_type) (int);
1192
1193/* ======================================================================== */ 1173/* ======================================================================== */
1194int gzip_main(int argc, char **argv) 1174int gzip_main(int argc, char **argv)
1195{ 1175{
@@ -1235,16 +1215,16 @@ int gzip_main(int argc, char **argv)
1235 1215
1236 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; 1216 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
1237 if (foreground) { 1217 if (foreground) {
1238 (void) signal(SIGINT, (sig_type) abort_gzip); 1218 (void) signal(SIGINT, abort_gzip);
1239 } 1219 }
1240#ifdef SIGTERM 1220#ifdef SIGTERM
1241 if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { 1221 if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
1242 (void) signal(SIGTERM, (sig_type) abort_gzip); 1222 (void) signal(SIGTERM, abort_gzip);
1243 } 1223 }
1244#endif 1224#endif
1245#ifdef SIGHUP 1225#ifdef SIGHUP
1246 if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { 1226 if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
1247 (void) signal(SIGHUP, (sig_type) abort_gzip); 1227 (void) signal(SIGHUP, abort_gzip);
1248 } 1228 }
1249#endif 1229#endif
1250 1230
@@ -1271,6 +1251,7 @@ int gzip_main(int argc, char **argv)
1271 for (i = optind; i < argc; i++) { 1251 for (i = optind; i < argc; i++) {
1272 char *path = NULL; 1252 char *path = NULL;
1273 1253
1254 clear_bufs();
1274 if (strcmp(argv[i], "-") == 0) { 1255 if (strcmp(argv[i], "-") == 0) {
1275 time_stamp = 0; 1256 time_stamp = 0;
1276 ifile_size = -1L; 1257 ifile_size = -1L;
@@ -1749,7 +1730,7 @@ static void ct_init(ush * attr, int *methodp)
1749/* =========================================================================== 1730/* ===========================================================================
1750 * Initialize a new block. 1731 * Initialize a new block.
1751 */ 1732 */
1752static void init_block() 1733static void init_block(void)
1753{ 1734{
1754 int n; /* iterates over tree elements */ 1735 int n; /* iterates over tree elements */
1755 1736
@@ -2162,7 +2143,7 @@ static void send_tree(ct_data * tree, int max_code)
2162 * Construct the Huffman tree for the bit lengths and return the index in 2143 * Construct the Huffman tree for the bit lengths and return the index in
2163 * bl_order of the last bit length code to send. 2144 * bl_order of the last bit length code to send.
2164 */ 2145 */
2165static const int build_bl_tree() 2146static int build_bl_tree(void)
2166{ 2147{
2167 int max_blindex; /* index of last bit length code of non zero freq */ 2148 int max_blindex; /* index of last bit length code of non zero freq */
2168 2149
@@ -2425,7 +2406,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
2425 * IN assertion: the fields freq of dyn_ltree are set and the total of all 2406 * IN assertion: the fields freq of dyn_ltree are set and the total of all
2426 * frequencies does not exceed 64K (to fit in an int on 16 bit machines). 2407 * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
2427 */ 2408 */
2428static void set_file_type() 2409static void set_file_type(void)
2429{ 2410{
2430 int n = 0; 2411 int n = 0;
2431 unsigned ascii_freq = 0; 2412 unsigned ascii_freq = 0;
@@ -2538,7 +2519,7 @@ static int file_read(char *buf, unsigned size)
2538 * Write the output buffer outbuf[0..outcnt-1] and update bytes_out. 2519 * Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
2539 * (used for the compressed data only) 2520 * (used for the compressed data only)
2540 */ 2521 */
2541static void flush_outbuf() 2522static void flush_outbuf(void)
2542{ 2523{
2543 if (outcnt == 0) 2524 if (outcnt == 0)
2544 return; 2525 return;
diff --git a/busybox/archival/libunarchive/archive_xread_all_eof.c b/busybox/archival/libunarchive/archive_xread_all_eof.c
index 8084e3524..f1eea2928 100644
--- a/busybox/archival/libunarchive/archive_xread_all_eof.c
+++ b/busybox/archival/libunarchive/archive_xread_all_eof.c
@@ -26,7 +26,7 @@ extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned
26 26
27 size = bb_full_read(archive_handle->src_fd, buf, count); 27 size = bb_full_read(archive_handle->src_fd, buf, count);
28 if ((size != 0) && (size != count)) { 28 if ((size != 0) && (size != count)) {
29 bb_perror_msg_and_die("Short read, read %d of %d", size, count); 29 bb_perror_msg_and_die("Short read, read %ld of %ld", (long)size, (long)count);
30 } 30 }
31 return(size); 31 return(size);
32} 32}
diff --git a/busybox/archival/libunarchive/decompress_bunzip2.c b/busybox/archival/libunarchive/decompress_bunzip2.c
index 259a47776..07e3cf018 100644
--- a/busybox/archival/libunarchive/decompress_bunzip2.c
+++ b/busybox/archival/libunarchive/decompress_bunzip2.c
@@ -134,8 +134,6 @@ static unsigned int get_bits(bunzip_data *bd, char bits_wanted)
134 134
135static int get_next_block(bunzip_data *bd) 135static int get_next_block(bunzip_data *bd)
136{ 136{
137 /* Note: Ignore the warning about hufGroup, base and limit being used uninitialized.
138 * They will be initialized on the fist pass of the loop. */
139 struct group_data *hufGroup; 137 struct group_data *hufGroup;
140 int dbufCount,nextSym,dbufSize,groupCount,*base,*limit,selector, 138 int dbufCount,nextSym,dbufSize,groupCount,*base,*limit,selector,
141 i,j,k,t,runPos,symCount,symTotal,nSelectors,byteCount[256]; 139 i,j,k,t,runPos,symCount,symTotal,nSelectors,byteCount[256];
@@ -286,16 +284,15 @@ static int get_next_block(bunzip_data *bd)
286 mtfSymbol[i]=(unsigned char)i; 284 mtfSymbol[i]=(unsigned char)i;
287 } 285 }
288 /* Loop through compressed symbols. */ 286 /* Loop through compressed symbols. */
289 runPos=dbufCount=symCount=selector=0; 287 runPos=dbufCount=selector=0;
290 for(;;) { 288 for(;;) {
291 /* Determine which Huffman coding group to use. */ 289 /* fetch next Huffman coding group from list. */
292 if(!(symCount--)) { 290 symCount=GROUP_SIZE-1;
293 symCount=GROUP_SIZE-1; 291 if(selector>=nSelectors) return RETVAL_DATA_ERROR;
294 if(selector>=nSelectors) return RETVAL_DATA_ERROR; 292 hufGroup=bd->groups+selectors[selector++];
295 hufGroup=bd->groups+selectors[selector++]; 293 base=hufGroup->base-1;
296 base=hufGroup->base-1; 294 limit=hufGroup->limit-1;
297 limit=hufGroup->limit-1; 295continue_this_group:
298 }
299 /* Read next Huffman-coded symbol. */ 296 /* Read next Huffman-coded symbol. */
300 /* Note: It is far cheaper to read maxLen bits and back up than it is 297 /* Note: It is far cheaper to read maxLen bits and back up than it is
301 to read minLen bits and then an additional bit at a time, testing 298 to read minLen bits and then an additional bit at a time, testing
@@ -346,7 +343,7 @@ got_huff_bits:
346 context). Thus space is saved. */ 343 context). Thus space is saved. */
347 t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */ 344 t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
348 runPos <<= 1; 345 runPos <<= 1;
349 continue; 346 goto end_of_huffman_loop;
350 } 347 }
351 /* When we hit the first non-run symbol after a run, we now know 348 /* When we hit the first non-run symbol after a run, we now know
352 how many times to repeat the last literal, so append that many 349 how many times to repeat the last literal, so append that many
@@ -384,6 +381,10 @@ got_huff_bits:
384 /* We have our literal byte. Save it into dbuf. */ 381 /* We have our literal byte. Save it into dbuf. */
385 byteCount[uc]++; 382 byteCount[uc]++;
386 dbuf[dbufCount++] = (unsigned int)uc; 383 dbuf[dbufCount++] = (unsigned int)uc;
384 /* Skip group initialization if we're not done with this group. Done this
385 * way to avoid compiler warning. */
386end_of_huffman_loop:
387 if(symCount--) goto continue_this_group;
387 } 388 }
388 /* At this point, we've read all the Huffman-coded symbols (and repeated 389 /* At this point, we've read all the Huffman-coded symbols (and repeated
389 runs) for this block from the input stream, and decoded them into the 390 runs) for this block from the input stream, and decoded them into the
diff --git a/busybox/archival/libunarchive/decompress_unzip.c b/busybox/archival/libunarchive/decompress_unzip.c
index e8cf54bff..b17065d92 100644
--- a/busybox/archival/libunarchive/decompress_unzip.c
+++ b/busybox/archival/libunarchive/decompress_unzip.c
@@ -151,7 +151,10 @@ static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current
151 /* Leave the first 4 bytes empty so we can always unwind the bitbuffer 151 /* Leave the first 4 bytes empty so we can always unwind the bitbuffer
152 * to the front of the bytebuffer, leave 4 bytes free at end of tail 152 * to the front of the bytebuffer, leave 4 bytes free at end of tail
153 * so we can easily top up buffer in check_trailer_gzip() */ 153 * so we can easily top up buffer in check_trailer_gzip() */
154 bytebuffer_size = 4 + bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8); 154 if (!(bytebuffer_size = bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8))) {
155 bb_error_msg_and_die("unexpected end of file");
156 }
157 bytebuffer_size += 4;
155 bytebuffer_offset = 4; 158 bytebuffer_offset = 4;
156 } 159 }
157 bitbuffer |= ((unsigned int) bytebuffer[bytebuffer_offset]) << *current; 160 bitbuffer |= ((unsigned int) bytebuffer[bytebuffer_offset]) << *current;
diff --git a/busybox/archival/tar.c b/busybox/archival/tar.c
index 950e21dd3..b2a212397 100644
--- a/busybox/archival/tar.c
+++ b/busybox/archival/tar.c
@@ -724,7 +724,7 @@ int tar_main(int argc, char **argv)
724 ); 724 );
725 725
726 /* Check one and only one context option was given */ 726 /* Check one and only one context option was given */
727 if(opt & 0x80000000UL) { 727 if(opt & BB_GETOPT_ERROR) {
728 bb_show_usage(); 728 bb_show_usage();
729 } 729 }
730#ifdef CONFIG_FEATURE_TAR_CREATE 730#ifdef CONFIG_FEATURE_TAR_CREATE