g[un]zip: add support for -v (verbose).
Add CONFIG_DESKTOP, almost all bloat from this change is hidden under that.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user