94 struct ind *me = (
struct ind *)in_desc;
101 if ((
unsigned)ret >
SIZE -
len)
110 }
while (ret != 0 &&
len <
SIZE);
134 struct outd *me = (
struct outd *)out_desc;
143 if ((
unsigned)ret >
len)
155#define NEXT() (have ? 0 : (have = in(indp, &next)), \
156 last = have ? (have--, (int)(*next++)) : -1)
175 if (chunk > have) { \
181 if (chunk > have) { \
230 strm->
msg = (
char *)
"unknown lzw flags set";
234 if (max < 9 || max > 16) {
235 strm->
msg = (
char *)
"lzw bits out of range";
245 end = flags ? 256 : 255;
251 final = prev = (unsigned)
last;
255 strm->
msg = (
char *)
"invalid lzw code";
258 rem = (unsigned)
last >> 1;
261 outbuf[0] = (
unsigned char)
final;
299 rem = (unsigned)
last >> (8 - left);
302 if (
code == 256 && flags) {
321 if (
code != end + 1 || prev > end) {
322 strm->
msg = (
char *)
"invalid lzw code";
325 match[stack++] = (
unsigned char)
final;
331 while (
code >= 256) {
342 prefix[end] = (
unsigned short)prev;
343 suffix[end] = (
unsigned char)
final;
350 while (stack >
SIZE - outcnt) {
351 while (outcnt <
SIZE)
385 int ret, first,
last;
386 unsigned have, flags,
len;
407 strm->
msg = (
char *)
"incorrect header check";
422 if (
last == -1)
break;
423 strm->
msg = (
char *)
"unknown compression method";
434 if (
last == -1)
break;
436 strm->
msg = (
char *)
"unknown header flags set";
442 len += (unsigned)(
NEXT()) << 8;
443 if (
last == -1)
break;
447 if (
NEXT() == -1)
break;
450 if (
last == -1)
break;
464 if (
last == -1)
break;
489 strm->
msg = (
char *)
"incorrect data check";
500 strm->
msg = (
char *)
"incorrect length check";
523 if (
stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG)
527 (void)chmod(to, was.st_mode & 07777);
530 (void)
chown(to, was.st_uid, was.st_gid);
533 when.
actime = was.st_atime;
535 (void)utime(to, &when);
554 if (inname ==
NULL || *inname == 0) {
559 infile = open(inname, O_RDONLY, 0);
561 fprintf(stderr,
"gun cannot open %s\n", inname);
567 else if (outname ==
NULL || *outname == 0) {
572 outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666);
575 fprintf(stderr,
"gun cannot create %s\n", outname);
582 ret =
gunpipe(strm, infile, outfile);
583 if (outfile > 2) close(outfile);
584 if (infile > 2) close(infile);
590 if (infile > 2 && outfile > 2) {
595 fprintf(stderr,
"gun warning: trailing garbage ignored in %s\n",
599 if (outfile > 2) unlink(outname);
600 fprintf(stderr,
"gun data error on %s: %s\n", inname, strm->
msg);
603 if (outfile > 2) unlink(outname);
604 fprintf(stderr,
"gun out of memory error--aborting\n");
607 if (outfile > 2) unlink(outname);
609 fprintf(stderr,
"gun write error on %s: %s\n",
613 fprintf(stderr,
"gun read error on %s: %s\n",
617 fprintf(stderr,
"gun unexpected end of file on %s\n",
622 if (outfile > 2) unlink(outname);
623 fprintf(stderr,
"gun internal error--aborting\n");
635 unsigned char *window;
645 fprintf(stderr,
"gun out of memory error--aborting\n");
653 if (
argc && strcmp(*
argv,
"-h") == 0) {
654 fprintf(stderr,
"gun 1.6 (17 Jan 2010)\n");
655 fprintf(stderr,
"Copyright (C) 2003-2010 Mark Adler\n");
656 fprintf(stderr,
"usage: gun [-t] [file1.gz [file2.Z ...]]\n");
659 if (
argc && strcmp(*
argv,
"-t") == 0) {
670 if (strcmp(*
argv +
len - 3,
".gz") == 0 ||
671 strcmp(*
argv +
len - 3,
"-gz") == 0)
673 else if (strcmp(*
argv +
len - 2,
".z") == 0 ||
674 strcmp(*
argv +
len - 2,
"-z") == 0 ||
675 strcmp(*
argv +
len - 2,
"_z") == 0 ||
676 strcmp(*
argv +
len - 2,
".Z") == 0)
679 fprintf(stderr,
"gun error: no gz type on %s--skipping\n",
684 if (outname ==
NULL) {
685 fprintf(stderr,
"gun out of memory error--aborting\n");
int bits(struct state *s, int need)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
unsigned char suffix[65536]
int gunpipe(z_stream *strm, int infile, int outfile)
void copymeta(char *from, char *to)
unsigned char outbuf[SIZE]
unsigned char match[65280+2]
unsigned in(void *in_desc, z_const unsigned char **buf)
int gunzip(z_stream *strm, char *inname, char *outname, int test)
int lunpipe(unsigned have, z_const unsigned char *next, struct ind *indp, int outfile, z_stream *strm)
unsigned short prefix[65536]
unsigned char inbuf[SIZE]
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
int ZEXPORT inflateBackEnd(z_streamp strm)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
size_t strlen(const char *)
int chown(const char *, int, int)
#define inflateBackInit(strm, windowBits, window)
int write(ozstream &zs, const T *x, Items items)
int read(izstream &zs, T *x, Items items)