/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* zmethod -- detect compressed tar files for on-the-fly decompression. * * Derived from GNU Zip program, Copyright (C) 1992-1993 Jean-loup Gailly * The unzip code was written and put in the public domain by Mark Adler. * Portions of the lzw code are derived from the public domain 'compress' * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, * Ken Turkowski, Dave Mack and Peter Jannesen. * * Adaptation to DJTAR program: Eli Zaretskii, November 1995 */ /* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the GNU General Public License for full details. Everyone is granted permission to copy, modify and redistribute this software, but only under the conditions described in the GNU General Public License. A copy of this license is supposed to have been given to you along with this software so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ #include "tailor.h" #include "zread.h" #include "lzw.h" /* global buffers */ uch inbuf[INBUFSIZ + INBUF_EXTRA]; uch outbuf[OUTBUFSIZ+OUTBUF_EXTRA]; ush d_buf[DIST_BUFSIZE]; uch window[2L*WSIZE]; ush tab_prefix[1L<= orig_name + sizeof(orig_name)) { error("corrupted input -- file name too large"); } } } /* ORIG_NAME */ /* Discard file comment if any */ if ((flags & COMMENT) != 0) { while (get_char() != 0) /* null */ ; } if (part_nb == 1) { header_bytes = inptr + 2*sizeof(long); /* include crc and size */ } } else if (memcmp(magic, PKZIP_MAGIC, 2) == 0 && inptr == 2 && memcmp((char*)inbuf, PKZIP_MAGIC, 4) == 0) { /* To simplify the code, we support a zip file when alone only. * We are thus guaranteed that the entire local header fits in inbuf. */ inptr = 0; decompressor = unzip; if (check_zipfile() != OK) return -1; /* check_zipfile may get ofname from the local header */ last_member = 1; } else if (memcmp(magic, PACK_MAGIC, 2) == 0) { decompressor = unpack; method = PACKED; } else if (memcmp(magic, LZW_MAGIC, 2) == 0) { decompressor = unlzw; method = COMPRESSED; last_member = 1; } else if (memcmp(magic, LZH_MAGIC, 2) == 0) { decompressor = unlzh; method = LZHED; last_member = 1; } else if (part_nb == 1) { /* pass input unchanged by default */ method = STORED; decompressor = copy; inptr = 0; last_member = 1; } if (method >= 0) return method; if (part_nb == 1 && z_switch) { fprintf(log_out, "\n%s: %s: not in gzip format\n", progname, ifname); exit_code = ERROR; return -1; } else { WARN((log_out, "\n%s: %s: decompression OK, trailing garbage ignored\n", progname, ifname)); return -2; } }