diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-01 15:55:11 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-01 15:55:11 +0000 |
commit | 97a8dd3857aea9730382e2975a2ee2000fd23ebb (patch) | |
tree | 608f73898f3ed5f466dff68189625fa9328a15be /archival/libunarchive | |
parent | f8aa109a9f7c67b291f240fb3ed91da90f26359b (diff) | |
download | busybox-w32-97a8dd3857aea9730382e2975a2ee2000fd23ebb.tar.gz busybox-w32-97a8dd3857aea9730382e2975a2ee2000fd23ebb.tar.bz2 busybox-w32-97a8dd3857aea9730382e2975a2ee2000fd23ebb.zip |
g[un]zip: add support for -v (verbose).
Add CONFIG_DESKTOP, almost all bloat from this change
is hidden under that.
Diffstat (limited to 'archival/libunarchive')
-rw-r--r-- | archival/libunarchive/decompress_bunzip2.c | 22 | ||||
-rw-r--r-- | archival/libunarchive/decompress_uncompress.c | 18 | ||||
-rw-r--r-- | archival/libunarchive/decompress_unlzma.c | 16 | ||||
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 15 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar_gz.c | 2 | ||||
-rw-r--r-- | archival/libunarchive/open_transformer.c | 6 |
6 files changed, 51 insertions, 28 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c index 657d4ab01..d0a4ecb5e 100644 --- a/archival/libunarchive/decompress_bunzip2.c +++ b/archival/libunarchive/decompress_bunzip2.c | |||
@@ -671,20 +671,24 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf, | |||
671 | /* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data, | 671 | /* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data, |
672 | not end of file.) */ | 672 | not end of file.) */ |
673 | 673 | ||
674 | int uncompressStream(int src_fd, int dst_fd) | 674 | USE_DESKTOP(long long) int |
675 | uncompressStream(int src_fd, int dst_fd) | ||
675 | { | 676 | { |
677 | USE_DESKTOP(long long total_written = 0;) | ||
676 | char *outbuf; | 678 | char *outbuf; |
677 | bunzip_data *bd; | 679 | bunzip_data *bd; |
678 | int i; | 680 | int i; |
679 | 681 | ||
680 | outbuf=xmalloc(IOBUF_SIZE); | 682 | outbuf=xmalloc(IOBUF_SIZE); |
681 | if(!(i=start_bunzip(&bd,src_fd,0,0))) { | 683 | i=start_bunzip(&bd,src_fd,0,0); |
684 | if(!i) { | ||
682 | for(;;) { | 685 | for(;;) { |
683 | if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break; | 686 | if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break; |
684 | if(i!=write(dst_fd,outbuf,i)) { | 687 | if(i!=write(dst_fd,outbuf,i)) { |
685 | i=RETVAL_UNEXPECTED_OUTPUT_EOF; | 688 | i=RETVAL_UNEXPECTED_OUTPUT_EOF; |
686 | break; | 689 | break; |
687 | } | 690 | } |
691 | USE_DESKTOP(total_written += i;) | ||
688 | } | 692 | } |
689 | } | 693 | } |
690 | 694 | ||
@@ -692,27 +696,27 @@ int uncompressStream(int src_fd, int dst_fd) | |||
692 | 696 | ||
693 | if(i==RETVAL_LAST_BLOCK) { | 697 | if(i==RETVAL_LAST_BLOCK) { |
694 | if (bd->headerCRC!=bd->totalCRC) { | 698 | if (bd->headerCRC!=bd->totalCRC) { |
695 | bb_error_msg("Data integrity error when decompressing."); | 699 | bb_error_msg("data integrity error when decompressing"); |
696 | } else { | 700 | } else { |
697 | i=RETVAL_OK; | 701 | i=RETVAL_OK; |
698 | } | 702 | } |
699 | } else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) { | 703 | } else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) { |
700 | bb_error_msg("Compressed file ends unexpectedly"); | 704 | bb_error_msg("compressed file ends unexpectedly"); |
701 | } else { | 705 | } else { |
702 | bb_error_msg("Decompression failed"); | 706 | bb_error_msg("decompression failed"); |
703 | } | 707 | } |
704 | free(bd->dbuf); | 708 | free(bd->dbuf); |
705 | free(bd); | 709 | free(bd); |
706 | free(outbuf); | 710 | free(outbuf); |
707 | 711 | ||
708 | return i; | 712 | return i ? i : USE_DESKTOP(total_written) + 0; |
709 | } | 713 | } |
710 | 714 | ||
711 | #ifdef TESTING | 715 | #ifdef TESTING |
712 | 716 | ||
713 | static char * const bunzip_errors[]={NULL,"Bad file checksum","Not bzip data", | 717 | static char * const bunzip_errors[]={NULL,"Bad file checksum","Not bzip data", |
714 | "Unexpected input EOF","Unexpected output EOF","Data error", | 718 | "Unexpected input EOF","Unexpected output EOF","Data error", |
715 | "Out of memory","Obsolete (pre 0.9.5) bzip format not supported."}; | 719 | "Out of memory","Obsolete (pre 0.9.5) bzip format not supported."}; |
716 | 720 | ||
717 | /* Dumb little test thing, decompress stdin to stdout */ | 721 | /* Dumb little test thing, decompress stdin to stdout */ |
718 | int main(int argc, char *argv[]) | 722 | int main(int argc, char *argv[]) |
@@ -720,8 +724,8 @@ int main(int argc, char *argv[]) | |||
720 | int i=uncompressStream(0,1); | 724 | int i=uncompressStream(0,1); |
721 | char c; | 725 | char c; |
722 | 726 | ||
723 | if(i) fprintf(stderr,"%s\n", bunzip_errors[-i]); | 727 | if(i<0) fprintf(stderr,"%s\n", bunzip_errors[-i]); |
724 | else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n"); | 728 | else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n"); |
725 | return -i; | 729 | return -i; |
726 | } | 730 | } |
727 | #endif | 731 | #endif |
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c index e2941438c..ff98254ff 100644 --- a/archival/libunarchive/decompress_uncompress.c +++ b/archival/libunarchive/decompress_uncompress.c | |||
@@ -86,8 +86,10 @@ static int maxbits = BITS; | |||
86 | * with those of the compress() routine. See the definitions above. | 86 | * with those of the compress() routine. See the definitions above. |
87 | */ | 87 | */ |
88 | 88 | ||
89 | int uncompress(int fd_in, int fd_out) | 89 | USE_DESKTOP(long long) int |
90 | uncompress(int fd_in, int fd_out) | ||
90 | { | 91 | { |
92 | USE_DESKTOP(long long total_written = 0;) | ||
91 | unsigned char *stackp; | 93 | unsigned char *stackp; |
92 | long int code; | 94 | long int code; |
93 | int finchar; | 95 | int finchar; |
@@ -182,16 +184,16 @@ int uncompress(int fd_in, int fd_out) | |||
182 | { | 184 | { |
183 | unsigned char *p = &inbuf[posbits >> 3]; | 185 | unsigned char *p = &inbuf[posbits >> 3]; |
184 | 186 | ||
185 | code = | 187 | code = ((((long) (p[0])) | ((long) (p[1]) << 8) | |
186 | ((((long) (p[0])) | ((long) (p[1]) << 8) | | 188 | ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; |
187 | ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; | ||
188 | } | 189 | } |
189 | posbits += n_bits; | 190 | posbits += n_bits; |
190 | 191 | ||
191 | 192 | ||
192 | if (oldcode == -1) { | 193 | if (oldcode == -1) { |
193 | outbuf[outpos++] = (unsigned char) (finchar = | 194 | oldcode = code; |
194 | (int) (oldcode = code)); | 195 | finchar = (int) oldcode; |
196 | outbuf[outpos++] = (unsigned char) finchar; | ||
195 | continue; | 197 | continue; |
196 | } | 198 | } |
197 | 199 | ||
@@ -255,6 +257,7 @@ int uncompress(int fd_in, int fd_out) | |||
255 | 257 | ||
256 | if (outpos >= OBUFSIZ) { | 258 | if (outpos >= OBUFSIZ) { |
257 | write(fd_out, outbuf, outpos); | 259 | write(fd_out, outbuf, outpos); |
260 | USE_DESKTOP(total_written += outpos;) | ||
258 | outpos = 0; | 261 | outpos = 0; |
259 | } | 262 | } |
260 | stackp += i; | 263 | stackp += i; |
@@ -280,9 +283,10 @@ int uncompress(int fd_in, int fd_out) | |||
280 | 283 | ||
281 | if (outpos > 0) { | 284 | if (outpos > 0) { |
282 | write(fd_out, outbuf, outpos); | 285 | write(fd_out, outbuf, outpos); |
286 | USE_DESKTOP(total_written += outpos;) | ||
283 | } | 287 | } |
284 | 288 | ||
285 | RELEASE_CONFIG_BUFFER(inbuf); | 289 | RELEASE_CONFIG_BUFFER(inbuf); |
286 | RELEASE_CONFIG_BUFFER(outbuf); | 290 | RELEASE_CONFIG_BUFFER(outbuf); |
287 | return 0; | 291 | return USE_DESKTOP(total_written) + 0; |
288 | } | 292 | } |
diff --git a/archival/libunarchive/decompress_unlzma.c b/archival/libunarchive/decompress_unlzma.c index 0fb1249cb..a6902807b 100644 --- a/archival/libunarchive/decompress_unlzma.c +++ b/archival/libunarchive/decompress_unlzma.c | |||
@@ -211,9 +211,10 @@ typedef struct { | |||
211 | #define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS) | 211 | #define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS) |
212 | #define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS) | 212 | #define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS) |
213 | 213 | ||
214 | 214 | USE_DESKTOP(long long) int | |
215 | int unlzma(int src_fd, int dst_fd) | 215 | unlzma(int src_fd, int dst_fd) |
216 | { | 216 | { |
217 | USE_DESKTOP(long long total_written = 0;) | ||
217 | lzma_header_t header; | 218 | lzma_header_t header; |
218 | int lc, pb, lp; | 219 | int lc, pb, lp; |
219 | uint32_t pos_state_mask; | 220 | uint32_t pos_state_mask; |
@@ -305,7 +306,9 @@ int unlzma(int src_fd, int dst_fd) | |||
305 | if (buffer_pos == header.dict_size) { | 306 | if (buffer_pos == header.dict_size) { |
306 | buffer_pos = 0; | 307 | buffer_pos = 0; |
307 | global_pos += header.dict_size; | 308 | global_pos += header.dict_size; |
309 | // FIXME: error check | ||
308 | write(dst_fd, buffer, header.dict_size); | 310 | write(dst_fd, buffer, header.dict_size); |
311 | USE_DESKTOP(total_written += header.dict_size;) | ||
309 | } | 312 | } |
310 | if (state < 4) | 313 | if (state < 4) |
311 | state = 0; | 314 | state = 0; |
@@ -345,7 +348,9 @@ int unlzma(int src_fd, int dst_fd) | |||
345 | if (buffer_pos == header.dict_size) { | 348 | if (buffer_pos == header.dict_size) { |
346 | buffer_pos = 0; | 349 | buffer_pos = 0; |
347 | global_pos += header.dict_size; | 350 | global_pos += header.dict_size; |
351 | // FIXME: error check | ||
348 | write(dst_fd, buffer, header.dict_size); | 352 | write(dst_fd, buffer, header.dict_size); |
353 | USE_DESKTOP(total_written += header.dict_size;) | ||
349 | } | 354 | } |
350 | continue; | 355 | continue; |
351 | } else { | 356 | } else { |
@@ -456,15 +461,18 @@ int unlzma(int src_fd, int dst_fd) | |||
456 | if (buffer_pos == header.dict_size) { | 461 | if (buffer_pos == header.dict_size) { |
457 | buffer_pos = 0; | 462 | buffer_pos = 0; |
458 | global_pos += header.dict_size; | 463 | global_pos += header.dict_size; |
464 | // FIXME: error check | ||
459 | write(dst_fd, buffer, header.dict_size); | 465 | write(dst_fd, buffer, header.dict_size); |
466 | USE_DESKTOP(total_written += header.dict_size;) | ||
460 | } | 467 | } |
461 | len--; | 468 | len--; |
462 | } while (len != 0 && buffer_pos < header.dst_size); | 469 | } while (len != 0 && buffer_pos < header.dst_size); |
463 | } | 470 | } |
464 | } | 471 | } |
465 | 472 | ||
473 | // FIXME: error check | ||
466 | write(dst_fd, buffer, buffer_pos); | 474 | write(dst_fd, buffer, buffer_pos); |
475 | USE_DESKTOP(total_written += buffer_pos;) | ||
467 | rc_free(&rc); | 476 | rc_free(&rc); |
468 | return 0; | 477 | return USE_DESKTOP(total_written) + 0; |
469 | } | 478 | } |
470 | |||
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 989ac4fd8..27b4ddbcf 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -835,8 +835,10 @@ void inflate_cleanup(void) | |||
835 | free(bytebuffer); | 835 | free(bytebuffer); |
836 | } | 836 | } |
837 | 837 | ||
838 | int inflate_unzip(int in, int out) | 838 | USE_DESKTOP(long long) int |
839 | inflate_unzip(int in, int out) | ||
839 | { | 840 | { |
841 | USE_DESKTOP(long long total = 0;) | ||
840 | ssize_t nwrote; | 842 | ssize_t nwrote; |
841 | typedef void (*sig_type) (int); | 843 | typedef void (*sig_type) (int); |
842 | 844 | ||
@@ -864,6 +866,7 @@ int inflate_unzip(int in, int out) | |||
864 | bb_perror_msg("write"); | 866 | bb_perror_msg("write"); |
865 | return -1; | 867 | return -1; |
866 | } | 868 | } |
869 | USE_DESKTOP(total += nwrote;) | ||
867 | if (ret == 0) break; | 870 | if (ret == 0) break; |
868 | } | 871 | } |
869 | 872 | ||
@@ -880,15 +883,17 @@ int inflate_unzip(int in, int out) | |||
880 | gunzip_bb >>= 8; | 883 | gunzip_bb >>= 8; |
881 | gunzip_bk -= 8; | 884 | gunzip_bk -= 8; |
882 | } | 885 | } |
883 | return 0; | 886 | return USE_DESKTOP(total) + 0; |
884 | } | 887 | } |
885 | 888 | ||
886 | int inflate_gunzip(int in, int out) | 889 | USE_DESKTOP(long long) int |
890 | inflate_gunzip(int in, int out) | ||
887 | { | 891 | { |
888 | uint32_t stored_crc = 0; | 892 | uint32_t stored_crc = 0; |
889 | unsigned int count; | 893 | unsigned int count; |
894 | USE_DESKTOP(long long total = )inflate_unzip(in, out); | ||
890 | 895 | ||
891 | inflate_unzip(in, out); | 896 | USE_DESKTOP(if (total < 0) return total;) |
892 | 897 | ||
893 | /* top up the input buffer with the rest of the trailer */ | 898 | /* top up the input buffer with the rest of the trailer */ |
894 | count = bytebuffer_size - bytebuffer_offset; | 899 | count = bytebuffer_size - bytebuffer_offset; |
@@ -915,5 +920,5 @@ int inflate_gunzip(int in, int out) | |||
915 | return -1; | 920 | return -1; |
916 | } | 921 | } |
917 | 922 | ||
918 | return 0; | 923 | return USE_DESKTOP(total) + 0; |
919 | } | 924 | } |
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c index ad26f465a..24e4f9c9f 100644 --- a/archival/libunarchive/get_header_tar_gz.c +++ b/archival/libunarchive/get_header_tar_gz.c | |||
@@ -17,7 +17,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle) | |||
17 | 17 | ||
18 | xread(archive_handle->src_fd, &magic, 2); | 18 | xread(archive_handle->src_fd, &magic, 2); |
19 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { | 19 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { |
20 | bb_error_msg_and_die("Invalid gzip magic"); | 20 | bb_error_msg_and_die("invalid gzip magic"); |
21 | } | 21 | } |
22 | 22 | ||
23 | check_header_gzip(archive_handle->src_fd); | 23 | check_header_gzip(archive_handle->src_fd); |
diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 578b92963..99e71ec2e 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c | |||
@@ -11,7 +11,8 @@ | |||
11 | #include "unarchive.h" | 11 | #include "unarchive.h" |
12 | 12 | ||
13 | /* transformer(), more than meets the eye */ | 13 | /* transformer(), more than meets the eye */ |
14 | int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd)) | 14 | int open_transformer(int src_fd, |
15 | USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd)) | ||
15 | { | 16 | { |
16 | int fd_pipe[2]; | 17 | int fd_pipe[2]; |
17 | int pid; | 18 | int pid; |
@@ -28,6 +29,7 @@ int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd)) | |||
28 | if (pid == 0) { | 29 | if (pid == 0) { |
29 | /* child process */ | 30 | /* child process */ |
30 | close(fd_pipe[0]); /* We don't wan't to read from the parent */ | 31 | close(fd_pipe[0]); /* We don't wan't to read from the parent */ |
32 | // FIXME: error check? | ||
31 | transformer(src_fd, fd_pipe[1]); | 33 | transformer(src_fd, fd_pipe[1]); |
32 | close(fd_pipe[1]); /* Send EOF */ | 34 | close(fd_pipe[1]); /* Send EOF */ |
33 | close(src_fd); | 35 | close(src_fd); |
@@ -38,5 +40,5 @@ int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd)) | |||
38 | /* parent process */ | 40 | /* parent process */ |
39 | close(fd_pipe[1]); /* Don't want to write to the child */ | 41 | close(fd_pipe[1]); /* Don't want to write to the child */ |
40 | 42 | ||
41 | return(fd_pipe[0]); | 43 | return fd_pipe[0]; |
42 | } | 44 | } |