version 1.71, 2005/02/22 21:45:44 |
version 1.71.2.3, 2005/11/27 23:05:41 |
Line 637 gz_compress(int in, int out, off_t *gsiz |
|
Line 637 gz_compress(int in, int out, off_t *gsiz |
|
(int)(in_tot >> 24) & 0xff); |
(int)(in_tot >> 24) & 0xff); |
if (i != 8) |
if (i != 8) |
maybe_err("snprintf"); |
maybe_err("snprintf"); |
|
if (in_tot > 0xffffffff) |
|
maybe_warn("input file size >= 4GB cannot be saved"); |
if (write(out, outbufp, i) != i) { |
if (write(out, outbufp, i) != i) { |
maybe_warn("write"); |
maybe_warn("write"); |
in_tot = -1; |
in_tot = -1; |
Line 664 gz_uncompress(int in, int out, char *pre |
|
Line 666 gz_uncompress(int in, int out, char *pre |
|
{ |
{ |
z_stream z; |
z_stream z; |
char *outbufp, *inbufp; |
char *outbufp, *inbufp; |
off_t out_tot, in_tot; |
off_t out_tot = -1, in_tot = 0; |
uint32_t out_sub_tot; |
uint32_t out_sub_tot = 0; |
enum { |
enum { |
GZSTATE_MAGIC0, |
GZSTATE_MAGIC0, |
GZSTATE_MAGIC1, |
GZSTATE_MAGIC1, |
Line 685 gz_uncompress(int in, int out, char *pre |
|
Line 687 gz_uncompress(int in, int out, char *pre |
|
GZSTATE_LEN, |
GZSTATE_LEN, |
} state = GZSTATE_MAGIC0; |
} state = GZSTATE_MAGIC0; |
int flags = 0, skip_count = 0; |
int flags = 0, skip_count = 0; |
int error, done_reading = 0; |
int error = Z_STREAM_ERROR, done_reading = 0; |
uLong crc; |
uLong crc = 0; |
ssize_t wr; |
ssize_t wr; |
int needmore = 0; |
int needmore = 0; |
|
|
Line 725 gz_uncompress(int in, int out, char *pre |
|
Line 727 gz_uncompress(int in, int out, char *pre |
|
BUFLEN - z.avail_in); |
BUFLEN - z.avail_in); |
|
|
if (in_size == -1) { |
if (in_size == -1) { |
#ifndef SMALL |
|
if (tflag && vflag) |
|
print_test(filename, 0); |
|
#endif |
|
maybe_warn("failed to read stdin"); |
maybe_warn("failed to read stdin"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} else if (in_size == 0) { |
} else if (in_size == 0) { |
done_reading = 1; |
done_reading = 1; |
} |
} |
Line 751 gz_uncompress(int in, int out, char *pre |
|
Line 748 gz_uncompress(int in, int out, char *pre |
|
case GZSTATE_MAGIC0: |
case GZSTATE_MAGIC0: |
if (*z.next_in != GZIP_MAGIC0) { |
if (*z.next_in != GZIP_MAGIC0) { |
maybe_warnx("input not gziped (MAGIC0)"); |
maybe_warnx("input not gziped (MAGIC0)"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
ADVANCE(); |
ADVANCE(); |
state++; |
state++; |
Line 764 gz_uncompress(int in, int out, char *pre |
|
Line 760 gz_uncompress(int in, int out, char *pre |
|
if (*z.next_in != GZIP_MAGIC1 && |
if (*z.next_in != GZIP_MAGIC1 && |
*z.next_in != GZIP_OMAGIC1) { |
*z.next_in != GZIP_OMAGIC1) { |
maybe_warnx("input not gziped (MAGIC1)"); |
maybe_warnx("input not gziped (MAGIC1)"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
ADVANCE(); |
ADVANCE(); |
state++; |
state++; |
Line 774 gz_uncompress(int in, int out, char *pre |
|
Line 769 gz_uncompress(int in, int out, char *pre |
|
case GZSTATE_METHOD: |
case GZSTATE_METHOD: |
if (*z.next_in != Z_DEFLATED) { |
if (*z.next_in != Z_DEFLATED) { |
maybe_warnx("unknown compression method"); |
maybe_warnx("unknown compression method"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
ADVANCE(); |
ADVANCE(); |
state++; |
state++; |
Line 859 gz_uncompress(int in, int out, char *pre |
|
Line 853 gz_uncompress(int in, int out, char *pre |
|
case GZSTATE_INIT: |
case GZSTATE_INIT: |
if (inflateInit2(&z, -MAX_WBITS) != Z_OK) { |
if (inflateInit2(&z, -MAX_WBITS) != Z_OK) { |
maybe_warnx("failed to inflateInit"); |
maybe_warnx("failed to inflateInit"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
state++; |
state++; |
break; |
break; |
|
|
case GZSTATE_READ: |
case GZSTATE_READ: |
error = inflate(&z, Z_FINISH); |
error = inflate(&z, Z_FINISH); |
|
switch (error) { |
/* Z_BUF_ERROR goes with Z_FINISH... */ |
/* Z_BUF_ERROR goes with Z_FINISH... */ |
if (error != Z_STREAM_END && error != Z_BUF_ERROR) |
case Z_BUF_ERROR: |
/* Just need more input */ |
case Z_STREAM_END: |
|
case Z_OK: |
break; |
break; |
|
|
|
case Z_NEED_DICT: |
|
maybe_warnx("Z_NEED_DICT error"); |
|
goto stop_and_fail; |
|
case Z_DATA_ERROR: |
|
maybe_warnx("data stream error"); |
|
goto stop_and_fail; |
|
case Z_STREAM_ERROR: |
|
maybe_warnx("internal stream error"); |
|
goto stop_and_fail; |
|
case Z_MEM_ERROR: |
|
maybe_warnx("memory allocation error"); |
|
goto stop_and_fail; |
|
|
|
default: |
|
maybe_warn("unknown error from inflate(): %d", |
|
error); |
|
} |
wr = BUFLEN - z.avail_out; |
wr = BUFLEN - z.avail_out; |
|
|
if (wr != 0) { |
if (wr != 0) { |
Line 882 gz_uncompress(int in, int out, char *pre |
|
Line 895 gz_uncompress(int in, int out, char *pre |
|
#endif |
#endif |
write(out, outbufp, wr) != wr) { |
write(out, outbufp, wr) != wr) { |
maybe_warn("error writing to output"); |
maybe_warn("error writing to output"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
|
|
out_tot += wr; |
out_tot += wr; |
Line 909 gz_uncompress(int in, int out, char *pre |
|
Line 921 gz_uncompress(int in, int out, char *pre |
|
continue; |
continue; |
} |
} |
maybe_warnx("truncated input"); |
maybe_warnx("truncated input"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
origcrc = ((unsigned)z.next_in[0] & 0xff) | |
origcrc = ((unsigned)z.next_in[0] & 0xff) | |
((unsigned)z.next_in[1] & 0xff) << 8 | |
((unsigned)z.next_in[1] & 0xff) << 8 | |
Line 919 gz_uncompress(int in, int out, char *pre |
|
Line 930 gz_uncompress(int in, int out, char *pre |
|
if (origcrc != crc) { |
if (origcrc != crc) { |
maybe_warnx("invalid compressed" |
maybe_warnx("invalid compressed" |
" data--crc error"); |
" data--crc error"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
} |
} |
|
|
Line 942 gz_uncompress(int in, int out, char *pre |
|
Line 952 gz_uncompress(int in, int out, char *pre |
|
continue; |
continue; |
} |
} |
maybe_warnx("truncated input"); |
maybe_warnx("truncated input"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
origlen = ((unsigned)z.next_in[0] & 0xff) | |
origlen = ((unsigned)z.next_in[0] & 0xff) | |
((unsigned)z.next_in[1] & 0xff) << 8 | |
((unsigned)z.next_in[1] & 0xff) << 8 | |
Line 953 gz_uncompress(int in, int out, char *pre |
|
Line 962 gz_uncompress(int in, int out, char *pre |
|
if (origlen != out_sub_tot) { |
if (origlen != out_sub_tot) { |
maybe_warnx("invalid compressed" |
maybe_warnx("invalid compressed" |
" data--length error"); |
" data--length error"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
} |
} |
|
|
Line 963 gz_uncompress(int in, int out, char *pre |
|
Line 971 gz_uncompress(int in, int out, char *pre |
|
|
|
if (error < 0) { |
if (error < 0) { |
maybe_warnx("decompression error"); |
maybe_warnx("decompression error"); |
out_tot = -1; |
goto stop_and_fail; |
goto stop; |
|
} |
} |
state = GZSTATE_MAGIC0; |
state = GZSTATE_MAGIC0; |
break; |
break; |
} |
} |
continue; |
continue; |
|
stop_and_fail: |
|
out_tot = -1; |
stop: |
stop: |
break; |
break; |
} |
} |
if (state > GZSTATE_INIT) |
if (state > GZSTATE_INIT) |
inflateEnd(&z); |
inflateEnd(&z); |
|
|
#ifndef SMALL |
|
if (tflag && vflag) |
|
print_test(filename, out_tot != -1); |
|
#endif |
|
|
|
free(inbufp); |
free(inbufp); |
out1: |
out1: |
free(outbufp); |
free(outbufp); |
Line 1206 file_compress(char *file, char *outfile, |
|
Line 1210 file_compress(char *file, char *outfile, |
|
maybe_warn("couldn't close ouput"); |
maybe_warn("couldn't close ouput"); |
|
|
#ifndef SMALL |
#ifndef SMALL |
if (stat(outfile, &osb) < 0) { |
if (stat(outfile, &osb) != 0) { |
maybe_warn("couldn't stat: %s", outfile); |
maybe_warn("couldn't stat: %s", outfile); |
goto bad_outfile; |
goto bad_outfile; |
} |
} |
Line 1445 file_uncompress(char *file, char *outfil |
|
Line 1449 file_uncompress(char *file, char *outfil |
|
/* |
/* |
* if we can't stat the file don't remove the file. |
* if we can't stat the file don't remove the file. |
*/ |
*/ |
if (stat(outfile, &osb) < 0) { |
if (stat(outfile, &osb) != 0) { |
maybe_warn("couldn't stat (leaving original): %s", |
maybe_warn("couldn't stat (leaving original): %s", |
outfile); |
outfile); |
return -1; |
return -1; |
} |
} |
if (osb.st_size != size) { |
if (osb.st_size != size) { |
maybe_warn("stat gave different size: %" PRIdOFF |
maybe_warnx("stat gave different size: %" PRIdOFF |
" != %" PRIdOFF " (leaving original)", |
" != %" PRIdOFF " (leaving original)", |
size, osb.st_size); |
size, osb.st_size); |
unlink(outfile); |
unlink(outfile); |
Line 1582 handle_stdin(void) |
|
Line 1586 handle_stdin(void) |
|
#ifndef SMALL |
#ifndef SMALL |
if (vflag && !tflag && usize != -1 && gsize != -1) |
if (vflag && !tflag && usize != -1 && gsize != -1) |
print_verbage(NULL, NULL, usize, gsize); |
print_verbage(NULL, NULL, usize, gsize); |
|
if (vflag && tflag) |
|
print_test("(stdin)", usize != -1); |
#endif |
#endif |
|
|
} |
} |
Line 1650 handle_pathname(char *path) |
|
Line 1656 handle_pathname(char *path) |
|
} |
} |
|
|
retry: |
retry: |
if (stat(path, &sb) < 0) { |
if (stat(path, &sb) != 0) { |
/* lets try <path>.gz if we're decompressing */ |
/* lets try <path>.gz if we're decompressing */ |
if (dflag && s == NULL && errno == ENOENT) { |
if (dflag && s == NULL && errno == ENOENT) { |
len = strlen(path); |
len = strlen(path); |
Line 1697 handle_file(char *file, struct stat *sbp |
|
Line 1703 handle_file(char *file, struct stat *sbp |
|
infile = file; |
infile = file; |
if (dflag) { |
if (dflag) { |
usize = file_uncompress(file, outfile, sizeof(outfile)); |
usize = file_uncompress(file, outfile, sizeof(outfile)); |
|
if (vflag && tflag) |
|
print_test(file, usize != -1); |
if (usize == -1) |
if (usize == -1) |
return; |
return; |
gsize = sbp->st_size; |
gsize = sbp->st_size; |
Line 1827 print_list(int fd, off_t out, const char |
|
Line 1835 print_list(int fd, off_t out, const char |
|
static int first = 1; |
static int first = 1; |
#ifndef SMALL |
#ifndef SMALL |
static off_t in_tot, out_tot; |
static off_t in_tot, out_tot; |
uint32_t crc; |
uint32_t crc = 0; |
#endif |
#endif |
off_t in; |
off_t in = 0; |
int rv; |
int rv; |
|
|
if (first) { |
if (first) { |