2 Copyright (c) 1990-2002 Info-ZIP. All rights reserved.
4 See the accompanying file LICENSE, version 2000-Apr-09 or later
5 (the contents of which are also included in unzip.h) for terms of use.
6 If, for some reason, all these files are missing, the Info-ZIP license
7 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
9 /*---------------------------------------------------------------------------
13 This header file contains private (internal) macros, typedefs, prototypes
14 and global-variable declarations used by all of the UnZip source files.
15 In a prior life it was part of the main unzip.h header, but now it is only
16 included by that header if UNZIP_INTERNAL is defined.
18 ---------------------------------------------------------------------------*/
22 #ifndef __unzpriv_h /* prevent multiple inclusions */
25 /* First thing: Signal all following code that we compile UnZip utilities! */
30 /* GRR 960204: MORE defined here in preparation for removal altogether */
37 /* fUnZip should never need to be reentrant */
45 # ifdef SFX /* fUnZip is NOT the sfx stub! */
51 /* disable support for Deflate64(tm) */
56 /* enable Deflate64(tm) support unless compiling for SFX stub */
57 # if (!defined(USE_DEFLATE64) && !defined(SFX))
58 # define USE_DEFLATE64
62 #if (defined(NO_VMS_TEXT_CONV) || defined(VMS))
67 # if (!defined(VMS_TEXT_CONV) && !defined(SFX))
68 # define VMS_TEXT_CONV
72 #if (defined(DLL) && !defined(REENTRANT))
76 #if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
77 # define DYNAMIC_CRC_TABLE
80 #if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
81 # ifndef DYNALLOC_CRCTAB
82 # define DYNALLOC_CRCTAB
86 /*---------------------------------------------------------------------------
87 OS-dependent configuration for UnZip internals
88 ---------------------------------------------------------------------------*/
90 /* bad or (occasionally?) missing stddef.h: */
91 #if (defined(M_XENIX) || defined(DNIX))
95 #if (defined(M_XENIX) && !defined(M_UNIX)) /* SCO Xenix only, not SCO Unix */
97 # define NO_LIMITS_H /* no limits.h, but MODERN defined */
98 # define NO_UID_GID /* no uid_t/gid_t */
102 #ifdef realix /* Modcomp Real/IX, real-time SysV.3 variant */
104 # define NO_UID_GID /* no uid_t/gid_t */
107 #if (defined(_AIX) && !defined(_ALL_SOURCE))
111 #if defined(apollo) /* defines __STDC__ */
117 # define SHORT_NAMES /* 14-char limitation on path components */
118 /* # define FILENAME_MAX 14 */
119 # define FILENAME_MAX NAME_MAX /* GRR: experiment */
122 #if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
126 #endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
127 #if (defined(M_SYSV) || defined(M_SYS5))
131 #endif /* M_SYSV || M_SYS5 */
132 /* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
133 #if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
137 #endif /* __SVR4 || __svr4__ || sgi || __hpux */
138 #if (defined(LINUX) || defined(__QNX__))
142 #endif /* LINUX || __QNX__ */
144 #if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
145 # if (!defined(BSD) && !defined(SYSV))
148 #endif /* ultrix || __ultrix || bsd4_2 */
149 #if (defined(sun) || defined(pyr) || defined(CONVEX))
150 # if (!defined(BSD) && !defined(SYSV))
153 #endif /* sun || pyr || CONVEX */
155 #ifdef pyr /* Pyramid: has BSD and AT&T "universes" */
158 # define USE_STRINGS_H /* instead of more common string.h */
159 # define ZMEM /* ZMEM now uses bcopy/bzero: not in AT&T universe */
160 # endif /* (AT&T memcpy claimed to be very slow, though) */
161 # define DECLARE_ERRNO
164 /* stat() bug for Borland, VAX C RTL, and Atari ST MiNT on TOS
165 * filesystems: returns 0 for wildcards! (returns 0xffffffff on Minix
166 * filesystem or `U:' drive under Atari MiNT.) Watcom C was previously
167 * included on this list; it would be good to know what version the problem
168 * was fixed at, if it did exist. */
169 #if (defined(__TURBOC__) || defined(VMS) || defined(__MINT__))
170 # define WILD_STAT_BUG
173 /*---------------------------------------------------------------------------
174 OS-dependent includes
175 ---------------------------------------------------------------------------*/
178 # define LONGINT off_t /* Amdahl UTS nonsense ("extended file types") */
180 # define LONGINT long
188 # include <stdlib.h> /* standard library prototypes, malloc(), etc. */
190 typedef size_t extent
;
192 # ifndef AOS_VS /* mostly modern? */
194 # ifdef VAXC /* not fully modern, but does have stdlib.h and void */
199 # endif /* !AOS_VS */
200 typedef unsigned int extent
;
204 #ifndef MINIX /* Minix needs it after all the other includes (?) */
207 #include <ctype.h> /* skip for VMS, to use tolower() function? */
208 #include <errno.h> /* used in mapname() */
210 # include <strings.h> /* strcpy, strcmp, memcpy, index/rindex, etc. */
212 # include <string.h> /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
214 #if (defined(MODERN) && !defined(NO_LIMITS_H))
215 # include <limits.h> /* GRR: EXPERIMENTAL! (can be deleted) */
218 /* this include must be down here for SysV.4, for some reason... */
219 #include <signal.h> /* used in unzip.c, fileio.c */
222 /*---------------------------------------------------------------------------
224 ---------------------------------------------------------------------------*/
227 # define MAIN UZ_EXP UzpMain /* was UzpUnzip */
230 # define REDIRECTC(c) varputchar(__G__ c)
231 # define REDIRECTPRINT(buf,size) varmessage(__G__ buf, size)
232 # define FINISH_REDIRECT() finish_REXX_redirect(__G)
234 # define REDIRECTC(c)
235 # define REDIRECTPRINT(buf,size) 0
236 # define FINISH_REDIRECT() close_redirect(__G)
240 /*---------------------------------------------------------------------------
241 Acorn RISCOS section:
242 ---------------------------------------------------------------------------*/
245 # include "acorn/riscos.h"
248 /*---------------------------------------------------------------------------
250 ---------------------------------------------------------------------------*/
253 # include "amiga/amiga.h"
256 /*---------------------------------------------------------------------------
257 AOS/VS section (somewhat similar to Unix, apparently):
258 ---------------------------------------------------------------------------*/
262 # include "aosvs/aosvs.h"
266 /*---------------------------------------------------------------------------
268 ---------------------------------------------------------------------------*/
276 # define EXE_EXTENSION ".tos"
278 # define DATE_FORMAT DF_DMY
282 # define timezone _timezone
284 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
286 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
291 /*---------------------------------------------------------------------------
293 ---------------------------------------------------------------------------*/
295 #if (defined(__BEOS__) || defined(__HAIKU__))
296 # include <sys/types.h> /* [cjh]: This is pretty much a generic */
297 # include <sys/stat.h> /* POSIX 1003.1 system; see beos/ for */
298 # include <fcntl.h> /* extra code to deal with our extra file */
299 # include <sys/param.h> /* attributes. */
305 # define DATE_FORMAT DF_MDY /* GRR: customize with locale.h somehow? */
308 # define PutNativeEOL *q++ = native(LF);
309 # define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
310 # define SCREENWIDTH 80
311 # define USE_EF_UT_TIME
312 # define SET_DIR_ATTRIB
313 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
316 # define RESTORE_UIDGID
317 # define NO_STRNICMP /* not in the x86 headers at least */
320 # define MAIN main_stub /* now that we're using a wrapper... */
323 /*---------------------------------------------------------------------------
324 Human68k/X680x0 section:
325 ---------------------------------------------------------------------------*/
328 /* DO NOT DEFINE DOS_OS2 HERE! If Human68k is so much */
329 /* like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
337 # include <sys/stat.h>
338 # ifdef HAVE_MBSTRING_H
339 # include <mbstring.h>
341 # ifdef HAVE_MBCTYPE_H
342 # include <mbctype.h>
345 # define _ismbblead(c) (0x80 <= (c) && ((c) < 0xa0 || 0xe0 <= (c)))
349 # define DATE_FORMAT DF_YMD /* Japanese standard */
352 # define PutNativeEOL *q++ = native(LF);
356 # define MAIN main_sfx
360 /*---------------------------------------------------------------------------
362 ---------------------------------------------------------------------------*/
368 /*---------------------------------------------------------------------------
369 MS-DOS, OS/2, FLEXOS section:
370 ---------------------------------------------------------------------------*/
381 #if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
383 # define MSC /* This should work for older MSC, too! */
387 #if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
388 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
389 # include <sys/stat.h>
390 # include <io.h> /* lseek(), open(), setftime(), dup(), creat() */
391 # include <time.h> /* localtime() */
392 # include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
394 # ifdef OS2 /* defined for all OS/2 compilers */
395 # include "os2/os2cfg.h"
398 # include "flexos/flxcfg.h"
400 # include "msdos/doscfg.h"
404 # if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
406 * ARGH. MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
407 * 1970 Jan 1 00:00. So we have to diddle time_t's appropriately: add or
408 * subtract 70 years' worth of seconds; i.e., number of days times 86400;
409 * i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
410 * (25550 + 17 + 1) * 86400 == 2209075200 seconds. We know time_t is an
411 * unsigned long (ulg) on the only system with this bug.
413 # define TIMET_TO_NATIVE(x) (x) += (ulg)2209075200L;
414 # define NATIVE_TO_TIMET(x) (x) -= (ulg)2209075200L;
416 # if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
417 # define timezone _timezone
419 # if (defined(__GO32__) || defined(FLEXOS))
422 # define DIR_END '\\' /* OS uses '\\' as directory separator */
423 # define DIR_END2 '/' /* also check for '/' (RTL may convert) */
428 # define DATE_FORMAT dateformat()
430 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
431 # define USE_EF_UT_TIME
432 #endif /* MSDOS || OS2 || FLEXOS */
434 /*---------------------------------------------------------------------------
435 MTS section (piggybacks UNIX, I think):
436 ---------------------------------------------------------------------------*/
439 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
440 # include <sys/stat.h>
441 # include <sys/file.h> /* MTS uses this instead of fcntl.h */
444 # include <unix.h> /* some important non-ANSI routines */
445 # define mkdir(s,n) (-1) /* no "make directory" capability */
446 # define EBCDIC /* set EBCDIC conversion on */
447 # define NO_STRNICMP /* unzip's is as good the one in MTS */
449 # define close_outfile() fclose(G.outfile) /* can't set time on files */
450 # define umask(n) /* don't have umask() on MTS */
451 # define FOPWT "w" /* open file for writing in TEXT mode */
453 # define DATE_FORMAT DF_MDY
456 # define PutNativeEOL *q++ = native(LF);
459 /*---------------------------------------------------------------------------
461 ---------------------------------------------------------------------------*/
464 # include "novell/nlmcfg.h"
467 /*---------------------------------------------------------------------------
469 ---------------------------------------------------------------------------*/
475 # include <sys/stat.h>
477 # include "qdos/izqdos.h"
479 # define DATE_FORMAT DF_MDY
482 # define PutNativeEOL *q++ = native(LF);
484 # define RETURN QReturn
487 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
490 # define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
491 # define SCREENWIDTH 80
494 /*---------------------------------------------------------------------------
496 ---------------------------------------------------------------------------*/
501 # if (!defined(__INT32) && !defined(INT_16BIT))
502 # define INT_16BIT /* report "int" size is 16-bit to inflate setup */
504 /* use a single LF delimiter so that writes to 101 text files work */
505 # define PutNativeEOL *q++ = native(LF);
508 # define DATE_FORMAT DF_DMY
510 # define SCREENLINES 25
511 /* USE_EF_UT_TIME is set in tandem.h */
512 # define RESTORE_UIDGID
516 /*---------------------------------------------------------------------------
518 ---------------------------------------------------------------------------*/
521 # include "theos/thscfg.h"
524 /*---------------------------------------------------------------------------
526 ---------------------------------------------------------------------------*/
529 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
530 # include <sys/stat.h>
531 # include <sys/param.h>
532 # include <sys/time.h>
533 # include <sys/timeb.h>
534 # include <sys/file.h>
536 # include <monsym.h> /* get amazing monsym() macro */
537 extern int open(), close(), read();
538 extern int stat(), unlink(), jsys(), fcntl();
539 extern long lseek(), dup(), creat();
540 # define strchr index /* GRR: necessary? */
541 # define strrchr rindex
542 # define REALLY_SHORT_SYMS
544 # ifndef HAVE_STRNICMP
545 # define NO_STRNICMP /* probably not provided by TOPS20 C RTL */
549 # define DIR_EXT ".directory"
551 # define DATE_FORMAT DF_MDY
553 # define EXE_EXTENSION ".exe" /* just a guess... */
556 /*---------------------------------------------------------------------------
558 ---------------------------------------------------------------------------*/
561 # include "unix/unxcfg.h"
564 /*---------------------------------------------------------------------------
565 VM/CMS and MVS section:
566 ---------------------------------------------------------------------------*/
570 # define CLOSE_INFILE() close_infile(__G)
573 /*---------------------------------------------------------------------------
575 ---------------------------------------------------------------------------*/
578 # include <types.h> /* GRR: experimenting... */
580 # include <time.h> /* the usual non-BSD time functions */
581 # include <file.h> /* same things as fcntl.h has */
584 # define _MAX_PATH (NAM$C_MAXRSS+1) /* to define FILNAMSIZ below */
585 # ifndef HAVE_STRNICMP /* use our private zstrnicmp() */
586 # define NO_STRNICMP /* unless explicitely overridden */
588 # ifdef RETURN_CODES /* VMS interprets standard PK return codes incorrectly */
589 # define RETURN(ret) return_VMS(__G__ (ret)) /* verbose version */
590 # define EXIT(ret) return_VMS(__G__ (ret))
592 # define RETURN return_VMS /* quiet version */
593 # define EXIT return_VMS
596 # define USAGE(ret) VMSCLI_usage(__G__ (ret))
600 # define DIR_EXT ".dir"
602 # define DATE_FORMAT DF_MDY
605 # define PutNativeEOL *q++ = native(LF);
606 # define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
607 # define SCREENWIDTH 80
608 # define SCREENLWRAP screenlinewrap()
609 # if (defined(__VMS_VERSION) && !defined(VMS_VERSION))
610 # define VMS_VERSION __VMS_VERSION
612 # if (defined(__VMS_VER) && !defined(__CRTL_VER))
613 # define __CRTL_VER __VMS_VER
615 # if ((!defined(__CRTL_VER)) || (__CRTL_VER < 70000000))
616 # define NO_GMTIME /* gmtime() of earlier VMS C RTLs is broken */
618 # if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
619 # define USE_EF_UT_TIME
622 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
625 # define RESTORE_UIDGID
628 /*---------------------------------------------------------------------------
629 Win32 (Windows 95/NT) section:
630 ---------------------------------------------------------------------------*/
632 #if (defined(WIN32) && !defined(POCKET_UNZIP))
633 # include "win32/w32cfg.h"
645 # define UNZIP_VERSION 21 /* compatible with PKUNZIP 4.0 */
647 # define UNZIP_VERSION 20 /* compatible with PKUNZIP 2.0 */
649 #define VMS_UNZIP_VERSION 42 /* if OS-needed-to-extract is VMS: can do */
651 #if (defined(MSDOS) || defined(OS2))
655 #if (defined(OS2) || defined(WIN32))
659 #if (defined(DOS_OS2) || defined(WIN32))
661 # define DOS_W32_OS2 /* historical: don't use */
664 #if (defined(DOS_OS2_W32) || defined(__human68k__))
665 # define DOS_H68_OS2_W32
668 #if (defined(DOS_OS2) || defined(FLEXOS))
672 #if (defined(DOS_OS2_W32) || defined(FLEXOS))
673 # define DOS_FLX_OS2_W32
676 #if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
677 # define DOS_FLX_H68_OS2_W32
680 #if (defined(DOS_FLX_OS2) || defined(NLM))
681 # define DOS_FLX_NLM_OS2
684 #if (defined(DOS_FLX_OS2_W32) || defined(NLM))
685 # define DOS_FLX_NLM_OS2_W32
688 #if (defined(DOS_FLX_H68_OS2_W32) || defined(NLM))
689 # define DOS_FLX_H68_NLM_OS2_W32
692 #if (defined(TOPS20) || defined(VMS))
696 #if (defined(MSDOS) || defined(T20_VMS))
700 #if ((defined(__BEOS__) || defined(__HAIKU__)) || defined(UNIX))
704 #if (defined(BEO_UNX) || defined(THEOS))
708 /* clean up with a few defaults */
710 # define DIR_END '/' /* last char before program name or filename */
713 # define DATE_FORMAT DF_MDY /* defaults to US convention */
716 # define CLOSE_INFILE() close(G.zipfd)
719 # define RETURN return /* only used in main() */
725 # define USAGE(ret) usage(__G__ (ret)) /* used in unzip.c, zipinfo.c */
727 #ifndef TIMET_TO_NATIVE /* everybody but MSC 7.0 and Macintosh */
728 # define TIMET_TO_NATIVE(x)
729 # define NATIVE_TO_TIMET(x)
732 # ifdef WILD_STAT_BUG
733 # define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
740 # define STRNICMP zstrnicmp
742 # define STRNICMP strnicmp
747 #if (defined(DOS_FLX_NLM_OS2_W32) || defined(BEO_UNX) || defined(RISCOS))
752 #if (defined(AOS_VS) || defined(ATARI)) /* GRR: others? */
758 /* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
760 #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
761 # if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
762 # define INT_SPRINTF /* sprintf() returns int: SysVish/Posix */
764 # if (defined(DOS_FLX_NLM_OS2_W32) || defined(VMS) || defined(AMIGA))
765 # define INT_SPRINTF /* sprintf() returns int: ANSI */
767 # if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
768 # if (defined(POSIX) || defined(__POSIX))
769 # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
772 # define PCHAR_SPRINTF /* undetermined actual return value */
775 # if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS) || defined(THEOS))
776 # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
779 # define PCHAR_SPRINTF /* sprintf() returns char *: SunOS cc *and* gcc */
783 /* defaults that we hope will take care of most machines in the future */
785 #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
787 # define INT_SPRINTF /* sprintf() returns int: ANSI */
790 # define PCHAR_SPRINTF /* sprintf() returns char *: BSDish */
794 #define MSG_STDERR(f) (f & 1) /* bit 0: 0 = stdout, 1 = stderr */
795 #define MSG_INFO(f) ((f & 6) == 0) /* bits 1 and 2: 0 = info */
796 #define MSG_WARN(f) ((f & 6) == 2) /* bits 1 and 2: 1 = warning */
797 #define MSG_ERROR(f) ((f & 6) == 4) /* bits 1 and 2: 2 = error */
798 #define MSG_FATAL(f) ((f & 6) == 6) /* bits 1 and 2: (3 = fatal error) */
799 #define MSG_ZFN(f) (f & 0x0008) /* bit 3: 1 = print zipfile name */
800 #define MSG_FN(f) (f & 0x0010) /* bit 4: 1 = print filename */
801 #define MSG_LNEWLN(f) (f & 0x0020) /* bit 5: 1 = leading newline if !SOL */
802 #define MSG_TNEWLN(f) (f & 0x0040) /* bit 6: 1 = trailing newline if !SOL */
803 #define MSG_MNEWLN(f) (f & 0x0080) /* bit 7: 1 = trailing NL for prompts */
804 /* the following are subject to change */
805 #define MSG_NO_WGUI(f) (f & 0x0100) /* bit 8: 1 = skip if Windows GUI */
806 #define MSG_NO_AGUI(f) (f & 0x0200) /* bit 9: 1 = skip if Acorn GUI */
807 #define MSG_NO_DLL2(f) (f & 0x0400) /* bit 10: 1 = skip if OS/2 DLL */
808 #define MSG_NO_NDLL(f) (f & 0x0800) /* bit 11: 1 = skip if WIN32 DLL */
809 #define MSG_NO_WDLL(f) (f & 0x1000) /* bit 12: 1 = skip if Windows DLL */
811 #if (defined(MORE) && !defined(SCREENLINES))
812 # ifdef DOS_FLX_NLM_OS2_W32
813 # define SCREENLINES 25 /* can be (should be) a function instead */
815 # define SCREENLINES 24 /* VT-100s are assumed to be minimal hardware */
818 #if (defined(MORE) && !defined(SCREENSIZE))
820 # define SCREENSIZE(scrrows, scrcols) { \
821 if ((scrrows) != NULL) *(scrrows) = SCREENLINES; }
823 # define SCREENSIZE(scrrows, scrcols) { \
824 if ((scrrows) != NULL) *(scrrows) = SCREENLINES; \
825 if ((scrcols) != NULL) *(scrcols) = SCREENWIDTH; }
829 #define DIR_BLKSIZ 64 /* number of directory entries per block
830 * (should fit in 4096 bytes, usually) */
832 # ifdef USE_DEFLATE64
833 # define WSIZE 65536L /* window size--must be a power of two, and */
834 # else /* at least 64K for PKZip's deflate64 method */
835 # define WSIZE 0x8000 /* window size--must be a power of two, and */
836 # endif /* at least 32K for zip's deflate method */
840 # if (defined(MED_MEM) || defined(SMALL_MEM))
841 # define INBUFSIZ 2048 /* works for MS-DOS small model */
843 # define INBUFSIZ 8192 /* larger buffers for real OSes */
849 # define INT_16BIT /* on 16-bit systems int size is 16 bits */
852 # define nearmalloc malloc
853 # define nearfree free
854 # if (!defined(__IBMC__) || !defined(OS2))
864 #if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
865 # undef DYNALLOC_CRCTAB
868 #if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
869 # undef DYNALLOC_CRCTAB /* not safe with reentrant code */
872 #if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
873 # ifdef DYNALLOC_CRCTAB
874 # undef DYNALLOC_CRCTAB
878 #if (defined(USE_ZLIB) && defined(ASM_CRC))
882 /* Logic for case of small memory, length of EOL > 1: if OUTBUFSIZ == 2048,
883 * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
884 * and transbuf 1040 bytes. Have room for 32 extra EOL chars; 1008/32 == 31.5
885 * chars/line, smaller than estimated 35-70 characters per line for C source
886 * and normal text. Hence difference is sufficient for most "average" files.
887 * (Argument scales for larger OUTBUFSIZ.)
889 #ifdef SMALL_MEM /* i.e., 16-bit OSes: MS-DOS, OS/2 1.x, etc. */
890 # define LoadFarString(x) fLoadFarString(__G__ (x))
891 # define LoadFarStringSmall(x) fLoadFarStringSmall(__G__ (x))
892 # define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
893 # if (defined(_MSC_VER) && (_MSC_VER >= 600))
894 # define zfstrcpy(dest, src) _fstrcpy((dest), (src))
897 # define Far far /* __far only works for MSC 6.00, not 6.0a or Borland */
899 # define OUTBUFSIZ INBUFSIZ
901 # define RAWBUFSIZ (OUTBUFSIZ>>1)
903 # define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
905 # define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
906 typedef short shrint
; /* short/int or "shrink int" (unshrink) */
908 # define zfstrcpy(dest, src) strcpy((dest), (src))
910 # define LoadFarString(x) Qstrfix(x) /* fix up _ for '.' */
911 # define LoadFarStringSmall(x) Qstrfix(x)
912 # define LoadFarStringSmall2(x) Qstrfix(x)
914 # define LoadFarString(x) (char *)(x)
915 # define LoadFarStringSmall(x) (char *)(x)
916 # define LoadFarStringSmall2(x) (char *)(x)
919 # define OUTBUFSIZ 0xFF80 /* can't malloc arrays of 0xFFE8 or more */
920 # define TRANSBUFSIZ 0xFF80
921 typedef short shrint
;
923 # define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
924 # define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
926 typedef short shrint
;
928 typedef int shrint
; /* for efficiency/speed, we hope... */
930 # endif /* ?MED_MEM */
931 # define RAWBUFSIZ OUTBUFSIZ
932 #endif /* ?SMALL_MEM */
942 #ifdef SFX /* disable some unused features for SFX executables */
952 # ifdef CHEAP_SFX_AUTORUN
953 # ifndef NO_SFX_EXDIR
954 # define NO_SFX_EXDIR
957 # ifndef NO_SFX_EXDIR
968 /* user may have defined both by accident... NOTIMESTAMP takes precedence */
969 #if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
973 #if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
974 # define COPYRIGHT_CLEAN
977 #if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
986 # define PIPE_ERROR (errno == EPIPE)
989 /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
991 # define FOPR "r","ctx=stm"
992 # define FOPM "r+","ctx=stm","rfm=fix","mrs=512"
993 # define FOPW "w","ctx=stm","rfm=fix","mrs=512"
997 /* Binary files must be RECFM=F,LRECL=1 for ftell() to get correct pos */
998 /* ...unless byteseek is used. Let's try that for a while. */
999 # define FOPR "rb,byteseek"
1000 # define FOPM "r+b,byteseek"
1002 # define FOPW "wb,recfm=u,lrecl=32760,byteseek" /* New binary files */
1003 # define FOPWE "wb" /* Existing binary files */
1004 # define FOPWT "w,lrecl=133" /* New text files */
1005 # define FOPWTE "w" /* Existing text files */
1007 # define FOPW "wb,recfm=v,lrecl=32760"
1010 #endif /* CMS_MVS */
1012 #ifdef TOPS20 /* TOPS-20 MODERN? You kidding? */
1016 /* Defaults when nothing special has been defined previously. */
1043 #endif /* ?MODERN */
1046 * If <limits.h> exists on most systems, should include that, since it may
1047 * define some or all of the following: NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
1050 #ifdef DOS_FLX_NLM_OS2_W32
1051 # include <limits.h>
1056 # define PATH_MAX MAXPATHLEN /* in <sys/param.h> on some systems */
1059 # define PATH_MAX _MAX_PATH
1061 # if FILENAME_MAX > 255
1062 # define PATH_MAX FILENAME_MAX /* used like PATH_MAX on some systems */
1064 # define PATH_MAX 1024
1066 # endif /* ?_MAX_PATH */
1067 # endif /* ?MAXPATHLEN */
1068 #endif /* !PATH_MAX */
1070 #define FILNAMSIZ PATH_MAX
1072 /* DBCS support for Info-ZIP (mainly for japanese (-: )
1073 * by Yoshioka Tsuneo (QWF00133@nifty.ne.jp,tsuneo-y@is.aist-nara.ac.jp)
1076 # include <locale.h>
1077 /* Multi Byte Character Set */
1078 # define ___MBS_TMP_DEF char *___tmp_ptr;
1079 # define ___TMP_PTR ___tmp_ptr
1080 # define CLEN(ptr) mblen((ZCONST char *)(ptr), MB_CUR_MAX)
1082 # define PREINCSTR(ptr) (ptr += CLEN(ptr))
1084 # define POSTINCSTR(ptr) (___TMP_PTR=(char *)(ptr), PREINCSTR(ptr),___TMP_PTR)
1085 char *plastchar
OF((ZCONST
char *ptr
, extent len
));
1086 # define lastchar(ptr, len) ((int)(unsigned)*plastchar(ptr, len))
1088 # define NEED_UZMBSCHR
1089 # define MBSCHR(str,c) (char *)uzmbschr((ZCONST unsigned char *)(str), c)
1092 # define NEED_UZMBSRCHR
1093 # define MBSRCHR(str,c) (char *)uzmbsrchr((ZCONST unsigned char *)(str), c)
1095 # define SETLOCALE(category, locale) setlocale(category, locale)
1097 # define ___MBS_TMP_DEF
1099 # define CLEN(ptr) 1
1100 # define PREINCSTR(ptr) (++(ptr))
1101 # define POSTINCSTR(ptr) ((ptr)++)
1102 # define plastchar(ptr, len) (&ptr[(len)-1])
1103 # define lastchar(ptr, len) (ptr[(len)-1])
1104 # define MBSCHR(str, c) strchr(str, c)
1105 # define MBSRCHR(str, c) strrchr(str, c)
1106 # define SETLOCALE(category, locale)
1108 #define INCSTR(ptr) PREINCSTR(ptr)
1111 #if (defined(MALLOC_WORK) && !defined(MY_ZCALLOC))
1112 /* Any system without a special calloc function */
1113 # define zcalloc(items, size) \
1114 (zvoid far *)calloc((unsigned)(items), (unsigned)(size))
1115 # define zcfree free
1116 #endif /* MALLOC_WORK && !MY_ZCALLOC */
1118 #ifdef REGULUS /* returns the inode number on success(!)...argh argh argh */
1119 # define stat(p,s) zstat((p),(s))
1122 #if (defined(CRAY) && defined(ZMEM))
1128 # define memcmp(b1,b2,len) bcmp(b2,b1,len)
1129 # define memcpy(dest,src,len) bcopy(src,dest,len)
1130 # define memzero bzero
1132 # define memzero(dest,len) memset(dest,0,len)
1136 # define TRUE 1 /* sort of obvious */
1148 #if (!defined(S_IEXEC) && defined(S_IXUSR))
1149 # define S_IEXEC S_IXUSR
1152 #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
1155 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
1157 #endif /* UNIX && S_IFLNK && !MTS */
1161 # define S_ISDIR(m) (FALSE)
1163 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1168 # define IS_VOLID(m) ((m) & 0x08)
1172 #ifdef SHORT_SYMS /* Mark Williams C, ...? */
1173 # define extract_or_test_files xtr_or_tst_files
1174 # define extract_or_test_member xtr_or_tst_member
1177 #ifdef REALLY_SHORT_SYMS /* TOPS-20 linker: first 6 chars */
1178 # define process_cdir_file_hdr XXpcdfh
1179 # define process_local_file_hdr XXplfh
1180 # define extract_or_test_files XXxotf /* necessary? */
1181 # define extract_or_test_member XXxotm /* necessary? */
1182 # define check_for_newer XXcfn
1183 # define overwrite_all XXoa
1184 # define process_all_files XXpaf
1185 # define extra_field XXef
1186 # define explode_lit8 XXel8
1187 # define explode_lit4 XXel4
1188 # define explode_nolit8 XXnl8
1189 # define explode_nolit4 XXnl4
1190 # define cpdist8 XXcpdist8
1191 # define inflate_codes XXic
1192 # define inflate_stored XXis
1193 # define inflate_fixed XXif
1194 # define inflate_dynamic XXid
1195 # define inflate_block XXib
1196 # define maxcodemax XXmax
1199 #ifndef S_TIME_T_MAX /* max value of signed (>= 32-bit) time_t */
1200 # define S_TIME_T_MAX ((time_t)(ulg)0x7fffffffL)
1202 #ifndef U_TIME_T_MAX /* max value of unsigned (>= 32-bit) time_t */
1203 # define U_TIME_T_MAX ((time_t)(ulg)0xffffffffL)
1205 #ifdef DOSTIME_MINIMUM /* min DOSTIME value (1980-01-01) */
1206 # undef DOSTIME_MINIMUM
1208 #define DOSTIME_MINIMUM ((ulg)0x00210000L)
1209 #ifdef DOSTIME_2038_01_18 /* approximate DOSTIME equivalent of */
1210 # undef DOSTIME_2038_01_18 /* the signed-32-bit time_t limit */
1212 #define DOSTIME_2038_01_18 ((ulg)0x74320000L)
1215 # define ZSUFX "_zip"
1216 # define ALT_ZSUFX ".zip"
1219 # define ZSUFX "/zip"
1221 # define ZSUFX ".zip"
1223 # define ALT_ZSUFX ".ZIP" /* Unix-only so far (only case-sensitive fs) */
1226 #define CENTRAL_HDR_SIG "\001\002" /* the infamous "PK" signature bytes, */
1227 #define LOCAL_HDR_SIG "\003\004" /* sans "PK" (so unzip executable not */
1228 #define END_CENTRAL_SIG "\005\006" /* mistaken for zipfile itself) */
1229 #define EXTD_LOCAL_SIG "\007\010" /* [ASCII "\113" == EBCDIC "\080" ??] */
1231 /** internal-only return codes **/
1232 #define IZ_DIR 76 /* potential zipfile is a directory */
1233 /* special return codes for mapname() */
1234 #define MPN_OK 0 /* mapname successful */
1235 #define MPN_INF_TRUNC 1<<8 /* caution - filename truncated */
1236 #define MPN_INF_SKIP 2<<8 /* info - skipped because nothing to do */
1237 #define MPN_ERR_SKIP 3<<8 /* error - entry skipped */
1238 #define MPN_ERR_TOOLONG 4<<8 /* error - path too long */
1239 #define MPN_NOMEM 10<<8 /* error - out of memory, file skipped */
1240 #define MPN_CREATED_DIR 16<<8 /* directory created: set time & permissions */
1241 #define MPN_VOL_LABEL 17<<8 /* volume label, but can't set on hard disk */
1242 #define MPN_INVALID 99<<8 /* internal logic error, should never reach */
1243 /* mask for internal mapname&checkdir return codes */
1244 #define MPN_MASK 0x7F00
1245 /* error code for extracting/testing extra field blocks */
1246 #define IZ_EF_TRUNC 79 /* local extra field truncated (PKZIP'd) */
1248 /* choice of activities for do_string() */
1249 #define SKIP 0 /* skip header block */
1250 #define DISPLAY 1 /* display archive comment (ASCII) */
1251 #define DISPL_8 5 /* display file comment (ext. ASCII) */
1252 #define DS_FN 2 /* read filename (ext. ASCII, chead) */
1253 #define DS_FN_C 2 /* read filename from central header */
1254 #define DS_FN_L 6 /* read filename from local header */
1255 #define EXTRA_FIELD 3 /* copy extra field into buffer */
1258 # define FILENOTE 4 /* convert file comment to filenote */
1260 #if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
1261 # define CHECK_AUTORUN 7 /* copy command, display remainder */
1262 # define CHECK_AUTORUN_Q 8 /* copy command, skip remainder */
1265 #define DOES_NOT_EXIST -1 /* return values for check_for_newer() */
1266 #define EXISTS_AND_OLDER 0
1267 #define EXISTS_AND_NEWER 1
1269 #define OVERWRT_QUERY 0 /* status values for G.overwrite_mode */
1270 #define OVERWRT_ALWAYS 1
1271 #define OVERWRT_NEVER 2
1273 #define IS_OVERWRT_ALL (G.overwrite_mode == OVERWRT_ALWAYS)
1274 #define IS_OVERWRT_NONE (G.overwrite_mode == OVERWRT_NEVER)
1276 #define ROOT 0 /* checkdir() extract-to path: called once */
1277 #define INIT 1 /* allocate buildpath: called once per member */
1278 #define APPEND_DIR 2 /* append a dir comp.: many times per member */
1279 #define APPEND_NAME 3 /* append actual filename: once per member */
1280 #define GETPATH 4 /* retrieve the complete path and free it */
1281 #define END 5 /* free root path prior to exiting program */
1283 /* version_made_by codes (central dir): make sure these */
1284 /* are not defined on their respective systems!! */
1285 #define FS_FAT_ 0 /* filesystem used by MS-DOS, OS/2, Win32 */
1290 #define ATARI_ 5 /* what if it's a minix filesystem? [cjh] */
1291 #define FS_HPFS_ 6 /* filesystem used by OS/2 (and NT 3.x) */
1292 #define MAC_ 7 /* HFS filesystem used by MacOS */
1296 #define FS_NTFS_ 11 /* filesystem used by Windows NT */
1298 #define ACORN_ 13 /* Archimedes Acorn RISC OS */
1299 #define FS_VFAT_ 14 /* filesystem used by Windows 95, NT */
1301 #define BEOS_ 16 /* hybrid POSIX/database filesystem */
1302 #define TANDEM_ 17 /* Tandem NSK */
1303 #define THEOS_ 18 /* THEOS */
1304 #define NUM_HOSTS 19 /* index of last system + 1 */
1306 #define STORED 0 /* compression methods */
1315 #define ENHDEFLATED 9
1316 #define DCLIMPLODED 10
1317 #define NUM_METHODS 11 /* index of last method + 1 */
1318 /* don't forget to update list_files(), extract.c and zipinfo.c appropriately
1319 * if NUM_METHODS changes */
1321 /* (the PK-class error codes are public and have been moved into unzip.h) */
1323 #define DF_MDY 0 /* date format 10/26/91 (USA only) */
1324 #define DF_DMY 1 /* date format 26/10/91 (most of the world) */
1325 #define DF_YMD 2 /* date format 91/10/26 (a few countries) */
1327 /*---------------------------------------------------------------------------
1328 Extra-field block ID values and offset info.
1329 ---------------------------------------------------------------------------*/
1330 /* extra-field ID values, all little-endian: */
1331 #define EF_PKSZ64 0x0001 /* PKWARE's 64-bit filesize extensions */
1332 #define EF_AV 0x0007 /* PKWARE's authenticity verification */
1333 #define EF_OS2 0x0009 /* OS/2 extended attributes */
1334 #define EF_PKW32 0x000a /* PKWARE's Win95/98/WinNT filetimes */
1335 #define EF_PKVMS 0x000c /* PKWARE's VMS */
1336 #define EF_PKUNIX 0x000d /* PKWARE's Unix */
1337 #define EF_IZVMS 0x4d49 /* Info-ZIP's VMS ("IM") */
1338 #define EF_IZUNIX 0x5855 /* Info-ZIP's old Unix[1] ("UX") */
1339 #define EF_IZUNIX2 0x7855 /* Info-ZIP's new Unix[2] ("Ux") */
1340 #define EF_TIME 0x5455 /* universal timestamp ("UT") */
1341 #define EF_MAC3 0x334d /* Info-ZIP's new Macintosh (= "M3") */
1342 #define EF_JLMAC 0x07c8 /* Johnny Lee's old Macintosh (= 1992) */
1343 #define EF_ZIPIT 0x2605 /* Thomas Brown's Macintosh (ZipIt) */
1344 #define EF_ZIPIT2 0x2705 /* T. Brown's Mac (ZipIt) v 1.3.8 and newer ? */
1345 #define EF_SMARTZIP 0x4d63 /* Mac SmartZip by Marco Bambini */
1346 #define EF_VMCMS 0x4704 /* Info-ZIP's VM/CMS ("\004G") */
1347 #define EF_MVS 0x470f /* Info-ZIP's MVS ("\017G") */
1348 #define EF_ACL 0x4c41 /* (OS/2) access control list ("AL") */
1349 #define EF_NTSD 0x4453 /* NT security descriptor ("SD") */
1350 #define EF_BEOS 0x6542 /* BeOS ("Be") */
1351 #define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
1352 #define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
1353 #define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
1354 #define EF_TANDEM 0x4154 /* Tandem NSK ("TA") */
1355 #define EF_THEOS 0x6854 /* Jean-Michel Dubois' Theos "Th" */
1356 #define EF_THEOSO 0x4854 /* old Theos port */
1357 #define EF_MD5 0x4b46 /* Fred Kantor's MD5 ("FK") */
1358 #define EF_ASIUNIX 0x756e /* ASi's Unix ("nu") */
1360 #define EB_HEADSIZE 4 /* length of extra field block header */
1361 #define EB_ID 0 /* offset of block ID in header */
1362 #define EB_LEN 2 /* offset of data length field in header */
1363 #define EB_UCSIZE_P 0 /* offset of ucsize field in compr. data */
1364 #define EB_CMPRHEADLEN 6 /* lenght of compression header */
1366 #define EB_UX_MINLEN 8 /* minimal "UX" field contains atime, mtime */
1367 #define EB_UX_FULLSIZE 12 /* full "UX" field (atime, mtime, uid, gid) */
1368 #define EB_UX_ATIME 0 /* offset of atime in "UX" extra field data */
1369 #define EB_UX_MTIME 4 /* offset of mtime in "UX" extra field data */
1370 #define EB_UX_UID 8 /* byte offset of UID in "UX" field data */
1371 #define EB_UX_GID 10 /* byte offset of GID in "UX" field data */
1373 #define EB_UX2_MINLEN 4 /* minimal "Ux" field contains UID/GID */
1374 #define EB_UX2_UID 0 /* byte offset of UID in "Ux" field data */
1375 #define EB_UX2_GID 2 /* byte offset of GID in "Ux" field data */
1376 #define EB_UX2_VALID (1 << 8) /* UID/GID present */
1378 #define EB_UT_MINLEN 1 /* minimal UT field contains Flags byte */
1379 #define EB_UT_FLAGS 0 /* byte offset of Flags field */
1380 #define EB_UT_TIME1 1 /* byte offset of 1st time value */
1381 #define EB_UT_FL_MTIME (1 << 0) /* mtime present */
1382 #define EB_UT_FL_ATIME (1 << 1) /* atime present */
1383 #define EB_UT_FL_CTIME (1 << 2) /* ctime present */
1385 #define EB_FLGS_OFFS 4 /* offset of flags area in generic compressed
1386 extra field blocks (BEOS, MAC, and others) */
1387 #define EB_OS2_HLEN 4 /* size of OS2/ACL compressed data header */
1388 #define EB_BEOS_HLEN 5 /* length of BeOS e.f attribute header */
1389 #define EB_BE_FL_UNCMPR 0x01 /* "BeOS attributes uncompressed" bit flag */
1390 #define EB_MAC3_HLEN 14 /* length of Mac3 attribute block header */
1391 #define EB_SMARTZIP_HLEN 64 /* fixed length of the SmartZip extra field */
1392 #define EB_M3_FL_DATFRK 0x01 /* "this entry is data fork" flag */
1393 #define EB_M3_FL_UNCMPR 0x04 /* "Mac3 attributes uncompressed" bit flag */
1394 #define EB_M3_FL_TIME64 0x08 /* "Mac3 time fields are 64 bit wide" flag */
1395 #define EB_M3_FL_NOUTC 0x10 /* "Mac3 timezone offset fields missing" flag */
1397 #define EB_NTSD_C_LEN 4 /* length of central NT security data */
1398 #define EB_NTSD_L_LEN 5 /* length of minimal local NT security data */
1399 #define EB_NTSD_VERSION 4 /* offset of NTSD version byte */
1400 #define EB_NTSD_MAX_VER (0) /* maximum version # we know how to handle */
1402 #define EB_ASI_CRC32 0 /* offset of ASI Unix field's crc32 checksum */
1403 #define EB_ASI_MODE 4 /* offset of ASI Unix permission mode field */
1405 #define EB_IZVMS_HLEN 12 /* length of IZVMS attribute block header */
1406 #define EB_IZVMS_FLGS 4 /* offset of compression type flag */
1407 #define EB_IZVMS_UCSIZ 6 /* offset of ucsize field in IZVMS header */
1408 #define EB_IZVMS_BCMASK 07 /* 3 bits for compression type */
1409 #define EB_IZVMS_BCSTOR 0 /* Stored */
1410 #define EB_IZVMS_BC00 1 /* 0byte -> 0bit compression */
1411 #define EB_IZVMS_BCDEFL 2 /* Deflated */
1414 /*---------------------------------------------------------------------------
1415 True sizes of the various headers, as defined by PKWARE--so it is not
1416 likely that these will ever change. But if they do, make sure both these
1417 defines AND the typedefs below get updated accordingly.
1418 ---------------------------------------------------------------------------*/
1419 #define LREC_SIZE 26 /* lengths of local file headers, central */
1420 #define CREC_SIZE 42 /* directory headers, and the end-of- */
1421 #define ECREC_SIZE 18 /* central-dir record, respectively */
1423 #define MAX_BITS 13 /* used in unshrink() */
1424 #define HSIZE (1 << MAX_BITS) /* size of global work area */
1426 #define LF 10 /* '\n' on ASCII machines; must be 10 due to EBCDIC */
1427 #define CR 13 /* '\r' on ASCII machines; must be 13 due to EBCDIC */
1428 #define CTRLZ 26 /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
1431 # define foreign(c) ascii[(uch)(c)]
1432 # define native(c) ebcdic[(uch)(c)]
1433 # define NATIVE "EBCDIC"
1438 # define ENV_UNZIP "UNZIP_OPTS" /* names of environment variables */
1439 # define ENV_ZIPINFO "ZIPINFO_OPTS"
1442 # define ENV_UNZIP "Unzip$Options"
1443 # define ENV_ZIPINFO "Zipinfo$Options"
1444 # define ENV_UNZIPEXTS "Unzip$Exts"
1447 # define ENV_UNZIP "UNZIP" /* the standard names */
1448 # define ENV_ZIPINFO "ZIPINFO"
1450 #define ENV_UNZIP2 "UNZIPOPT" /* alternate names, for zip compat. */
1451 #define ENV_ZIPINFO2 "ZIPINFOOPT"
1453 #if (!defined(QQ) && !defined(NOQQ))
1457 #ifdef QQ /* Newtware version: no file */
1458 # define QCOND (!uO.qflag) /* comments with -vq or -vqq */
1459 #else /* Bill Davidsen version: no way to */
1460 # define QCOND (longhdr) /* kill file comments when listing */
1464 # define QCOND2 (uO.qflag < 2)
1466 # define QCOND2 (!uO.qflag)
1479 typedef unsigned short uid_t
; /* TI SysV.3 */
1480 typedef unsigned short gid_t
;
1482 typedef unsigned int uid_t
; /* SCO Xenix */
1483 typedef unsigned int gid_t
;
1487 #if (defined(GOT_UTIMBUF) || defined(sgi) || defined(ATARI))
1488 typedef struct utimbuf ztimbuf
;
1490 typedef struct ztimbuf
{
1491 time_t actime
; /* new access time */
1492 time_t modtime
; /* new modification time */
1496 typedef struct iztimes
{
1497 time_t atime
; /* new access time */
1498 time_t mtime
; /* new modification time */
1499 time_t ctime
; /* used for creation time; NOT same as st_ctime */
1502 #ifdef SET_DIR_ATTRIB
1503 typedef struct dirtime
{ /* temporary struct for holding directory info */
1504 struct dirtime
*next
; /* until can be sorted and set at end */
1505 char *fn
; /* filename of directory */
1507 iztimes t3
; /* mtime, atime, ctime */
1508 ztimbuf t2
; /* modtime, actime */
1510 unsigned perms
; /* same as min_info.file_attr */
1511 int have_uidgid
; /* flag */
1514 #endif /* SET_DIR_ATTRIB */
1516 typedef struct min_info
{
1518 ulg crc
; /* crc (needed if extended header) */
1519 ulg compr_size
; /* compressed size (needed if extended header) */
1520 ulg uncompr_size
; /* uncompressed size (needed if extended header) */
1521 ush diskstart
; /* no of volume where this entry starts */
1524 unsigned file_attr
; /* local flavor, as used by creat(), chmod()... */
1525 unsigned encrypted
: 1; /* file encrypted: decrypt before uncompressing */
1526 unsigned ExtLocHdr
: 1; /* use time instead of CRC for decrypt check */
1527 unsigned textfile
: 1; /* file is text (according to zip) */
1528 unsigned textmode
: 1; /* file is to be extracted as text */
1529 unsigned lcflag
: 1; /* convert filename to lowercase */
1530 unsigned vollabel
: 1; /* "file" is an MS-DOS volume (disk) label */
1531 unsigned HasUxAtt
: 1; /* crec ext_file_attr has Unix style mode bits */
1534 typedef struct VMStimbuf
{
1535 char *revdate
; /* (both roughly correspond to Unix modtime/st_mtime) */
1539 /*---------------------------------------------------------------------------
1540 Zipfile work area declarations.
1541 ---------------------------------------------------------------------------*/
1545 struct { /* unshrink(): */
1546 shrint
*Parent
; /* pointer to (8192 * sizeof(shrint)) */
1547 uch
*value
; /* pointer to 8KB char buffer */
1548 uch
*Stack
; /* pointer to another 8KB char buffer */
1550 uch
*Slide
; /* explode(), inflate(), unreduce() */
1552 #else /* !MALLOC_WORK */
1554 struct { /* unshrink(): */
1555 shrint Parent
[HSIZE
]; /* (8192 * sizeof(shrint)) == 16KB minimum */
1556 uch value
[HSIZE
]; /* 8KB */
1557 uch Stack
[HSIZE
]; /* 8KB */
1558 } shrink
; /* total = 32KB minimum; 80KB on Cray/Alpha */
1559 uch Slide
[WSIZE
]; /* explode(), inflate(), unreduce() */
1561 #endif /* ?MALLOC_WORK */
1563 #define slide G.area.Slide
1565 #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
1566 # define redirSlide G.redirect_sldptr
1568 # define redirSlide G.area.Slide
1571 /*---------------------------------------------------------------------------
1572 Zipfile layout declarations. If these headers ever change, make sure the
1573 xxREC_SIZE defines (above) change with them!
1574 ---------------------------------------------------------------------------*/
1576 typedef uch local_byte_hdr
[ LREC_SIZE
];
1577 # define L_VERSION_NEEDED_TO_EXTRACT_0 0
1578 # define L_VERSION_NEEDED_TO_EXTRACT_1 1
1579 # define L_GENERAL_PURPOSE_BIT_FLAG 2
1580 # define L_COMPRESSION_METHOD 4
1581 # define L_LAST_MOD_DOS_DATETIME 6
1583 # define L_COMPRESSED_SIZE 14
1584 # define L_UNCOMPRESSED_SIZE 18
1585 # define L_FILENAME_LENGTH 22
1586 # define L_EXTRA_FIELD_LENGTH 24
1588 typedef uch cdir_byte_hdr
[ CREC_SIZE
];
1589 # define C_VERSION_MADE_BY_0 0
1590 # define C_VERSION_MADE_BY_1 1
1591 # define C_VERSION_NEEDED_TO_EXTRACT_0 2
1592 # define C_VERSION_NEEDED_TO_EXTRACT_1 3
1593 # define C_GENERAL_PURPOSE_BIT_FLAG 4
1594 # define C_COMPRESSION_METHOD 6
1595 # define C_LAST_MOD_DOS_DATETIME 8
1597 # define C_COMPRESSED_SIZE 16
1598 # define C_UNCOMPRESSED_SIZE 20
1599 # define C_FILENAME_LENGTH 24
1600 # define C_EXTRA_FIELD_LENGTH 26
1601 # define C_FILE_COMMENT_LENGTH 28
1602 # define C_DISK_NUMBER_START 30
1603 # define C_INTERNAL_FILE_ATTRIBUTES 32
1604 # define C_EXTERNAL_FILE_ATTRIBUTES 34
1605 # define C_RELATIVE_OFFSET_LOCAL_HEADER 38
1607 typedef uch ec_byte_rec
[ ECREC_SIZE
+4 ];
1608 /* define SIGNATURE 0 space-holder only */
1609 # define NUMBER_THIS_DISK 4
1610 # define NUM_DISK_WITH_START_CENTRAL_DIR 6
1611 # define NUM_ENTRIES_CENTRL_DIR_THS_DISK 8
1612 # define TOTAL_ENTRIES_CENTRAL_DIR 10
1613 # define SIZE_CENTRAL_DIRECTORY 12
1614 # define OFFSET_START_CENTRAL_DIRECTORY 16
1615 # define ZIPFILE_COMMENT_LENGTH 20
1618 typedef struct local_file_header
{ /* LOCAL */
1619 uch version_needed_to_extract
[2];
1620 ush general_purpose_bit_flag
;
1621 ush compression_method
;
1622 ulg last_mod_dos_datetime
;
1626 ush filename_length
;
1627 ush extra_field_length
;
1631 typedef struct central_directory_file_header
{ /* CENTRAL */
1632 uch version_made_by
[2];
1633 uch version_needed_to_extract
[2];
1634 ush general_purpose_bit_flag
;
1635 ush compression_method
;
1636 ulg last_mod_dos_datetime
;
1640 ush filename_length
;
1641 ush extra_field_length
;
1642 ush file_comment_length
;
1643 ush disk_number_start
;
1644 ush internal_file_attributes
;
1645 ulg external_file_attributes
;
1646 ulg relative_offset_local_header
;
1650 typedef struct end_central_dir_record
{ /* END CENTRAL */
1651 ush number_this_disk
;
1652 ush num_disk_start_cdir
;
1653 ush num_entries_centrl_dir_ths_disk
;
1654 ush total_entries_central_dir
;
1655 ulg size_central_directory
;
1656 ulg offset_start_central_directory
;
1657 ush zipfile_comment_length
;
1661 /* Huffman code lookup table entry--this entry is four bytes for machines
1662 that have 16-bit pointers (e.g. PC's in the small or medium model).
1663 Valid extra bits are 0..16. e == 31 is EOB (end of block), e == 32
1664 means that v is a literal, 32 < e < 64 means that v is a pointer to
1665 the next table, which codes (e & 31) bits, and lastly e == 99 indicates
1666 an unused code. If a code with e == 99 is looked up, this implies an
1667 error in the data. */
1670 uch e
; /* number of extra bits or operation */
1671 uch b
; /* number of bits in this code or subcode */
1673 ush n
; /* literal, length base, or distance base */
1674 struct huft
*t
; /* pointer to next level of table */
1679 typedef struct _APIDocStruct
{
1693 #if (defined(OS2) && !defined(FUNZIP))
1694 # include "os2/os2data.h"
1697 #include "globals.h"
1701 /*************************/
1702 /* Function Prototypes */
1703 /*************************/
1705 /*---------------------------------------------------------------------------
1706 Functions in unzip.c (initialization routines):
1707 ---------------------------------------------------------------------------*/
1710 int MAIN
OF((int argc
, char **argv
));
1711 int unzip
OF((__GPRO__
int argc
, char **argv
));
1712 int uz_opts
OF((__GPRO__
int *pargc
, char ***pargv
));
1713 int usage
OF((__GPRO__
int error
));
1714 #endif /* !WINDLL */
1716 /*---------------------------------------------------------------------------
1717 Functions in process.c (main driver routines):
1718 ---------------------------------------------------------------------------*/
1720 int process_zipfiles
OF((__GPRO
));
1721 void free_G_buffers
OF((__GPRO
));
1722 /* static int do_seekable OF((__GPRO__ int lastchance)); */
1723 /* static int find_ecrec OF((__GPRO__ long searchlen)); */
1724 int uz_end_central
OF((__GPRO
));
1725 int process_cdir_file_hdr
OF((__GPRO
));
1726 int get_cdir_ent
OF((__GPRO
));
1727 int process_local_file_hdr
OF((__GPRO
));
1728 unsigned ef_scan_for_izux
OF((ZCONST uch
*ef_buf
, unsigned ef_len
,
1729 int ef_is_c
, ulg dos_mdatetime
,
1730 iztimes
*z_utim
, ush
*z_uidgid
));
1731 #if (defined(RISCOS) || defined(ACORN_FTYPE_NFS))
1732 zvoid
*getRISCOSexfield
OF((ZCONST uch
*ef_buf
, unsigned ef_len
));
1737 /*---------------------------------------------------------------------------
1738 Functions in zipinfo.c (`zipinfo-style' listing routines):
1739 ---------------------------------------------------------------------------*/
1743 int zi_opts
OF((__GPRO__
int *pargc
, char ***pargv
));
1745 int zi_end_central
OF((__GPRO
));
1746 int zipinfo
OF((__GPRO
));
1747 /* static int zi_long OF((__GPRO__ ulg *pEndprev)); */
1748 /* static int zi_short OF((__GPRO)); */
1749 /* static char *zi_time OF((__GPRO__ ZCONST ulg *datetimez,
1750 ZCONST time_t *modtimez, char *d_t_str));*/
1751 #endif /* !NO_ZIPINFO */
1753 /*---------------------------------------------------------------------------
1754 Functions in list.c (generic zipfile-listing routines):
1755 ---------------------------------------------------------------------------*/
1757 int list_files
OF((__GPRO
));
1759 int get_time_stamp
OF((__GPRO__
time_t *last_modtime
,
1762 int ratio
OF((ulg uc
, ulg c
));
1763 void fnprint
OF((__GPRO
));
1767 /*---------------------------------------------------------------------------
1768 Functions in fileio.c:
1769 ---------------------------------------------------------------------------*/
1771 int open_input_file
OF((__GPRO
));
1772 int open_outfile
OF((__GPRO
)); /* also vms.c */
1773 void undefer_input
OF((__GPRO
));
1774 void defer_leftover_input
OF((__GPRO
));
1775 unsigned readbuf
OF((__GPRO__
char *buf
, register unsigned len
));
1776 int readbyte
OF((__GPRO
));
1777 int fillinbuf
OF((__GPRO
));
1778 int seek_zipf
OF((__GPRO__ LONGINT abs_offset
));
1780 int flush
OF((__GPRO__ ulg size
)); /* actually funzip.c */
1782 int flush
OF((__GPRO__ uch
*buf
, ulg size
, int unshrink
));
1784 /* static int disk_error OF((__GPRO)); */
1785 void handler
OF((int signal
));
1786 time_t dos_to_unix_time
OF((ulg dos_datetime
));
1787 int check_for_newer
OF((__GPRO__
char *filename
)); /* os2,vmcms,vms */
1788 int do_string
OF((__GPRO__
unsigned int length
, int option
));
1789 ush makeword
OF((ZCONST uch
*b
));
1790 ulg makelong
OF((ZCONST uch
*sig
));
1791 #if (!defined(STR_TO_ISO) || defined(NEED_STR2ISO))
1792 char *str2iso
OF((char *dst
, ZCONST
char *src
));
1794 #if (!defined(STR_TO_OEM) || defined(NEED_STR2OEM))
1795 char *str2oem
OF((char *dst
, ZCONST
char *src
));
1798 int zstrnicmp
OF((register ZCONST
char *s1
,
1799 register ZCONST
char *s2
,
1800 register unsigned n
));
1803 int zstat
OF((ZCONST
char *p
, struct stat
*s
));
1805 #ifdef ZMEM /* MUST be ifdef'd because of conflicts with the standard def. */
1806 zvoid
*memset
OF((register zvoid
*, register int, register unsigned int));
1807 int memcmp
OF((register ZCONST zvoid
*, register ZCONST zvoid
*,
1808 register unsigned int));
1809 zvoid
*memcpy
OF((register zvoid
*, register ZCONST zvoid
*,
1810 register unsigned int));
1812 #ifdef NEED_UZMBSCHR
1813 unsigned char *uzmbschr
OF((ZCONST
unsigned char *str
, unsigned int c
));
1815 #ifdef NEED_UZMBSRCHR
1816 unsigned char *uzmbsrchr
OF((ZCONST
unsigned char *str
, unsigned int c
));
1819 char *fLoadFarString
OF((__GPRO__
const char Far
*sz
));
1820 char *fLoadFarStringSmall
OF((__GPRO__
const char Far
*sz
));
1821 char *fLoadFarStringSmall2
OF((__GPRO__
const char Far
*sz
));
1823 char Far
* Far zfstrcpy
OF((char Far
*s1
, const char Far
*s2
));
1828 /*---------------------------------------------------------------------------
1829 Functions in extract.c:
1830 ---------------------------------------------------------------------------*/
1832 int extract_or_test_files
OF((__GPRO
));
1833 /* static int store_info OF((void)); */
1834 /* static int extract_or_test_member OF((__GPRO)); */
1835 /* static int TestExtraField OF((__GPRO__ uch *ef, unsigned ef_len)); */
1836 /* static int test_OS2 OF((__GPRO__ uch *eb, unsigned eb_size)); */
1837 /* static int test_NT OF((__GPRO__ uch *eb, unsigned eb_size)); */
1838 int memextract
OF((__GPRO__ uch
*tgt
, ulg tgtsize
,
1839 ZCONST uch
*src
, ulg srcsize
));
1840 int memflush
OF((__GPRO__ ZCONST uch
*rawbuf
, ulg size
));
1841 #if (defined(VMS) || defined(VMS_TEXT_CONV))
1842 uch
*extract_izvms_block
OF((__GPRO__ ZCONST uch
*ebdata
,
1843 unsigned size
, unsigned *retlen
,
1844 ZCONST uch
*init
, unsigned needlen
));
1846 char *fnfilter
OF((ZCONST
char *raw
, uch
*space
));
1848 /*---------------------------------------------------------------------------
1849 Decompression functions:
1850 ---------------------------------------------------------------------------*/
1852 #if (!defined(SFX) && !defined(FUNZIP))
1853 int explode
OF((__GPRO
)); /* explode.c */
1855 int huft_free
OF((struct huft
*t
)); /* inflate.c */
1856 int huft_build
OF((__GPRO__ ZCONST
unsigned *b
, unsigned n
,
1857 unsigned s
, ZCONST ush
*d
, ZCONST uch
*e
,
1858 struct huft
**t
, int *m
));
1860 int UZinflate
OF((__GPRO__
int is_defl64
)); /* inflate.c */
1861 # define inflate_free(x) inflateEnd(&((Uz_Globs *)(&G))->dstrm)
1863 int inflate
OF((__GPRO__
int is_defl64
)); /* inflate.c */
1864 int inflate_free
OF((__GPRO
)); /* inflate.c */
1865 #endif /* ?USE_ZLIB */
1866 #if (!defined(SFX) && !defined(FUNZIP))
1867 #ifndef COPYRIGHT_CLEAN
1868 int unreduce
OF((__GPRO
)); /* unreduce.c */
1869 /* static void LoadFollowers OF((__GPRO__ f_array *follower, uch *Slen));
1871 #endif /* !COPYRIGHT_CLEAN */
1873 int unshrink
OF((__GPRO
)); /* unshrink.c */
1874 /* static void partial_clear OF((__GPRO)); * unshrink.c */
1875 #endif /* !LZW_CLEAN */
1876 #endif /* !SFX && !FUNZIP */
1878 /*---------------------------------------------------------------------------
1879 Internal API functions (only included in DLL versions):
1880 ---------------------------------------------------------------------------*/
1883 void setFileNotFound
OF((__GPRO
)); /* api.c */
1884 int unzipToMemory
OF((__GPRO__
char *zip
, char *file
,
1885 UzpBuffer
*retstr
)); /* api.c */
1886 int redirect_outfile
OF((__GPRO
)); /* api.c */
1887 int writeToMemory
OF((__GPRO__ ZCONST uch
*rawbuf
,
1888 extent size
)); /* api.c */
1889 int close_redirect
OF((__GPRO
)); /* api.c */
1890 /* this obsolescent entry point kept for compatibility: */
1891 int UzpUnzip
OF((int argc
, char **argv
));/* use UzpMain */
1893 int varmessage
OF((__GPRO__ ZCONST uch
*buf
, ulg size
));
1894 int varputchar
OF((__GPRO__
int c
)); /* rexxapi.c */
1895 int finish_REXX_redirect
OF((__GPRO
)); /* rexxapi.c */
1898 void APIhelp
OF((__GPRO__
int argc
, char **argv
));
1899 #endif /* apihelp.c */
1902 /*---------------------------------------------------------------------------
1903 MSDOS-only functions:
1904 ---------------------------------------------------------------------------*/
1906 #if (defined(MSDOS) && (defined(__GO32__) || defined(__EMX__)))
1907 unsigned _dos_getcountryinfo(void *); /* msdos.c */
1908 #if (!defined(__DJGPP__) || (__DJGPP__ < 2))
1909 unsigned _dos_setftime(int, unsigned, unsigned); /* msdos.c */
1910 unsigned _dos_setfileattr(const char *, unsigned); /* msdos.c */
1911 unsigned _dos_creat(const char *, unsigned, int *); /* msdos.c */
1912 void _dos_getdrive(unsigned *); /* msdos.c */
1913 unsigned _dos_close(int); /* msdos.c */
1914 #endif /* !__DJGPP__ || (__DJGPP__ < 2) */
1917 /*---------------------------------------------------------------------------
1918 OS/2-only functions:
1919 ---------------------------------------------------------------------------*/
1921 #ifdef OS2 /* GetFileTime conflicts with something in Win32 header files */
1922 #if (defined(REENTRANT) && defined(USETHREADID))
1923 ulg GetThreadId
OF((void));
1925 int GetCountryInfo
OF((void)); /* os2.c */
1926 long GetFileTime
OF((ZCONST
char *name
)); /* os2.c */
1927 /* static void SetPathAttrTimes OF((__GPRO__ int flags, int dir)); os2.c */
1928 /* static int SetEAs OF((__GPRO__ const char *path,
1929 void *eablock)); os2.c */
1930 /* static int SetACL OF((__GPRO__ const char *path,
1931 void *eablock)); os2.c */
1932 /* static int IsFileNameValid OF((const char *name)); os2.c */
1933 /* static void map2fat OF((char *pathcomp, char **pEndFAT)); os2.c */
1934 /* static int SetLongNameEA OF((char *name, char *longname)); os2.c */
1935 /* static void InitNLS OF((void)); os2.c */
1936 int IsUpperNLS
OF((int nChr
)); /* os2.c */
1937 int ToLowerNLS
OF((int nChr
)); /* os2.c */
1938 void DebugMalloc
OF((void)); /* os2.c */
1941 /*---------------------------------------------------------------------------
1942 QDOS-only functions:
1943 ---------------------------------------------------------------------------*/
1946 int QMatch (uch
, uch
);
1947 void QFilename (__GPRO__
char *);
1948 char *Qstrfix (char *);
1949 int QReturn (int zip_error
);
1952 /*---------------------------------------------------------------------------
1953 TOPS20-only functions:
1954 ---------------------------------------------------------------------------*/
1957 int upper
OF((char *s
)); /* tops20.c */
1958 int enquote
OF((char *s
)); /* tops20.c */
1959 int dequote
OF((char *s
)); /* tops20.c */
1960 int fnlegal
OF(()); /* error if prototyped? */ /* tops20.c */
1963 /*---------------------------------------------------------------------------
1964 VM/CMS- and MVS-only functions:
1965 ---------------------------------------------------------------------------*/
1968 extent getVMMVSexfield
OF((char *type
, uch
*ef_block
, unsigned datalen
));
1969 FILE *vmmvs_open_infile
OF((__GPRO
)); /* vmmvs.c */
1970 void close_infile
OF((__GPRO
)); /* vmmvs.c */
1973 /*---------------------------------------------------------------------------
1975 ---------------------------------------------------------------------------*/
1978 int check_format
OF((__GPRO
)); /* vms.c */
1979 /* int open_outfile OF((__GPRO)); * (see fileio.c) vms.c */
1980 /* int flush OF((__GPRO__ uch *rawbuf, unsigned size,
1981 int final_flag)); * (see fileio.c) vms.c */
1983 void return_VMS
OF((__GPRO__
int zip_error
)); /* vms.c */
1985 void return_VMS
OF((int zip_error
)); /* vms.c */
1988 ulg vms_unzip_cmdline
OF((int *, char ***)); /* cmdline.c */
1989 int VMSCLI_usage
OF((__GPRO__
int error
)); /* cmdline.c */
1993 /*---------------------------------------------------------------------------
1994 WIN32-only functions:
1995 ---------------------------------------------------------------------------*/
1998 int IsWinNT
OF((void)); /* win32.c */
2000 void process_defer_NT
OF((__GPRO
)); /* win32.c */
2001 int test_NTSD
OF((__GPRO__ uch
*eb
, unsigned eb_size
,
2002 uch
*eb_ucptr
, ulg eb_ucsize
)); /* win32.c */
2003 # define TEST_NTSD test_NTSD
2005 #ifdef W32_STAT_BANDAID
2006 int zstat_win32
OF((__W32STAT_GLOBALS__
2007 const char *path
, struct stat
*buf
)); /* win32.c */
2011 /*---------------------------------------------------------------------------
2012 Miscellaneous/shared functions:
2013 ---------------------------------------------------------------------------*/
2015 Uz_Globs
*globalsCtor
OF((void)); /* globals.c */
2017 int envargs
OF((int *Pargc
, char ***Pargv
,
2018 ZCONST
char *envstr
, ZCONST
char *envstr2
));
2020 void mksargs
OF((int *argcp
, char ***argvp
)); /* envargs.c */
2022 int match
OF((ZCONST
char *s
, ZCONST
char *p
,
2023 int ic
)); /* match.c */
2024 int iswild
OF((ZCONST
char *p
)); /* match.c */
2026 #ifdef DYNALLOC_CRCTAB
2027 void free_crc_table
OF((void)); /* crctab.c */
2030 ZCONST ulg near
*get_crc_table
OF((void)); /* funzip.c, crctab.c */
2031 ulg crc32
OF((ulg crc
, ZCONST uch
*buf
, extent len
));
2032 #endif /* !USE_ZLIB */ /* assembler source or crc32.c */
2034 int dateformat
OF((void)); /* currently, only msdos.c */
2036 void version
OF((__GPRO
)); /* local */
2038 int mapattr
OF((__GPRO
)); /* local */
2039 int mapname
OF((__GPRO__
int renamed
)); /* local */
2040 int checkdir
OF((__GPRO__
char *pathcomp
, int flag
)); /* local */
2041 char *do_wild
OF((__GPRO__ ZCONST
char *wildzipfn
)); /* local */
2042 char *GetLoadPath
OF((__GPRO
)); /* local */
2043 #if (defined(MORE) && (defined(BEO_UNX) || defined(QDOS) || defined(VMS)))
2044 int screensize
OF((int *tt_rows
, int *tt_cols
)); /* local */
2046 int screenlinewrap
OF((void)); /* local */
2048 #endif /* MORE && (BEO_UNX || QDOS || VMS) */
2050 int SetFileSize
OF((FILE *file
, ulg filesize
)); /* local */
2052 #ifndef MTS /* macro in MTS */
2053 void close_outfile
OF((__GPRO
)); /* local */
2055 #ifdef SET_DIR_ATTRIB
2056 int set_direc_attribs
OF((__GPRO__ dirtime
*d
)); /* local */
2060 int stamp_file
OF((__GPRO__
2061 ZCONST
char *fname
, time_t modtime
)); /* local */
2063 int stamp_file
OF((ZCONST
char *fname
, time_t modtime
)); /* local */
2066 #if (defined(MALLOC_WORK) && defined(MY_ZCALLOC))
2067 zvoid far
*zcalloc
OF((unsigned int, unsigned int));
2068 zvoid zcfree
OF((zvoid far
*));
2069 #endif /* MALLOC_WORK && MY_ZCALLOC */
2070 #ifdef SYSTEM_SPECIFIC_CTOR
2071 void SYSTEM_SPECIFIC_CTOR
OF((__GPRO
)); /* local */
2083 # define MAX(a,b) ((a) > (b) ? (a) : (b))
2086 # define MIN(a,b) ((a) < (b) ? (a) : (b))
2090 # if (defined(THEOS) && defined(NO_BOGUS_SPC))
2091 # define NO_DEBUG_IN_MACROS
2092 # define Trace(x) _fprintf x
2094 # define Trace(x) fprintf x
2101 # define TTrace(x) fprintf x
2106 #ifdef NO_DEBUG_IN_MACROS
2109 # define MTrace(x) Trace(x)
2112 #if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
2113 # define ToLower(x) ((char)(isupper((int)x)? tolower((int)x) : x))
2115 # define ToLower tolower /* assumed "smart"; used in match() */
2118 #ifdef USE_STRM_INPUT
2119 /* ``Replace'' the unbuffered UNIX style I/O function with similar
2120 * standard C functions from <stdio.h>.
2122 # define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
2123 # define lseek(fd,o,w) fseek((FILE *)(fd),(o),(w))
2124 # define close(fd) fclose((FILE *)(fd))
2125 #endif /* USE_STRM_INPUT */
2127 /* The return value of the Info() "macro function" is never checked in
2128 * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
2129 * Info() definition for "FUNZIP" would have to be corrected:
2130 * #define Info(buf,flag,sprf_arg) \
2131 * (fprintf((flag)&1? stderr : stdout, \
2132 * (char *)(sprintf sprf_arg, (buf))) == EOF)
2134 #ifndef Info /* may already have been defined for redirection */
2136 # define Info(buf,flag,sprf_arg) \
2137 fprintf((flag)&1? stderr : stdout, (char *)(sprintf sprf_arg, (buf)))
2139 # ifdef INT_SPRINTF /* optimized version for "int sprintf()" flavour */
2140 # define Info(buf,flag,sprf_arg) \
2141 (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
2142 # else /* generic version, does not use sprintf() return value */
2143 # define Info(buf,flag,sprf_arg) \
2144 (*G.message)((zvoid *)&G, (uch *)(buf), \
2145 (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
2150 /* The following macros wrappers around the fnfilter function are used many
2151 * times to prepare archive entry names or name components for displaying
2152 * listings and (warning/error) messages. They use sections in the upper half
2153 * of 'slide' as buffer, since their output is normally fed through the
2154 * Info() macro with 'slide' (the start of this area) as message buffer.
2156 #define FnFilter1(fname) fnfilter((fname), slide + (WSIZE>>1))
2157 #define FnFilter2(fname) fnfilter((fname), slide + ((WSIZE>>1) + (WSIZE>>2)))
2159 #ifndef FUNZIP /* used only in inflate.c */
2160 # define MESSAGE(str,len,flag) (*G.message)((zvoid *)&G,(str),(len),(flag))
2163 #if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
2164 # define CRCVAL_INITIAL crc32(0L, NULL, 0)
2166 # define CRCVAL_INITIAL 0L
2169 #ifndef TEST_NTSD /* "NTSD valid?" checking function */
2170 # define TEST_NTSD NULL /* ... is not available */
2173 #define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
2174 {error_in_archive=error; if(error>1) return error;}
2177 * Skip a variable-length field, and report any errors. Used in zipinfo.c
2178 * and unzip.c in several functions.
2180 * macro SKIP_(length)
2183 * if (length && ((error = do_string(length, SKIP)) != 0)) {
2184 * error_in_archive = error; /-* might be warning *-/
2185 * if (error > 1) /-* fatal *-/
2194 # define FLUSH(w) flush(__G__ (ulg)(w))
2195 # define NEXTBYTE getc(G.in) /* redefined in crypt.h if full version */
2197 # define FLUSH(w) ((G.mem_mode) ? memflush(__G__ redirSlide,(ulg)(w)) \
2198 : flush(__G__ redirSlide,(ulg)(w),0))
2199 # define NEXTBYTE (--G.incnt >= 0 ? (int)(*G.inptr++) : readbyte(__G))
2203 #define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
2204 while (G.bits_left<=8*(int)(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
2205 G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
2206 zdest=(shrint)((ush)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
2207 G.bits_left-=nbits;}
2210 * macro READBITS(nbits,zdest) * only used by unreduce and unshrink *
2212 * if (nbits > G.bits_left) { * fill G.bitbuf, 8*sizeof(ulg) bits *
2216 * while (G.bits_left <= 8*(int)(sizeof(G.bitbuf)-1) &&
2217 * (temp = NEXTBYTE) != EOF) {
2218 * G.bitbuf |= (ulg)temp << G.bits_left;
2223 * zdest = (shrint)((ush)G.bitbuf & mask_bits[nbits]);
2224 * G.bitbuf >>= nbits;
2225 * G.bits_left -= nbits;
2231 /* GRR: should use StringLower for STRLOWER macro if possible */
2234 * Copy the zero-terminated string in str1 into str2, converting any
2235 * uppercase letters to lowercase as we go. str2 gets zero-terminated
2236 * as well, of course. str1 and str2 may be the same character array.
2239 # define STRLOWER(str1, str2) \
2241 char *p, *q, c; unsigned i; \
2242 p = (char *)(str1); \
2243 q = (char *)(str2); \
2244 while ((c = *p) != '\0') { \
2245 if ((i = CLEN(p)) > 1) { \
2246 while (i--) *q++ = *p++; \
2248 *q++ = (char)(isupper((int)(c))? tolower((int)(c)) : c); \
2255 # define STRLOWER(str1, str2) \
2258 p = (char *)(str1) - 1; \
2259 q = (char *)(str2); \
2261 *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
2266 * NOTES: This macro makes no assumptions about the characteristics of
2267 * the tolower() function or macro (beyond its existence), nor does it
2268 * make assumptions about the structure of the character set (i.e., it
2269 * should work on EBCDIC machines, too). The fact that either or both
2270 * of isupper() and tolower() may be macros has been taken into account;
2271 * watch out for "side effects" (in the C sense) when modifying this
2276 # define foreign(c) (c)
2280 # define native(c) (c)
2281 # define A_TO_N(str1)
2284 # define NATIVE "native chars"
2286 # define A_TO_N(str1) {register uch *p;\
2287 for (p=(uch *)(str1); *p; p++) *p=native(*p);}
2290 * Translate the zero-terminated string in str1 from ASCII to the native
2291 * character set. The translation is performed in-place and uses the
2292 * "native" macro to translate each character.
2294 * NOTE: Using the "native" macro means that is it the only part of unzip
2295 * which knows which translation table (if any) is actually in use to
2296 * produce the native character set. This makes adding new character set
2297 * translation tables easy, insofar as all that is needed is an appropriate
2298 * "native" macro definition and the translation table itself. Currently,
2299 * the only non-ASCII native character set implemented is EBCDIC, but this
2300 * may not always be so.
2304 /* default setup for internal codepage: assume ISO 8859-1 compatibility!! */
2305 #if (!defined(NATIVE) && !defined(CRTL_CP_IS_ISO) && !defined(CRTL_CP_IS_OEM))
2306 # define CRTL_CP_IS_ISO
2310 /* Translate "extended ASCII" chars (OEM coding for DOS and OS/2; else
2311 * ISO-8859-1 [ISO Latin 1, Win Ansi,...]) into the internal "native"
2312 * code page. As with A_TO_N(), conversion is done in place.
2315 # ifdef CRTL_CP_IS_OEM
2316 # ifndef IZ_ISO2OEM_ARRAY
2317 # define IZ_ISO2OEM_ARRAY
2319 # define _ISO_INTERN(str1) {register uch *p;\
2320 for (p=(uch *)(str1); *p; p++)\
2321 *p = native((*p & 0x80) ? iso2oem[*p & 0x7f] : *p);}
2323 # define _ISO_INTERN(str1) A_TO_N(str1)
2328 # ifdef CRTL_CP_IS_OEM
2329 # define _OEM_INTERN(str1) A_TO_N(str1)
2331 # ifndef IZ_OEM2ISO_ARRAY
2332 # define IZ_OEM2ISO_ARRAY
2334 # define _OEM_INTERN(str1) {register uch *p;\
2335 for (p=(uch *)(str1); *p; p++)\
2336 *p = native((*p & 0x80) ? oem2iso[*p & 0x7f] : *p);}
2341 # ifdef CRTL_CP_IS_ISO
2342 # define STR_TO_ISO strcpy
2344 # define STR_TO_ISO str2iso
2345 # define NEED_STR2ISO
2350 # ifdef CRTL_CP_IS_OEM
2351 # define STR_TO_OEM strcpy
2353 # define STR_TO_OEM str2oem
2354 # define NEED_STR2OEM
2358 #if (!defined(INTERN_TO_ISO) && !defined(ASCII2ISO))
2359 # ifdef CRTL_CP_IS_OEM
2360 /* know: "ASCII" is "OEM" */
2361 # define ASCII2ISO(c) (((c) & 0x80) ? oem2iso[(c) & 0x7f] : (c))
2362 # if (defined(NEED_STR2ISO) && !defined(CRYP_USES_OEM2ISO))
2363 # define CRYP_USES_OEM2ISO
2366 /* assume: "ASCII" is "ISO-ANSI" */
2367 # define ASCII2ISO(c) (c)
2371 #if (!defined(INTERN_TO_OEM) && !defined(ASCII2OEM))
2372 # ifdef CRTL_CP_IS_OEM
2373 /* know: "ASCII" is "OEM" */
2374 # define ASCII2OEM(c) (c)
2376 /* assume: "ASCII" is "ISO-ANSI" */
2377 # define ASCII2OEM(c) (((c) & 0x80) ? iso2oem[(c) & 0x7f] : (c))
2378 # if (defined(NEED_STR2OEM) && !defined(CRYP_USES_ISO2OEM))
2379 # define CRYP_USES_ISO2OEM
2384 /* codepage conversion setup for testp() in crypt.c */
2385 #ifdef CRTL_CP_IS_ISO
2387 # define STR_TO_CP2 STR_TO_OEM
2390 # ifdef CRTL_CP_IS_OEM
2392 # define STR_TO_CP2 STR_TO_ISO
2394 # else /* native internal CP is neither ISO nor OEM */
2396 # define STR_TO_CP1 STR_TO_ISO
2399 # define STR_TO_CP2 STR_TO_OEM
2405 /* Convert filename (and file comment string) into "internal" charset.
2406 * This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
2407 * codepage when made on
2408 * -> DOS (this includes 16-bit Windows 3.1) (FS_FAT_)
2409 * -> OS/2 (FS_HPFS_)
2410 * -> Win95/WinNT with Nico Mak's WinZip (FS_NTFS_ && hostver == "5.0")
2412 * PKZIP for Windows 2.5, 2.6, and 4.0 flag their entries as "FS_FAT_", but
2413 * the filename stored in the local header is coded in Windows ANSI (CP 1252
2414 * resp. ISO 8859-1 on US and western Europe locale settings).
2415 * Likewise, PKZIP for UNIX 2.51 flags its entries as "FS_FAT_", but the
2416 * filenames stored in BOTH the local and the central header are coded
2417 * in the local system's codepage (usually ANSI codings like ISO 8859-1).
2419 * All other ports are assumed to code zip entry filenames in ISO 8859-1.
2421 #ifndef Ext_ASCII_TO_Native
2422 # define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
2423 if (((hostnum) == FS_FAT_ && \
2424 !(((islochdr) || (isuxatt)) && \
2425 ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
2426 (hostnum) == FS_HPFS_ || \
2427 ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
2428 _OEM_INTERN((string)); \
2430 _ISO_INTERN((string)); \
2436 /**********************/
2437 /* Global constants */
2438 /**********************/
2440 extern ZCONST ush near mask_bits
[];
2441 extern ZCONST
char *fnames
[2];
2444 extern ZCONST uch ebcdic
[];
2446 #ifdef IZ_ISO2OEM_ARRAY
2447 extern ZCONST uch Far iso2oem
[];
2449 #ifdef IZ_OEM2ISO_ARRAY
2450 extern ZCONST uch Far oem2iso
[];
2453 extern ZCONST
char Far VersionDate
[];
2454 extern ZCONST
char Far CentSigMsg
[];
2456 extern ZCONST
char Far EndSigMsg
[];
2458 extern ZCONST
char Far SeekMsg
[];
2459 extern ZCONST
char Far FilenameNotMatched
[];
2460 extern ZCONST
char Far ExclFilenameNotMatched
[];
2461 extern ZCONST
char Far ReportMsg
[];
2464 extern ZCONST
char Far Zipnfo
[];
2465 extern ZCONST
char Far CompiledWith
[];
2470 /***********************************/
2471 /* Global (shared?) RTL variables */
2472 /***********************************/
2474 #ifdef DECLARE_ERRNO
2479 #endif /* !__unzpriv_h */