*** old/gzip.c Thu Aug 19 15:39:43 1993 --- ./gzip.c Fri Apr 24 18:29:52 1999 *************** *** 304,309 **** --- 304,313 ---- #define strequ(s1, s2) (strcmp((s1),(s2)) == 0) + #define EOF_ (-1) + #define WARNING_ (-2) + #define ERROR_ (-3) + /* ======================================================================== */ local void usage() { *************** *** 628,639 **** fprintf(stderr,"For help, type: %s -h\n", progname); do_exit(ERROR); } if (decompress || !ascii) { ! SET_BINARY_MODE(fileno(stdin)); } if (!test && !list && (!decompress || !ascii)) { ! SET_BINARY_MODE(fileno(stdout)); } strcpy(ifname, "stdin"); strcpy(ofname, "stdout"); --- 632,645 ---- fprintf(stderr,"For help, type: %s -h\n", progname); do_exit(ERROR); } + ifd = fileno(stdin); + ofd = fileno(stdout); if (decompress || !ascii) { ! SET_BINARY_MODE(ifd); } if (!test && !list && (!decompress || !ascii)) { ! SET_BINARY_MODE(ofd); } strcpy(ifname, "stdin"); strcpy(ofname, "stdout"); *************** *** 650,657 **** if (S_ISREG(istat.st_mode)) # endif time_stamp = istat.st_mtime; - #endif /* NO_STDIN_FSTAT */ } ifile_size = -1L; /* convention for unknown size */ clear_bufs(); /* clear input and output buffers */ --- 656,663 ---- if (S_ISREG(istat.st_mode)) # endif time_stamp = istat.st_mtime; } + #endif /* NO_STDIN_FSTAT */ ifile_size = -1L; /* convention for unknown size */ clear_bufs(); /* clear input and output buffers */ *************** *** 672,684 **** /* Actually do the compression/decompression. Loop over zipped members. */ for (;;) { ! if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; ! if (!decompress || last_member || inptr == insize) break; /* end of file */ method = get_method(ifd); ! if (method < 0) return; /* error message already emitted */ bytes_out = 0; /* required for length check */ } --- 678,691 ---- /* Actually do the compression/decompression. Loop over zipped members. */ for (;;) { ! if ((*work)(ifd, ofd) != OK) return; ! if (!decompress || last_member) break; /* end of file */ method = get_method(ifd); ! if (method == ERROR_) return; /* error message already emitted */ ! if (method < 0) break; bytes_out = 0; /* required for length check */ } *************** *** 696,701 **** --- 703,712 ---- #endif } } + if (decompress && method == WARNING_) { + WARN((stderr, "%s: decompression OK, trailing garbage ignored\n", + progname)); + } } /* ======================================================================== *************** *** 812,821 **** */ for (;;) { if ((*work)(ifd, ofd) != OK) { ! method = -1; /* force cleanup */ break; } ! if (!decompress || last_member || inptr == insize) break; /* end of file */ method = get_method(ifd); --- 823,832 ---- */ for (;;) { if ((*work)(ifd, ofd) != OK) { ! method = ERROR_; /* force cleanup */ break; } ! if (!decompress || last_member) break; /* end of file */ method = get_method(ifd); *************** *** 827,833 **** if (!to_stdout && close(ofd)) { write_error(); } ! if (method == -1) { if (!to_stdout) unlink (ofname); return; } --- 838,844 ---- if (!to_stdout && close(ofd)) { write_error(); } ! if (method == ERROR_) { if (!to_stdout) unlink (ofname); return; } *************** *** 845,850 **** --- 856,866 ---- } fprintf(stderr, "\n"); } + if (decompress && method == WARNING_) { + WARN((stderr, "%s: %s: decompression OK, trailing garbage ignored\n", + progname, ifname)); + } + /* Copy modes, times, ownership, and remove the input file */ if (!to_stdout) { copy_stat(&istat); *************** *** 1153,1172 **** { uch flags; /* compression flags */ char magic[2]; /* magic header */ ulg stamp; /* time stamp */ /* If --force and --stdout, zcat == cat, so do not complain about ! * premature end of file: use try_byte instead of get_byte. */ ! if (force && to_stdout) { ! magic[0] = (char)try_byte(); magic[1] = (char)try_byte(); /* If try_byte returned EOF, magic[1] == 0xff */ } else { magic[0] = (char)get_byte(); magic[1] = (char)get_byte(); } ! method = -1; /* unknown yet */ part_nb++; /* number of parts in gzip file */ header_bytes = 0; last_member = RECORD_IO; --- 1169,1194 ---- { uch flags; /* compression flags */ char magic[2]; /* magic header */ + int first_byte; ulg stamp; /* time stamp */ /* If --force and --stdout, zcat == cat, so do not complain about ! * premature end of file: use try_byte instead of get_byte. Also, if we ! * have already decompressed one part, do not complain about EOF. */ ! if (part_nb > 0 || (force && to_stdout && !list & !test)) { ! first_byte = try_byte(); ! if (part_nb > 0 && (first_byte == EOF || first_byte == '\0')) { ! return EOF_; ! } ! magic[0] = (char)first_byte; magic[1] = (char)try_byte(); /* If try_byte returned EOF, magic[1] == 0xff */ } else { magic[0] = (char)get_byte(); magic[1] = (char)get_byte(); } ! method = ERROR_; /* unknown yet */ part_nb++; /* number of parts in gzip file */ header_bytes = 0; last_member = RECORD_IO; *************** *** 1181,1187 **** "%s: %s: unknown method %d -- get newer version of gzip\n", progname, ifname, method); exit_code = ERROR; ! return -1; } work = unzip; flags = (uch)get_byte(); --- 1203,1209 ---- "%s: %s: unknown method %d -- get newer version of gzip\n", progname, ifname, method); exit_code = ERROR; ! return ERROR_; } work = unzip; flags = (uch)get_byte(); *************** *** 1205,1211 **** "%s: %s has flags 0x%x -- get newer version of gzip\n", progname, ifname, flags); exit_code = ERROR; ! if (force <= 1) return -1; } stamp = (ulg)get_byte(); stamp |= ((ulg)get_byte()) << 8; --- 1227,1233 ---- "%s: %s has flags 0x%x -- get newer version of gzip\n", progname, ifname, flags); exit_code = ERROR; ! if (force <= 1) return ERROR_; } stamp = (ulg)get_byte(); stamp |= ((ulg)get_byte()) << 8; *************** *** 1274,1280 **** */ inptr = 0; work = unzip; ! if (check_zipfile(in) != OK) return -1; /* check_zipfile may get ofname from the local header */ last_member = 1; --- 1296,1302 ---- */ inptr = 0; work = unzip; ! if (check_zipfile(in) != OK) return ERROR_; /* check_zipfile may get ofname from the local header */ last_member = 1; *************** *** 1292,1298 **** method = LZHED; last_member = 1; ! } else if (force && to_stdout && !list) { /* pass input unchanged */ method = STORED; work = copy; inptr = 0; --- 1314,1320 ---- method = LZHED; last_member = 1; ! } else if (force && to_stdout && !list && !test) { /* straight copy */ method = STORED; work = copy; inptr = 0; *************** *** 1303,1313 **** if (part_nb == 1) { fprintf(stderr, "\n%s: %s: not in gzip format\n", progname, ifname); exit_code = ERROR; ! return -1; } else { ! WARN((stderr, "\n%s: %s: decompression OK, trailing garbage ignored\n", ! progname, ifname)); ! return -2; } } --- 1325,1333 ---- if (part_nb == 1) { fprintf(stderr, "\n%s: %s: not in gzip format\n", progname, ifname); exit_code = ERROR; ! return ERROR_; } else { ! return WARNING_; /* warning message will be displayed by caller */ } }