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) {
131 len = (
long)
read(in->fd, in->buf + in->left,
CHUNK - in->left);
134 in->left += (unsigned)len;
135 }
while (len != 0 && in->left <
CHUNK);
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);
183 if (
read(in->fd, in->buf, 1) != 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);
260 strm->avail_in = in->left;
261 strm->next_in = in->next;
267 fwrite(
"\x1f\x8b\x08\0\0\0\0\0\0\xff", 1, 10, out);
286 unsigned char *
start;
294 bail(
"could not open ", name);
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);
355 in->buf[strm.
next_in - in->buf - 1] &= ~pos;
361 fwrite(start, 1, strm.
next_in - start, out);
368 in->buf[strm.
next_in - in->buf] &= ~1;
375 in->next = in->buf + (strm.
next_in - in->buf);
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);
local void zpull(z_streamp strm, bin *in)
int read(int fd, char *buf, int nbytes)
local void bclose(bin *in)
local unsigned long bget4(bin *in)
local void put4(unsigned long val, FILE *out)
local void gzhead(bin *in)
local bin * bopen(char *name)
int main(int argc, char **argv)
local int bail(char *why1, char *why2)
local void bskip(bin *in, unsigned skip)
#define inflateInit2(strm, windowBits)
GLenum GLuint GLenum GLsizei const GLchar * buf
off_t lseek(int fd, off_t offset, int whence)
uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2)
local int out(void *out_desc, unsigned char *buf, unsigned len)
int ZEXPORT inflate(z_streamp strm, int flush)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
local void skip(file *in, unsigned n)
GLuint const GLchar * name
int open(const char *name, int flags, int mode)
local void gzinit(unsigned long *crc, unsigned long *tot, FILE *out)
local void gzcopy(char *name, int clr, unsigned long *crc, unsigned long *tot, FILE *out)
int ZEXPORT inflateEnd(z_streamp strm)