89#define CHUNK (1U << LGCHUNK)
95 fprintf(stderr,
"gzappend error: %s%s\n", msg1, msg2);
127 unsigned char *start, *
last, *to, *from;
131 if (rot >=
len) rot %=
len;
132 if (rot == 0)
return;
146 if (rot ==
len - 1) {
156 start = from = list + cycles;
162 if (from == start)
break;
185 if (
len == -1)
bye(
"error reading ",
in->name);
186 in->left = (unsigned)
len;
198#define read1(in) (in->left == 0 ? readmore(in) : 0, \
199 in->left--, *(in->next)++)
208 bypass = n & ~((1U <<
in->size) - 1);
211 bye(
"seeking ",
in->name);
216 bye(
"unexpected end of ",
in->name);
228 val += (unsigned)
read1(
in) << 8;
241 if (
read1(
in) != 8)
bye(
"unknown compression method in",
in->name);
243 if (flags & 0xe0)
bye(
"unknown header flags set in",
in->name);
247 n += (unsigned)(
read1(
in)) << 8;
250 if (flags & 8)
while (
read1(
in) != 0) ;
251 if (flags & 16)
while (
read1(
in) != 0) ;
252 if (flags & 2)
skip(
in, 2);
261 int ret, lastbit, left, full;
263 unsigned long crc,
tot;
264 unsigned char *window;
270 gz.
fd = open(
name, O_RDWR, 0);
271 if (gz.
fd == -1)
bye(
"cannot open ",
name);
282 if (window ==
NULL)
bye(
"out of memory",
"");
287 if (ret !=
Z_OK)
bye(
"out of memory",
" or library mismatch");
314 bye(
"invalid compressed data--format violated in",
name);
343 if (crc !=
read4(&gz))
344 bye(
"invalid compressed data--crc mismatch in ",
name);
346 if ((
tot & 0xffffffffUL) !=
read4(&gz))
347 bye(
"invalid compressed data--length mismatch in",
name);
352 "gzappend warning: junk at end of gzip file overwritten\n");
355 lseek(gz.
fd, lastoff - (lastbit != 0),
SEEK_SET);
357 *gz.
buf = (
unsigned char)(*gz.
buf ^ (1 << ((8 - lastbit) & 7)));
369 if (ret !=
Z_OK)
bye(
"out of memory",
"");
392 unsigned char *
in, *
out;
397 fd = open(
name, O_RDONLY, 0);
399 fprintf(stderr,
"gzappend warning: %s not found, skipping ...\n",
414 "gzappend warning: error reading %s, skipping rest ...\n",
430 if (
len == -1)
bye(
"writing gzip file",
"");
431 left -= (unsigned)
len;
439 out[0] = (
unsigned char)(strm->
adler);
440 out[1] = (
unsigned char)(strm->
adler >> 8);
441 out[2] = (
unsigned char)(strm->
adler >> 16);
442 out[3] = (
unsigned char)(strm->
adler >> 24);
450 if (ret == -1)
bye(
"writing gzip file",
"");
459 if (fd > 0) close(fd);
477 "gzappend 1.2 (11 Oct 2012) Copyright (C) 2003, 2012 Mark Adler\n"
480 "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n");
486 if (
argv[0][0] ==
'-') {
487 if (
argv[0][1] <
'0' ||
argv[0][1] >
'9' ||
argv[0][2] != 0)
488 bye(
"invalid compression level",
"");
489 level =
argv[0][1] -
'0';
490 if (*++
argv ==
NULL)
bye(
"no gzip file name after options",
"");
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value)
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
unsigned in(void *in_desc, z_const unsigned char **buf)
unsigned gcd(unsigned a, unsigned b)
void skip(file *in, unsigned n)
void gztack(char *name, int gd, z_stream *strm, int last)
unsigned long read4(file *in)
int gzscan(char *name, z_stream *strm, int level)
void bye(char *msg1, char *msg2)
void rotate(unsigned char *list, unsigned len, unsigned rot)
void * memmove(void *, const void *, size_t)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateEnd(z_streamp strm)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
z_const unsigned char * next
#define Z_DEFAULT_STRATEGY
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
#define inflateInit2(strm, windowBits)
#define Z_DEFAULT_COMPRESSION
int write(ozstream &zs, const T *x, Items items)
int read(izstream &zs, T *x, Items items)