diff options
author | Denis Vlasenko | 2006-10-01 15:55:11 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-10-01 15:55:11 +0000 |
commit | 97a8dd3857aea9730382e2975a2ee2000fd23ebb (patch) | |
tree | 608f73898f3ed5f466dff68189625fa9328a15be /archival/libunarchive | |
parent | f8aa109a9f7c67b291f240fb3ed91da90f26359b (diff) | |
download | busybox-97a8dd3857aea9730382e2975a2ee2000fd23ebb.zip busybox-97a8dd3857aea9730382e2975a2ee2000fd23ebb.tar.gz |
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 657d4ab..d0a4ecb 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, /* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data, not end of file.) */ -int uncompressStream(int src_fd, int dst_fd) +USE_DESKTOP(long long) int +uncompressStream(int src_fd, int dst_fd) { + USE_DESKTOP(long long total_written = 0;) char *outbuf; bunzip_data *bd; int i; outbuf=xmalloc(IOBUF_SIZE); - if(!(i=start_bunzip(&bd,src_fd,0,0))) { + i=start_bunzip(&bd,src_fd,0,0); + if(!i) { for(;;) { if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break; if(i!=write(dst_fd,outbuf,i)) { i=RETVAL_UNEXPECTED_OUTPUT_EOF; break; } + USE_DESKTOP(total_written += i;) } } @@ -692,27 +696,27 @@ int uncompressStream(int src_fd, int dst_fd) if(i==RETVAL_LAST_BLOCK) { if (bd->headerCRC!=bd->totalCRC) { - bb_error_msg("Data integrity error when decompressing."); + bb_error_msg("data integrity error when decompressing"); } else { i=RETVAL_OK; } } else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) { - bb_error_msg("Compressed file ends unexpectedly"); + bb_error_msg("compressed file ends unexpectedly"); } else { - bb_error_msg("Decompression failed"); + bb_error_msg("decompression failed"); } free(bd->dbuf); free(bd); free(outbuf); - return i; + return i ? i : USE_DESKTOP(total_written) + 0; } #ifdef TESTING static char * const bunzip_errors[]={NULL,"Bad file checksum","Not bzip data", "Unexpected input EOF","Unexpected output EOF","Data error", - "Out of memory","Obsolete (pre 0.9.5) bzip format not supported."}; + "Out of memory","Obsolete (pre 0.9.5) bzip format not supported."}; /* Dumb little test thing, decompress stdin to stdout */ int main(int argc, char *argv[]) @@ -720,8 +724,8 @@ int main(int argc, char *argv[]) int i=uncompressStream(0,1); char c; - if(i) fprintf(stderr,"%s\n", bunzip_errors[-i]); - else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n"); + if(i<0) fprintf(stderr,"%s\n", bunzip_errors[-i]); + else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n"); return -i; } #endif diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c index e294143..ff98254 100644 --- a/archival/libunarchive/decompress_uncompress.c +++ b/archival/libunarchive/decompress_uncompress.c @@ -86,8 +86,10 @@ static int maxbits = BITS; * with those of the compress() routine. See the definitions above. */ -int uncompress(int fd_in, int fd_out) +USE_DESKTOP(long long) int +uncompress(int fd_in, int fd_out) { + USE_DESKTOP(long long total_written = 0;) unsigned char *stackp; long int code; int finchar; @@ -182,16 +184,16 @@ int uncompress(int fd_in, int fd_out) { unsigned char *p = &inbuf[posbits >> 3]; - code = - ((((long) (p[0])) | ((long) (p[1]) << 8) | - ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; + code = ((((long) (p[0])) | ((long) (p[1]) << 8) | + ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; } posbits += n_bits; if (oldcode == -1) { - outbuf[outpos++] = (unsigned char) (finchar = - (int) (oldcode = code)); + oldcode = code; + finchar = (int) oldcode; + outbuf[outpos++] = (unsigned char) finchar; continue; } @@ -255,6 +257,7 @@ int uncompress(int fd_in, int fd_out) if (outpos >= OBUFSIZ) { write(fd_out, outbuf, outpos); + USE_DESKTOP(total_written += outpos;) outpos = 0; } stackp += i; @@ -280,9 +283,10 @@ int uncompress(int fd_in, int fd_out) if (outpos > 0) { write(fd_out, outbuf, outpos); + USE_DESKTOP(total_written += outpos;) } RELEASE_CONFIG_BUFFER(inbuf); RELEASE_CONFIG_BUFFER(outbuf); - return 0; + return USE_DESKTOP(total_written) + 0; } diff --git a/archival/libunarchive/decompress_unlzma.c b/archival/libunarchive/decompress_unlzma.c index 0fb1249..a690280 100644 --- a/archival/libunarchive/decompress_unlzma.c +++ b/archival/libunarchive/decompress_unlzma.c @@ -211,9 +211,10 @@ typedef struct { #define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS) #define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS) - -int unlzma(int src_fd, int dst_fd) +USE_DESKTOP(long long) int +unlzma(int src_fd, int dst_fd) { + USE_DESKTOP(long long total_written = 0;) lzma_header_t header; int lc, pb, lp; uint32_t pos_state_mask; @@ -305,7 +306,9 @@ int unlzma(int src_fd, int dst_fd) if (buffer_pos == header.dict_size) { buffer_pos = 0; global_pos += header.dict_size; + // FIXME: error check write(dst_fd, buffer, header.dict_size); + USE_DESKTOP(total_written += header.dict_size;) } if (state < 4) state = 0; @@ -345,7 +348,9 @@ int unlzma(int src_fd, int dst_fd) if (buffer_pos == header.dict_size) { buffer_pos = 0; global_pos += header.dict_size; + // FIXME: error check write(dst_fd, buffer, header.dict_size); + USE_DESKTOP(total_written += header.dict_size;) } continue; } else { @@ -456,15 +461,18 @@ int unlzma(int src_fd, int dst_fd) if (buffer_pos == header.dict_size) { buffer_pos = 0; global_pos += header.dict_size; + // FIXME: error check write(dst_fd, buffer, header.dict_size); + USE_DESKTOP(total_written += header.dict_size;) } len--; } while (len != 0 && buffer_pos < header.dst_size); } } + // FIXME: error check write(dst_fd, buffer, buffer_pos); + USE_DESKTOP(total_written += buffer_pos;) rc_free(&rc); - return 0; + return USE_DESKTOP(total_written) + 0; } - diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 989ac4f..27b4ddb 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c @@ -835,8 +835,10 @@ void inflate_cleanup(void) free(bytebuffer); } -int inflate_unzip(int in, int out) +USE_DESKTOP(long long) int +inflate_unzip(int in, int out) { + USE_DESKTOP(long long total = 0;) ssize_t nwrote; typedef void (*sig_type) (int); @@ -864,6 +866,7 @@ int inflate_unzip(int in, int out) bb_perror_msg("write"); return -1; } + USE_DESKTOP(total += nwrote;) if (ret == 0) break; } @@ -880,15 +883,17 @@ int inflate_unzip(int in, int out) gunzip_bb >>= 8; gunzip_bk -= 8; } - return 0; + return USE_DESKTOP(total) + 0; } -int inflate_gunzip(int in, int out) +USE_DESKTOP(long long) int +inflate_gunzip(int in, int out) { uint32_t stored_crc = 0; unsigned int count; + USE_DESKTOP(long long total = )inflate_unzip(in, out); - inflate_unzip(in, out); + USE_DESKTOP(if (total < 0) return total;) /* top up the input buffer with the rest of the trailer */ count = bytebuffer_size - bytebuffer_offset; @@ -915,5 +920,5 @@ int inflate_gunzip(int in, int out) return -1; } - return 0; + return USE_DESKTOP(total) + 0; } diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c index ad26f46..24e4f9c 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) xread(archive_handle->src_fd, &magic, 2); if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { - bb_error_msg_and_die("Invalid gzip magic"); + bb_error_msg_and_die("invalid gzip magic"); } check_header_gzip(archive_handle->src_fd); diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 578b929..99e71ec 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c @@ -11,7 +11,8 @@ #include "unarchive.h" /* transformer(), more than meets the eye */ -int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd)) +int open_transformer(int src_fd, + USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd)) { int fd_pipe[2]; int pid; @@ -28,6 +29,7 @@ int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd)) if (pid == 0) { /* child process */ close(fd_pipe[0]); /* We don't wan't to read from the parent */ + // FIXME: error check? transformer(src_fd, fd_pipe[1]); close(fd_pipe[1]); /* Send EOF */ close(src_fd); @@ -38,5 +40,5 @@ int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd)) /* parent process */ close(fd_pipe[1]); /* Don't want to write to the child */ - return(fd_pipe[0]); + return fd_pipe[0]; } |