68 fprintf(stderr,
"gzjoin error: %s%s, output incomplete\n", why1, why2);
108 in->
fd = open(name, O_RDONLY, 0);
109 if (in->
buf == NULL || in->
fd == -1) {
134 in->
left += (unsigned)len;
136 return len == 0 ? 1 : 0;
140 #define bget(in) (in->left ? 0 : bload(in), \ 141 in->left ? (in->left--, *(in->next)++) : \ 142 bail("unexpected end of file on ", in->name)) 150 val += (
unsigned long)(
bget(in)) << 8;
151 val += (
unsigned long)(
bget(in)) << 16;
152 val += (
unsigned long)(
bget(in)) << 24;
164 if (skip <= in->left) {
178 left = skip & (
CHUNK - 1);
184 bail(
"unexpected end of file on ", in->
name);
196 bail(
"unexpected end of file on ", in->
name);
209 if (
bget(in) != 0x1f ||
bget(in) != 0x8b ||
bget(in) != 8)
210 bail(in->
name,
" is not a valid gzip file");
214 if ((flags & 0xe0) != 0)
215 bail(
"unknown reserved bits set in ", in->
name);
225 len += (unsigned)(
bget(in)) << 8;
231 while (
bget(in) != 0)
236 while (
bget(in) != 0)
247 putc(val & 0xff, out);
248 putc((val >> 8) & 0xff, out);
249 putc((val >> 16) & 0xff, out);
250 putc((val >> 24) & 0xff, out);
259 bail(
"unexpected end of file on ", in->
name);
267 fwrite(
"\x1f\x8b\x08\0\0\0\0\0\0\xff", 1, 10, out);
279 local void gzcopy(
char *name,
int clr,
unsigned long *crc,
unsigned long *tot,
286 unsigned char *start;
294 bail(
"could not open ", name);
306 if (junk == NULL || ret !=
Z_OK)
307 bail(
"out of memory",
"");
320 fwrite(start, 1, strm.
next_in - start, out);
332 bail(
"out of memory",
"");
334 bail(
"invalid compressed data in ", in->
name);
361 fwrite(start, 1, strm.
next_in - start, out);
379 fwrite(start, 1, in->
next - start - 1, out);
381 if (pos == 0 || !clr)
386 last &= ((0x100 >> pos) - 1);
392 fwrite(
"\0\0\xff\xff", 1, 4, out);
401 putc(last | 0x20, out);
404 putc(last | 0x80, out);
412 *tot += (
unsigned long)len;
427 int main(
int argc,
char **argv)
429 unsigned long crc, tot;
437 fputs(
"gzjoin usage: gzjoin f1.gz [f2.gz [f3.gz ...]] > fjoin.gz\n",
443 gzinit(&crc, &tot, stdout);
445 gzcopy(*argv++, argc, &crc, &tot, stdout);
static void zpull(z_streamp strm, bin *in)
static void bskip(bin *in, unsigned skip)
static int bload(bin *in)
static void gzhead(bin *in)
int main(int argc, char **argv)
static int bail(char *why1, char *why2)
static unsigned long bget4(bin *in)
static void skip(file *in, unsigned n)
static void bclose(bin *in)
unsigned long crc32(unsigned long crc, unsigned char *buf, uInt len)
#define inflateInit2(strm, windowBits)
static int out(void *out_desc, unsigned char *buf, unsigned len)
static void gzcopy(char *name, int clr, unsigned long *crc, unsigned long *tot, FILE *out)
static bin * bopen(char *name)
int read(izstream &zs, T *x, Items items)
static void put4(unsigned long val, FILE *out)
uLong crc32_combine(uLong crc1, uLong crc2, long len2)
static unsigned in(void *in_desc, z_const unsigned char **buf)
int inflateEnd(z_streamp strm)
int inflate(z_streamp strm, int flush)
static void gzinit(unsigned long *crc, unsigned long *tot, FILE *out)