annotate src/zlib-1.2.8/examples/gzappend.c @ 128:5b4145a0d408

Current zlib source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 18 Oct 2016 14:33:52 +0100
parents
children
rev   line source
cannam@128 1 /* gzappend -- command to append to a gzip file
cannam@128 2
cannam@128 3 Copyright (C) 2003, 2012 Mark Adler, all rights reserved
cannam@128 4 version 1.2, 11 Oct 2012
cannam@128 5
cannam@128 6 This software is provided 'as-is', without any express or implied
cannam@128 7 warranty. In no event will the author be held liable for any damages
cannam@128 8 arising from the use of this software.
cannam@128 9
cannam@128 10 Permission is granted to anyone to use this software for any purpose,
cannam@128 11 including commercial applications, and to alter it and redistribute it
cannam@128 12 freely, subject to the following restrictions:
cannam@128 13
cannam@128 14 1. The origin of this software must not be misrepresented; you must not
cannam@128 15 claim that you wrote the original software. If you use this software
cannam@128 16 in a product, an acknowledgment in the product documentation would be
cannam@128 17 appreciated but is not required.
cannam@128 18 2. Altered source versions must be plainly marked as such, and must not be
cannam@128 19 misrepresented as being the original software.
cannam@128 20 3. This notice may not be removed or altered from any source distribution.
cannam@128 21
cannam@128 22 Mark Adler madler@alumni.caltech.edu
cannam@128 23 */
cannam@128 24
cannam@128 25 /*
cannam@128 26 * Change history:
cannam@128 27 *
cannam@128 28 * 1.0 19 Oct 2003 - First version
cannam@128 29 * 1.1 4 Nov 2003 - Expand and clarify some comments and notes
cannam@128 30 * - Add version and copyright to help
cannam@128 31 * - Send help to stdout instead of stderr
cannam@128 32 * - Add some preemptive typecasts
cannam@128 33 * - Add L to constants in lseek() calls
cannam@128 34 * - Remove some debugging information in error messages
cannam@128 35 * - Use new data_type definition for zlib 1.2.1
cannam@128 36 * - Simplfy and unify file operations
cannam@128 37 * - Finish off gzip file in gztack()
cannam@128 38 * - Use deflatePrime() instead of adding empty blocks
cannam@128 39 * - Keep gzip file clean on appended file read errors
cannam@128 40 * - Use in-place rotate instead of auxiliary buffer
cannam@128 41 * (Why you ask? Because it was fun to write!)
cannam@128 42 * 1.2 11 Oct 2012 - Fix for proper z_const usage
cannam@128 43 * - Check for input buffer malloc failure
cannam@128 44 */
cannam@128 45
cannam@128 46 /*
cannam@128 47 gzappend takes a gzip file and appends to it, compressing files from the
cannam@128 48 command line or data from stdin. The gzip file is written to directly, to
cannam@128 49 avoid copying that file, in case it's large. Note that this results in the
cannam@128 50 unfriendly behavior that if gzappend fails, the gzip file is corrupted.
cannam@128 51
cannam@128 52 This program was written to illustrate the use of the new Z_BLOCK option of
cannam@128 53 zlib 1.2.x's inflate() function. This option returns from inflate() at each
cannam@128 54 block boundary to facilitate locating and modifying the last block bit at
cannam@128 55 the start of the final deflate block. Also whether using Z_BLOCK or not,
cannam@128 56 another required feature of zlib 1.2.x is that inflate() now provides the
cannam@128 57 number of unusued bits in the last input byte used. gzappend will not work
cannam@128 58 with versions of zlib earlier than 1.2.1.
cannam@128 59
cannam@128 60 gzappend first decompresses the gzip file internally, discarding all but
cannam@128 61 the last 32K of uncompressed data, and noting the location of the last block
cannam@128 62 bit and the number of unused bits in the last byte of the compressed data.
cannam@128 63 The gzip trailer containing the CRC-32 and length of the uncompressed data
cannam@128 64 is verified. This trailer will be later overwritten.
cannam@128 65
cannam@128 66 Then the last block bit is cleared by seeking back in the file and rewriting
cannam@128 67 the byte that contains it. Seeking forward, the last byte of the compressed
cannam@128 68 data is saved along with the number of unused bits to initialize deflate.
cannam@128 69
cannam@128 70 A deflate process is initialized, using the last 32K of the uncompressed
cannam@128 71 data from the gzip file to initialize the dictionary. If the total
cannam@128 72 uncompressed data was less than 32K, then all of it is used to initialize
cannam@128 73 the dictionary. The deflate output bit buffer is also initialized with the
cannam@128 74 last bits from the original deflate stream. From here on, the data to
cannam@128 75 append is simply compressed using deflate, and written to the gzip file.
cannam@128 76 When that is complete, the new CRC-32 and uncompressed length are written
cannam@128 77 as the trailer of the gzip file.
cannam@128 78 */
cannam@128 79
cannam@128 80 #include <stdio.h>
cannam@128 81 #include <stdlib.h>
cannam@128 82 #include <string.h>
cannam@128 83 #include <fcntl.h>
cannam@128 84 #include <unistd.h>
cannam@128 85 #include "zlib.h"
cannam@128 86
cannam@128 87 #define local static
cannam@128 88 #define LGCHUNK 14
cannam@128 89 #define CHUNK (1U << LGCHUNK)
cannam@128 90 #define DSIZE 32768U
cannam@128 91
cannam@128 92 /* print an error message and terminate with extreme prejudice */
cannam@128 93 local void bye(char *msg1, char *msg2)
cannam@128 94 {
cannam@128 95 fprintf(stderr, "gzappend error: %s%s\n", msg1, msg2);
cannam@128 96 exit(1);
cannam@128 97 }
cannam@128 98
cannam@128 99 /* return the greatest common divisor of a and b using Euclid's algorithm,
cannam@128 100 modified to be fast when one argument much greater than the other, and
cannam@128 101 coded to avoid unnecessary swapping */
cannam@128 102 local unsigned gcd(unsigned a, unsigned b)
cannam@128 103 {
cannam@128 104 unsigned c;
cannam@128 105
cannam@128 106 while (a && b)
cannam@128 107 if (a > b) {
cannam@128 108 c = b;
cannam@128 109 while (a - c >= c)
cannam@128 110 c <<= 1;
cannam@128 111 a -= c;
cannam@128 112 }
cannam@128 113 else {
cannam@128 114 c = a;
cannam@128 115 while (b - c >= c)
cannam@128 116 c <<= 1;
cannam@128 117 b -= c;
cannam@128 118 }
cannam@128 119 return a + b;
cannam@128 120 }
cannam@128 121
cannam@128 122 /* rotate list[0..len-1] left by rot positions, in place */
cannam@128 123 local void rotate(unsigned char *list, unsigned len, unsigned rot)
cannam@128 124 {
cannam@128 125 unsigned char tmp;
cannam@128 126 unsigned cycles;
cannam@128 127 unsigned char *start, *last, *to, *from;
cannam@128 128
cannam@128 129 /* normalize rot and handle degenerate cases */
cannam@128 130 if (len < 2) return;
cannam@128 131 if (rot >= len) rot %= len;
cannam@128 132 if (rot == 0) return;
cannam@128 133
cannam@128 134 /* pointer to last entry in list */
cannam@128 135 last = list + (len - 1);
cannam@128 136
cannam@128 137 /* do simple left shift by one */
cannam@128 138 if (rot == 1) {
cannam@128 139 tmp = *list;
cannam@128 140 memcpy(list, list + 1, len - 1);
cannam@128 141 *last = tmp;
cannam@128 142 return;
cannam@128 143 }
cannam@128 144
cannam@128 145 /* do simple right shift by one */
cannam@128 146 if (rot == len - 1) {
cannam@128 147 tmp = *last;
cannam@128 148 memmove(list + 1, list, len - 1);
cannam@128 149 *list = tmp;
cannam@128 150 return;
cannam@128 151 }
cannam@128 152
cannam@128 153 /* otherwise do rotate as a set of cycles in place */
cannam@128 154 cycles = gcd(len, rot); /* number of cycles */
cannam@128 155 do {
cannam@128 156 start = from = list + cycles; /* start index is arbitrary */
cannam@128 157 tmp = *from; /* save entry to be overwritten */
cannam@128 158 for (;;) {
cannam@128 159 to = from; /* next step in cycle */
cannam@128 160 from += rot; /* go right rot positions */
cannam@128 161 if (from > last) from -= len; /* (pointer better not wrap) */
cannam@128 162 if (from == start) break; /* all but one shifted */
cannam@128 163 *to = *from; /* shift left */
cannam@128 164 }
cannam@128 165 *to = tmp; /* complete the circle */
cannam@128 166 } while (--cycles);
cannam@128 167 }
cannam@128 168
cannam@128 169 /* structure for gzip file read operations */
cannam@128 170 typedef struct {
cannam@128 171 int fd; /* file descriptor */
cannam@128 172 int size; /* 1 << size is bytes in buf */
cannam@128 173 unsigned left; /* bytes available at next */
cannam@128 174 unsigned char *buf; /* buffer */
cannam@128 175 z_const unsigned char *next; /* next byte in buffer */
cannam@128 176 char *name; /* file name for error messages */
cannam@128 177 } file;
cannam@128 178
cannam@128 179 /* reload buffer */
cannam@128 180 local int readin(file *in)
cannam@128 181 {
cannam@128 182 int len;
cannam@128 183
cannam@128 184 len = read(in->fd, in->buf, 1 << in->size);
cannam@128 185 if (len == -1) bye("error reading ", in->name);
cannam@128 186 in->left = (unsigned)len;
cannam@128 187 in->next = in->buf;
cannam@128 188 return len;
cannam@128 189 }
cannam@128 190
cannam@128 191 /* read from file in, exit if end-of-file */
cannam@128 192 local int readmore(file *in)
cannam@128 193 {
cannam@128 194 if (readin(in) == 0) bye("unexpected end of ", in->name);
cannam@128 195 return 0;
cannam@128 196 }
cannam@128 197
cannam@128 198 #define read1(in) (in->left == 0 ? readmore(in) : 0, \
cannam@128 199 in->left--, *(in->next)++)
cannam@128 200
cannam@128 201 /* skip over n bytes of in */
cannam@128 202 local void skip(file *in, unsigned n)
cannam@128 203 {
cannam@128 204 unsigned bypass;
cannam@128 205
cannam@128 206 if (n > in->left) {
cannam@128 207 n -= in->left;
cannam@128 208 bypass = n & ~((1U << in->size) - 1);
cannam@128 209 if (bypass) {
cannam@128 210 if (lseek(in->fd, (off_t)bypass, SEEK_CUR) == -1)
cannam@128 211 bye("seeking ", in->name);
cannam@128 212 n -= bypass;
cannam@128 213 }
cannam@128 214 readmore(in);
cannam@128 215 if (n > in->left)
cannam@128 216 bye("unexpected end of ", in->name);
cannam@128 217 }
cannam@128 218 in->left -= n;
cannam@128 219 in->next += n;
cannam@128 220 }
cannam@128 221
cannam@128 222 /* read a four-byte unsigned integer, little-endian, from in */
cannam@128 223 unsigned long read4(file *in)
cannam@128 224 {
cannam@128 225 unsigned long val;
cannam@128 226
cannam@128 227 val = read1(in);
cannam@128 228 val += (unsigned)read1(in) << 8;
cannam@128 229 val += (unsigned long)read1(in) << 16;
cannam@128 230 val += (unsigned long)read1(in) << 24;
cannam@128 231 return val;
cannam@128 232 }
cannam@128 233
cannam@128 234 /* skip over gzip header */
cannam@128 235 local void gzheader(file *in)
cannam@128 236 {
cannam@128 237 int flags;
cannam@128 238 unsigned n;
cannam@128 239
cannam@128 240 if (read1(in) != 31 || read1(in) != 139) bye(in->name, " not a gzip file");
cannam@128 241 if (read1(in) != 8) bye("unknown compression method in", in->name);
cannam@128 242 flags = read1(in);
cannam@128 243 if (flags & 0xe0) bye("unknown header flags set in", in->name);
cannam@128 244 skip(in, 6);
cannam@128 245 if (flags & 4) {
cannam@128 246 n = read1(in);
cannam@128 247 n += (unsigned)(read1(in)) << 8;
cannam@128 248 skip(in, n);
cannam@128 249 }
cannam@128 250 if (flags & 8) while (read1(in) != 0) ;
cannam@128 251 if (flags & 16) while (read1(in) != 0) ;
cannam@128 252 if (flags & 2) skip(in, 2);
cannam@128 253 }
cannam@128 254
cannam@128 255 /* decompress gzip file "name", return strm with a deflate stream ready to
cannam@128 256 continue compression of the data in the gzip file, and return a file
cannam@128 257 descriptor pointing to where to write the compressed data -- the deflate
cannam@128 258 stream is initialized to compress using level "level" */
cannam@128 259 local int gzscan(char *name, z_stream *strm, int level)
cannam@128 260 {
cannam@128 261 int ret, lastbit, left, full;
cannam@128 262 unsigned have;
cannam@128 263 unsigned long crc, tot;
cannam@128 264 unsigned char *window;
cannam@128 265 off_t lastoff, end;
cannam@128 266 file gz;
cannam@128 267
cannam@128 268 /* open gzip file */
cannam@128 269 gz.name = name;
cannam@128 270 gz.fd = open(name, O_RDWR, 0);
cannam@128 271 if (gz.fd == -1) bye("cannot open ", name);
cannam@128 272 gz.buf = malloc(CHUNK);
cannam@128 273 if (gz.buf == NULL) bye("out of memory", "");
cannam@128 274 gz.size = LGCHUNK;
cannam@128 275 gz.left = 0;
cannam@128 276
cannam@128 277 /* skip gzip header */
cannam@128 278 gzheader(&gz);
cannam@128 279
cannam@128 280 /* prepare to decompress */
cannam@128 281 window = malloc(DSIZE);
cannam@128 282 if (window == NULL) bye("out of memory", "");
cannam@128 283 strm->zalloc = Z_NULL;
cannam@128 284 strm->zfree = Z_NULL;
cannam@128 285 strm->opaque = Z_NULL;
cannam@128 286 ret = inflateInit2(strm, -15);
cannam@128 287 if (ret != Z_OK) bye("out of memory", " or library mismatch");
cannam@128 288
cannam@128 289 /* decompress the deflate stream, saving append information */
cannam@128 290 lastbit = 0;
cannam@128 291 lastoff = lseek(gz.fd, 0L, SEEK_CUR) - gz.left;
cannam@128 292 left = 0;
cannam@128 293 strm->avail_in = gz.left;
cannam@128 294 strm->next_in = gz.next;
cannam@128 295 crc = crc32(0L, Z_NULL, 0);
cannam@128 296 have = full = 0;
cannam@128 297 do {
cannam@128 298 /* if needed, get more input */
cannam@128 299 if (strm->avail_in == 0) {
cannam@128 300 readmore(&gz);
cannam@128 301 strm->avail_in = gz.left;
cannam@128 302 strm->next_in = gz.next;
cannam@128 303 }
cannam@128 304
cannam@128 305 /* set up output to next available section of sliding window */
cannam@128 306 strm->avail_out = DSIZE - have;
cannam@128 307 strm->next_out = window + have;
cannam@128 308
cannam@128 309 /* inflate and check for errors */
cannam@128 310 ret = inflate(strm, Z_BLOCK);
cannam@128 311 if (ret == Z_STREAM_ERROR) bye("internal stream error!", "");
cannam@128 312 if (ret == Z_MEM_ERROR) bye("out of memory", "");
cannam@128 313 if (ret == Z_DATA_ERROR)
cannam@128 314 bye("invalid compressed data--format violated in", name);
cannam@128 315
cannam@128 316 /* update crc and sliding window pointer */
cannam@128 317 crc = crc32(crc, window + have, DSIZE - have - strm->avail_out);
cannam@128 318 if (strm->avail_out)
cannam@128 319 have = DSIZE - strm->avail_out;
cannam@128 320 else {
cannam@128 321 have = 0;
cannam@128 322 full = 1;
cannam@128 323 }
cannam@128 324
cannam@128 325 /* process end of block */
cannam@128 326 if (strm->data_type & 128) {
cannam@128 327 if (strm->data_type & 64)
cannam@128 328 left = strm->data_type & 0x1f;
cannam@128 329 else {
cannam@128 330 lastbit = strm->data_type & 0x1f;
cannam@128 331 lastoff = lseek(gz.fd, 0L, SEEK_CUR) - strm->avail_in;
cannam@128 332 }
cannam@128 333 }
cannam@128 334 } while (ret != Z_STREAM_END);
cannam@128 335 inflateEnd(strm);
cannam@128 336 gz.left = strm->avail_in;
cannam@128 337 gz.next = strm->next_in;
cannam@128 338
cannam@128 339 /* save the location of the end of the compressed data */
cannam@128 340 end = lseek(gz.fd, 0L, SEEK_CUR) - gz.left;
cannam@128 341
cannam@128 342 /* check gzip trailer and save total for deflate */
cannam@128 343 if (crc != read4(&gz))
cannam@128 344 bye("invalid compressed data--crc mismatch in ", name);
cannam@128 345 tot = strm->total_out;
cannam@128 346 if ((tot & 0xffffffffUL) != read4(&gz))
cannam@128 347 bye("invalid compressed data--length mismatch in", name);
cannam@128 348
cannam@128 349 /* if not at end of file, warn */
cannam@128 350 if (gz.left || readin(&gz))
cannam@128 351 fprintf(stderr,
cannam@128 352 "gzappend warning: junk at end of gzip file overwritten\n");
cannam@128 353
cannam@128 354 /* clear last block bit */
cannam@128 355 lseek(gz.fd, lastoff - (lastbit != 0), SEEK_SET);
cannam@128 356 if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name);
cannam@128 357 *gz.buf = (unsigned char)(*gz.buf ^ (1 << ((8 - lastbit) & 7)));
cannam@128 358 lseek(gz.fd, -1L, SEEK_CUR);
cannam@128 359 if (write(gz.fd, gz.buf, 1) != 1) bye("writing after seek to ", name);
cannam@128 360
cannam@128 361 /* if window wrapped, build dictionary from window by rotating */
cannam@128 362 if (full) {
cannam@128 363 rotate(window, DSIZE, have);
cannam@128 364 have = DSIZE;
cannam@128 365 }
cannam@128 366
cannam@128 367 /* set up deflate stream with window, crc, total_in, and leftover bits */
cannam@128 368 ret = deflateInit2(strm, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
cannam@128 369 if (ret != Z_OK) bye("out of memory", "");
cannam@128 370 deflateSetDictionary(strm, window, have);
cannam@128 371 strm->adler = crc;
cannam@128 372 strm->total_in = tot;
cannam@128 373 if (left) {
cannam@128 374 lseek(gz.fd, --end, SEEK_SET);
cannam@128 375 if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name);
cannam@128 376 deflatePrime(strm, 8 - left, *gz.buf);
cannam@128 377 }
cannam@128 378 lseek(gz.fd, end, SEEK_SET);
cannam@128 379
cannam@128 380 /* clean up and return */
cannam@128 381 free(window);
cannam@128 382 free(gz.buf);
cannam@128 383 return gz.fd;
cannam@128 384 }
cannam@128 385
cannam@128 386 /* append file "name" to gzip file gd using deflate stream strm -- if last
cannam@128 387 is true, then finish off the deflate stream at the end */
cannam@128 388 local void gztack(char *name, int gd, z_stream *strm, int last)
cannam@128 389 {
cannam@128 390 int fd, len, ret;
cannam@128 391 unsigned left;
cannam@128 392 unsigned char *in, *out;
cannam@128 393
cannam@128 394 /* open file to compress and append */
cannam@128 395 fd = 0;
cannam@128 396 if (name != NULL) {
cannam@128 397 fd = open(name, O_RDONLY, 0);
cannam@128 398 if (fd == -1)
cannam@128 399 fprintf(stderr, "gzappend warning: %s not found, skipping ...\n",
cannam@128 400 name);
cannam@128 401 }
cannam@128 402
cannam@128 403 /* allocate buffers */
cannam@128 404 in = malloc(CHUNK);
cannam@128 405 out = malloc(CHUNK);
cannam@128 406 if (in == NULL || out == NULL) bye("out of memory", "");
cannam@128 407
cannam@128 408 /* compress input file and append to gzip file */
cannam@128 409 do {
cannam@128 410 /* get more input */
cannam@128 411 len = read(fd, in, CHUNK);
cannam@128 412 if (len == -1) {
cannam@128 413 fprintf(stderr,
cannam@128 414 "gzappend warning: error reading %s, skipping rest ...\n",
cannam@128 415 name);
cannam@128 416 len = 0;
cannam@128 417 }
cannam@128 418 strm->avail_in = (unsigned)len;
cannam@128 419 strm->next_in = in;
cannam@128 420 if (len) strm->adler = crc32(strm->adler, in, (unsigned)len);
cannam@128 421
cannam@128 422 /* compress and write all available output */
cannam@128 423 do {
cannam@128 424 strm->avail_out = CHUNK;
cannam@128 425 strm->next_out = out;
cannam@128 426 ret = deflate(strm, last && len == 0 ? Z_FINISH : Z_NO_FLUSH);
cannam@128 427 left = CHUNK - strm->avail_out;
cannam@128 428 while (left) {
cannam@128 429 len = write(gd, out + CHUNK - strm->avail_out - left, left);
cannam@128 430 if (len == -1) bye("writing gzip file", "");
cannam@128 431 left -= (unsigned)len;
cannam@128 432 }
cannam@128 433 } while (strm->avail_out == 0 && ret != Z_STREAM_END);
cannam@128 434 } while (len != 0);
cannam@128 435
cannam@128 436 /* write trailer after last entry */
cannam@128 437 if (last) {
cannam@128 438 deflateEnd(strm);
cannam@128 439 out[0] = (unsigned char)(strm->adler);
cannam@128 440 out[1] = (unsigned char)(strm->adler >> 8);
cannam@128 441 out[2] = (unsigned char)(strm->adler >> 16);
cannam@128 442 out[3] = (unsigned char)(strm->adler >> 24);
cannam@128 443 out[4] = (unsigned char)(strm->total_in);
cannam@128 444 out[5] = (unsigned char)(strm->total_in >> 8);
cannam@128 445 out[6] = (unsigned char)(strm->total_in >> 16);
cannam@128 446 out[7] = (unsigned char)(strm->total_in >> 24);
cannam@128 447 len = 8;
cannam@128 448 do {
cannam@128 449 ret = write(gd, out + 8 - len, len);
cannam@128 450 if (ret == -1) bye("writing gzip file", "");
cannam@128 451 len -= ret;
cannam@128 452 } while (len);
cannam@128 453 close(gd);
cannam@128 454 }
cannam@128 455
cannam@128 456 /* clean up and return */
cannam@128 457 free(out);
cannam@128 458 free(in);
cannam@128 459 if (fd > 0) close(fd);
cannam@128 460 }
cannam@128 461
cannam@128 462 /* process the compression level option if present, scan the gzip file, and
cannam@128 463 append the specified files, or append the data from stdin if no other file
cannam@128 464 names are provided on the command line -- the gzip file must be writable
cannam@128 465 and seekable */
cannam@128 466 int main(int argc, char **argv)
cannam@128 467 {
cannam@128 468 int gd, level;
cannam@128 469 z_stream strm;
cannam@128 470
cannam@128 471 /* ignore command name */
cannam@128 472 argc--; argv++;
cannam@128 473
cannam@128 474 /* provide usage if no arguments */
cannam@128 475 if (*argv == NULL) {
cannam@128 476 printf(
cannam@128 477 "gzappend 1.2 (11 Oct 2012) Copyright (C) 2003, 2012 Mark Adler\n"
cannam@128 478 );
cannam@128 479 printf(
cannam@128 480 "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n");
cannam@128 481 return 0;
cannam@128 482 }
cannam@128 483
cannam@128 484 /* set compression level */
cannam@128 485 level = Z_DEFAULT_COMPRESSION;
cannam@128 486 if (argv[0][0] == '-') {
cannam@128 487 if (argv[0][1] < '0' || argv[0][1] > '9' || argv[0][2] != 0)
cannam@128 488 bye("invalid compression level", "");
cannam@128 489 level = argv[0][1] - '0';
cannam@128 490 if (*++argv == NULL) bye("no gzip file name after options", "");
cannam@128 491 }
cannam@128 492
cannam@128 493 /* prepare to append to gzip file */
cannam@128 494 gd = gzscan(*argv++, &strm, level);
cannam@128 495
cannam@128 496 /* append files on command line, or from stdin if none */
cannam@128 497 if (*argv == NULL)
cannam@128 498 gztack(NULL, gd, &strm, 1);
cannam@128 499 else
cannam@128 500 do {
cannam@128 501 gztack(*argv, gd, &strm, argv[1] == NULL);
cannam@128 502 } while (*++argv != NULL);
cannam@128 503 return 0;
cannam@128 504 }