2 Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
4 See the accompanying file LICENSE, version 2009-Jan-02 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! */
48 # ifdef USE_BZIP2 /* fUnZip does not support bzip2 decompression */
53 #if (defined(USE_ZLIB) && !defined(HAVE_ZL_INFLAT64) && !defined(NO_DEFLATE64))
54 /* zlib does not (yet?) provide Deflate64(tm) support */
59 /* disable support for Deflate64(tm) */
64 /* enable Deflate64(tm) support unless compiling for SFX stub */
65 # if (!defined(USE_DEFLATE64) && !defined(SFX))
66 # define USE_DEFLATE64
70 /* disable bzip2 support for SFX stub, unless explicitly requested */
71 #if (defined(SFX) && !defined(BZIP2_SFX) && defined(USE_BZIP2))
75 #if (defined(NO_VMS_TEXT_CONV) || defined(VMS))
80 # if (!defined(VMS_TEXT_CONV) && !defined(SFX))
81 # define VMS_TEXT_CONV
85 /* Enable -B option per default on specific systems, to allow backing up
86 * files that would be overwritten.
87 * (This list of systems must be kept in sync with the list of systems
88 * that add the B_flag to the UzpOpts structure, see unzip.h.)
90 #if (!defined(NO_UNIXBACKUP) && !defined(UNIXBACKUP))
91 # if defined(UNIX) || defined(OS2) || defined(WIN32)
96 #if (defined(DLL) && !defined(REENTRANT))
100 #if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
101 # define DYNAMIC_CRC_TABLE
104 #if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
105 # ifndef DYNALLOC_CRCTAB
106 # define DYNALLOC_CRCTAB
110 /*---------------------------------------------------------------------------
111 OS-dependent configuration for UnZip internals
112 ---------------------------------------------------------------------------*/
114 /* Some compiler distributions for Win32/i386 systems try to emulate
115 * a Unix (POSIX-compatible) environment.
117 #if (defined(WIN32) && defined(UNIX))
118 /* UnZip does not support merging both ports in a single executable. */
119 # if (defined(FORCE_WIN32_OVER_UNIX) && defined(FORCE_UNIX_OVER_WIN32))
120 /* conflicting choice requests -> we prefer the Win32 environment */
121 # undef FORCE_UNIX_OVER_WIN32
123 # ifdef FORCE_WIN32_OVER_UNIX
124 /* native Win32 support was explicitly requested... */
127 /* use the POSIX (Unix) emulation features by default... */
132 /* bad or (occasionally?) missing stddef.h: */
133 #if (defined(M_XENIX) || defined(DNIX))
137 #if (defined(M_XENIX) && !defined(M_UNIX)) /* SCO Xenix only, not SCO Unix */
139 # define NO_LIMITS_H /* no limits.h, but MODERN defined */
140 # define NO_UID_GID /* no uid_t/gid_t */
144 #ifdef realix /* Modcomp Real/IX, real-time SysV.3 variant */
146 # define NO_UID_GID /* no uid_t/gid_t */
149 #if (defined(_AIX) && !defined(_ALL_SOURCE))
153 #if defined(apollo) /* defines __STDC__ */
159 # define SHORT_NAMES /* 14-char limitation on path components */
160 /* # define FILENAME_MAX 14 */
161 # define FILENAME_MAX NAME_MAX /* GRR: experiment */
164 #if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
168 #endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
169 #if (defined(M_SYSV) || defined(M_SYS5))
173 #endif /* M_SYSV || M_SYS5 */
174 /* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
175 #if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
179 #endif /* __SVR4 || __svr4__ || sgi || __hpux */
180 #if (defined(LINUX) || defined(__QNX__))
184 #endif /* LINUX || __QNX__ */
186 #if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
187 # if (!defined(BSD) && !defined(SYSV))
190 #endif /* ultrix || __ultrix || bsd4_2 */
191 #if (defined(sun) || defined(pyr) || defined(CONVEX))
192 # if (!defined(BSD) && !defined(SYSV))
195 #endif /* sun || pyr || CONVEX */
197 #ifdef pyr /* Pyramid: has BSD and AT&T "universes" */
200 # define USE_STRINGS_H /* instead of more common string.h */
201 # define ZMEM /* ZMEM now uses bcopy/bzero: not in AT&T universe */
202 # endif /* (AT&T memcpy claimed to be very slow, though) */
203 # define DECLARE_ERRNO
206 /* stat() bug for Borland, VAX C RTL, and Atari ST MiNT on TOS
207 * filesystems: returns 0 for wildcards! (returns 0xffffffff on Minix
208 * filesystem or `U:' drive under Atari MiNT.) Watcom C was previously
209 * included on this list; it would be good to know what version the problem
210 * was fixed at, if it did exist. */
211 #if (defined(__TURBOC__) && !defined(WIN32))
212 /*# define WILD_STAT_BUG*/
214 #if (defined(VMS) || defined(__MINT__))
215 # define WILD_STAT_BUG
218 /*---------------------------------------------------------------------------
219 OS-dependent includes
220 ---------------------------------------------------------------------------*/
223 /*---------------------------------------------------------------------------
225 ---------------------------------------------------------------------------*/
228 # define MAIN UZ_EXP UzpMain /* was UzpUnzip */
231 # define REDIRECTC(c) varputchar(__G__ c)
232 # define REDIRECTPRINT(buf,size) varmessage(__G__ buf, size)
233 # define FINISH_REDIRECT() finish_REXX_redirect(__G)
235 # define REDIRECTC(c)
236 # define REDIRECTPRINT(buf,size) 0
237 # define FINISH_REDIRECT() close_redirect(__G)
241 /*---------------------------------------------------------------------------
242 Acorn RISCOS section:
243 ---------------------------------------------------------------------------*/
246 # include "acorn/riscos.h"
249 /*---------------------------------------------------------------------------
251 ---------------------------------------------------------------------------*/
254 # include "amiga/amiga.h"
257 /*---------------------------------------------------------------------------
258 AOS/VS section (somewhat similar to Unix, apparently):
259 ---------------------------------------------------------------------------*/
263 # include "aosvs/aosvs.h"
267 /*---------------------------------------------------------------------------
269 ---------------------------------------------------------------------------*/
277 # define EXE_EXTENSION ".tos"
279 # define DATE_FORMAT DF_DMY
283 # define timezone _timezone
285 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
287 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
292 /*---------------------------------------------------------------------------
294 ---------------------------------------------------------------------------*/
297 # include "atheos/athcfg.h"
300 /*---------------------------------------------------------------------------
302 ---------------------------------------------------------------------------*/
305 # include "beos/beocfg.h"
308 /*---------------------------------------------------------------------------
309 Human68k/X680x0 section:
310 ---------------------------------------------------------------------------*/
313 /* DO NOT DEFINE DOS_OS2 HERE! If Human68k is so much */
314 /* like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
315 # if (!defined(_MBCS) && !defined(NO_MBCS))
316 /* enable MBCS support by default for this system */
319 # if (defined(_MBCS) && defined(NO_MBCS))
320 /* disable MBCS support when explicitely requested */
327 # include <sys/stat.h>
328 # ifdef HAVE_MBSTRING_H
329 # include <mbstring.h>
331 # ifdef HAVE_MBCTYPE_H
332 # include <mbctype.h>
335 # define _ismbblead(c) (0x80 <= (c) && ((c) < 0xa0 || 0xe0 <= (c)))
339 # define DATE_FORMAT DF_YMD /* Japanese standard */
342 # define PutNativeEOL *q++ = native(LF);
346 # define MAIN main_sfx
350 /*---------------------------------------------------------------------------
352 ---------------------------------------------------------------------------*/
358 /*---------------------------------------------------------------------------
359 MS-DOS, OS/2, FLEXOS section:
360 ---------------------------------------------------------------------------*/
371 #if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
373 # define MSC /* This should work for older MSC, too! */
377 #if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
378 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
379 # include <sys/stat.h>
380 # include <io.h> /* lseek(), open(), setftime(), dup(), creat() */
381 # include <time.h> /* localtime() */
382 # include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
384 # ifdef OS2 /* defined for all OS/2 compilers */
385 # include "os2/os2cfg.h"
388 # include "flexos/flxcfg.h"
390 # include "msdos/doscfg.h"
394 # if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
396 * ARGH. MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
397 * 1970 Jan 1 00:00. So we have to diddle time_t's appropriately: add or
398 * subtract 70 years' worth of seconds; i.e., number of days times 86400;
399 * i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
400 * (25550 + 17 + 1) * 86400 == 2209075200 seconds. We know time_t is an
401 * unsigned long (ulg) on the only system with this bug.
403 # define TIMET_TO_NATIVE(x) (x) += (ulg)2209075200L;
404 # define NATIVE_TO_TIMET(x) (x) -= (ulg)2209075200L;
406 # if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
407 # define timezone _timezone
409 # if (defined(__GO32__) || defined(FLEXOS))
412 # define DIR_END '\\' /* OS uses '\\' as directory separator */
413 # define DIR_END2 '/' /* also check for '/' (RTL may convert) */
418 # define DATE_FORMAT dateformat()
420 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
421 # if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
422 # define USE_EF_UT_TIME
424 #endif /* MSDOS || OS2 || FLEXOS */
426 /*---------------------------------------------------------------------------
427 MTS section (piggybacks UNIX, I think):
428 ---------------------------------------------------------------------------*/
431 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
432 # include <sys/stat.h>
433 # include <sys/file.h> /* MTS uses this instead of fcntl.h */
436 # include <unix.h> /* some important non-ANSI routines */
437 # define mkdir(s,n) (-1) /* no "make directory" capability */
438 # define EBCDIC /* set EBCDIC conversion on */
439 # define NO_STRNICMP /* unzip's is as good the one in MTS */
441 # define close_outfile() fclose(G.outfile) /* can't set time on files */
442 # define umask(n) /* don't have umask() on MTS */
443 # define FOPWT "w" /* open file for writing in TEXT mode */
445 # define DATE_FORMAT DF_MDY
448 # define PutNativeEOL *q++ = native(LF);
451 /*---------------------------------------------------------------------------
452 Novell Netware NLM section
453 ---------------------------------------------------------------------------*/
456 # include "netware/nlmcfg.h"
459 /*---------------------------------------------------------------------------
461 ---------------------------------------------------------------------------*/
467 # include <sys/stat.h>
469 # include "qdos/izqdos.h"
471 # define DATE_FORMAT DF_MDY
474 # define PutNativeEOL *q++ = native(LF);
476 # define RETURN QReturn
479 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
482 # define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
483 # define SCREENWIDTH 80
486 /*---------------------------------------------------------------------------
488 ---------------------------------------------------------------------------*/
494 /* We are compiling with non-WIDE memory model, int = 16 bits */
496 # define INT_16BIT /* report "int" size is 16-bit to inflate setup */
498 # ifdef USE_DEFLATE64
499 /* Following required for 64k WSIZE of Deflate64 support */
500 # define MED_MEM /* else OUTBUFSIZ is 64K and fails in do_string */
501 # define INBUFSIZ 8192 /* but larger buffer for real OSes */
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 "vms/vmscfg.h"
581 /*---------------------------------------------------------------------------
582 Win32 (Windows 95/NT) section:
583 ---------------------------------------------------------------------------*/
585 #if (defined(WIN32) && !defined(POCKET_UNZIP) && !defined(_WIN32_WCE))
586 # include "win32/w32cfg.h"
589 /*---------------------------------------------------------------------------
590 Win32 Windows CE section (also POCKET_UNZIP)
591 ---------------------------------------------------------------------------*/
593 #if (defined(_WIN32_WCE) || defined(POCKET_UNZIP))
594 # include "wince/wcecfg.h"
599 /* ----------------------------------------------------------------------------
600 MUST BE AFTER LARGE FILE INCLUDES
601 ---------------------------------------------------------------------------- */
602 /* This stuff calls in types and messes up large file includes. It needs to
603 go after large file defines in local includes.
604 I am guessing that moving them here probably broke some ports, but hey.
606 /* ----------------------------------------------------------------------------
608 ---------------------------------------------------------------------------- */
610 /* Some ports apply specific adjustments which must be in effect before
611 reading the "standard" include headers.
615 # define Z_OFF_T off_t /* Amdahl UTS nonsense ("extended file types") */
617 #if (defined(UNIX) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
618 # define Z_OFF_T off_t /* 64bit offsets to support 2GB < zipfile size < 4GB */
620 # define Z_OFF_T long long
624 #ifndef ZOFF_T_DEFINED
625 typedef Z_OFF_T zoff_t
;
626 # define ZOFF_T_DEFINED
628 #ifndef Z_STAT_DEFINED
629 typedef struct stat z_stat
;
630 # define Z_STAT_DEFINED
633 #ifndef MINIX /* Minix needs it after all the other includes (?) */
637 #include <ctype.h> /* skip for VMS, to use tolower() function? */
638 #include <errno.h> /* used in mapname() */
640 # include <strings.h> /* strcpy, strcmp, memcpy, index/rindex, etc. */
642 # include <string.h> /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
644 #if (defined(MODERN) && !defined(NO_LIMITS_H))
645 # include <limits.h> /* MAX/MIN constant symbols for system types... */
648 /* this include must be down here for SysV.4, for some reason... */
649 #include <signal.h> /* used in unzip.c, fileio.c */
657 # include <stdlib.h> /* standard library prototypes, malloc(), etc. */
659 typedef size_t extent
;
661 # ifndef AOS_VS /* mostly modern? */
663 # ifdef VAXC /* not fully modern, but has stdlib.h and void */
668 # endif /* !AOS_VS */
669 typedef unsigned int extent
;
679 #define UNZIP_BZ2VERS 46
682 # define UNZIP_VERSION UNZIP_BZ2VERS
684 # define UNZIP_VERSION 45
688 # define UNZIP_VERSION 21 /* compatible with PKUNZIP 4.0 */
690 # define UNZIP_VERSION 20 /* compatible with PKUNZIP 2.0 */
693 #define VMS_UNZIP_VERSION 42 /* if OS-needed-to-extract is VMS: can do */
695 #if (defined(MSDOS) || defined(OS2))
699 #if (defined(OS2) || defined(WIN32))
703 #if (defined(DOS_OS2) || defined(WIN32))
705 # define DOS_W32_OS2 /* historical: don't use */
708 #if (defined(DOS_OS2_W32) || defined(__human68k__))
709 # define DOS_H68_OS2_W32
712 #if (defined(DOS_OS2) || defined(FLEXOS))
716 #if (defined(DOS_OS2_W32) || defined(FLEXOS))
717 # define DOS_FLX_OS2_W32
720 #if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
721 # define DOS_FLX_H68_OS2_W32
724 #if (defined(DOS_FLX_OS2) || defined(NLM))
725 # define DOS_FLX_NLM_OS2
728 #if (defined(DOS_FLX_OS2_W32) || defined(NLM))
729 # define DOS_FLX_NLM_OS2_W32
732 #if (defined(DOS_FLX_H68_OS2_W32) || defined(NLM))
733 # define DOS_FLX_H68_NLM_OS2_W32
736 #if (defined(TOPS20) || defined(VMS))
740 #if (defined(MSDOS) || defined(T20_VMS))
744 #if (defined(__ATHEOS__) || defined(__BEOS__))
748 #if (defined(ATH_BEO) || defined(UNIX))
752 #if (defined(ATH_BEO_UNX) || defined(THEOS))
753 # define ATH_BEO_THS_UNX
756 /* clean up with a few defaults */
758 # define DIR_END '/' /* last char before program name or filename */
761 # ifdef DATEFMT_ISO_DEFAULT
762 # define DATE_FORMAT DF_YMD /* defaults to invariant ISO-style */
764 # define DATE_FORMAT DF_MDY /* defaults to US convention */
768 # define DATE_SEPCHAR '-'
771 # define CLOSE_INFILE() close(G.zipfd)
774 # define RETURN return /* only used in main() */
780 # define USAGE(ret) usage(__G__ (ret)) /* used in unzip.c, zipinfo.c */
782 #ifndef TIMET_TO_NATIVE /* everybody but MSC 7.0 and Macintosh */
783 # define TIMET_TO_NATIVE(x)
784 # define NATIVE_TO_TIMET(x)
788 # define STRNICMP zstrnicmp
790 # define STRNICMP strnicmp
795 #if (defined(DOS_FLX_NLM_OS2_W32) || defined(ATH_BEO_UNX) || defined(RISCOS))
800 #if (defined(AOS_VS) || defined(ATARI)) /* GRR: others? */
806 /* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
808 #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
809 # if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
810 # define INT_SPRINTF /* sprintf() returns int: SysVish/Posix */
812 # if (defined(DOS_FLX_NLM_OS2_W32) || defined(VMS) || defined(AMIGA))
813 # define INT_SPRINTF /* sprintf() returns int: ANSI */
815 # if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
816 # if (defined(POSIX) || defined(__POSIX))
817 # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
820 # define PCHAR_SPRINTF /* undetermined actual return value */
823 # if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS) || defined(THEOS))
824 # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
827 # define PCHAR_SPRINTF /* sprintf() returns char *: SunOS cc *and* gcc */
831 /* defaults that we hope will take care of most machines in the future */
833 #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
835 # define INT_SPRINTF /* sprintf() returns int: ANSI */
838 # define PCHAR_SPRINTF /* sprintf() returns char *: BSDish */
842 #define MSG_STDERR(f) (f & 1) /* bit 0: 0 = stdout, 1 = stderr */
843 #define MSG_INFO(f) ((f & 6) == 0) /* bits 1 and 2: 0 = info */
844 #define MSG_WARN(f) ((f & 6) == 2) /* bits 1 and 2: 1 = warning */
845 #define MSG_ERROR(f) ((f & 6) == 4) /* bits 1 and 2: 2 = error */
846 #define MSG_FATAL(f) ((f & 6) == 6) /* bits 1 and 2: (3 = fatal error) */
847 #define MSG_ZFN(f) (f & 0x0008) /* bit 3: 1 = print zipfile name */
848 #define MSG_FN(f) (f & 0x0010) /* bit 4: 1 = print filename */
849 #define MSG_LNEWLN(f) (f & 0x0020) /* bit 5: 1 = leading newline if !SOL */
850 #define MSG_TNEWLN(f) (f & 0x0040) /* bit 6: 1 = trailing newline if !SOL */
851 #define MSG_MNEWLN(f) (f & 0x0080) /* bit 7: 1 = trailing NL for prompts */
852 /* the following are subject to change */
853 #define MSG_NO_WGUI(f) (f & 0x0100) /* bit 8: 1 = skip if Windows GUI */
854 #define MSG_NO_AGUI(f) (f & 0x0200) /* bit 9: 1 = skip if Acorn GUI */
855 #define MSG_NO_DLL2(f) (f & 0x0400) /* bit 10: 1 = skip if OS/2 DLL */
856 #define MSG_NO_NDLL(f) (f & 0x0800) /* bit 11: 1 = skip if WIN32 DLL */
857 #define MSG_NO_WDLL(f) (f & 0x1000) /* bit 12: 1 = skip if Windows DLL */
859 #if (defined(MORE) && !defined(SCREENLINES))
860 # ifdef DOS_FLX_NLM_OS2_W32
861 # define SCREENLINES 25 /* can be (should be) a function instead */
863 # define SCREENLINES 24 /* VT-100s are assumed to be minimal hardware */
866 #if (defined(MORE) && !defined(SCREENSIZE))
868 # define SCREENSIZE(scrrows, scrcols) { \
869 if ((scrrows) != NULL) *(scrrows) = SCREENLINES; }
871 # define SCREENSIZE(scrrows, scrcols) { \
872 if ((scrrows) != NULL) *(scrrows) = SCREENLINES; \
873 if ((scrcols) != NULL) *(scrcols) = SCREENWIDTH; }
877 #if (defined(__16BIT__) || defined(MED_MEM) || defined(SMALL_MEM))
878 # define DIR_BLKSIZ 64 /* number of directory entries per block
879 * (should fit in 4096 bytes, usually) */
881 # define DIR_BLKSIZ 16384 /* use more memory, to reduce long-range seeks */
885 # ifdef USE_DEFLATE64
886 # define WSIZE 65536L /* window size--must be a power of two, and */
887 # else /* at least 64K for PKZip's deflate64 method */
888 # define WSIZE 0x8000 /* window size--must be a power of two, and */
889 # endif /* at least 32K for zip's deflate method */
894 # define INT_16BIT /* on 16-bit systems int size is 16 bits */
897 # define nearmalloc malloc
898 # define nearfree free
899 # if (!defined(__IBMC__) || !defined(OS2))
909 #if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
910 # undef DYNALLOC_CRCTAB
913 #if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
914 # undef DYNALLOC_CRCTAB /* not safe with reentrant code */
917 #if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
918 # ifdef DYNALLOC_CRCTAB
919 # undef DYNALLOC_CRCTAB
923 #if (defined(USE_ZLIB) && defined(ASM_CRC))
928 # ifdef IZ_CRC_BE_OPTIMIZ
929 # undef IZ_CRC_BE_OPTIMIZ
931 # ifdef IZ_CRC_LE_OPTIMIZ
932 # undef IZ_CRC_LE_OPTIMIZ
935 #if (!defined(IZ_CRC_BE_OPTIMIZ) && !defined(IZ_CRC_LE_OPTIMIZ))
936 # ifdef IZ_CRCOPTIM_UNFOLDTBL
937 # undef IZ_CRCOPTIM_UNFOLDTBL
942 # if (defined(MED_MEM) || defined(SMALL_MEM))
943 # define INBUFSIZ 2048 /* works for MS-DOS small model */
945 # define INBUFSIZ 8192 /* larger buffers for real OSes */
949 #if (defined(INT_16BIT) && (defined(USE_DEFLATE64) || lenEOL > 1))
950 /* For environments using 16-bit integers OUTBUFSIZ must be limited to
951 * less than 64k (do_string() uses "unsigned" in calculations involving
952 * OUTBUFSIZ). This is achieved by defining MED_MEM when WSIZE = 64k (aka
953 * Deflate64 support enabled) or EOL markers contain multiple characters.
954 * (The rule gets applied AFTER the default rule for INBUFSIZ because it
955 * is not neccessary to reduce INBUFSIZE in this case.)
957 # if (!defined(SMALL_MEM) && !defined(MED_MEM))
962 /* Logic for case of small memory, length of EOL > 1: if OUTBUFSIZ == 2048,
963 * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
964 * and transbuf 1040 bytes. Have room for 32 extra EOL chars; 1008/32 == 31.5
965 * chars/line, smaller than estimated 35-70 characters per line for C source
966 * and normal text. Hence difference is sufficient for most "average" files.
967 * (Argument scales for larger OUTBUFSIZ.)
969 #ifdef SMALL_MEM /* i.e., 16-bit OSes: MS-DOS, OS/2 1.x, etc. */
970 # define LoadFarString(x) fLoadFarString(__G__ (x))
971 # define LoadFarStringSmall(x) fLoadFarStringSmall(__G__ (x))
972 # define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
973 # if (defined(_MSC_VER) && (_MSC_VER >= 600))
974 # define zfstrcpy(dest, src) _fstrcpy((dest), (src))
975 # define zfstrcmp(s1, s2) _fstrcmp((s1), (s2))
977 # if !(defined(SFX) || defined(FUNZIP))
978 # if (defined(_MSC_VER))
979 # define zfmalloc(sz) _fmalloc((sz))
980 # define zffree(x) _ffree(x)
982 # if (defined(__TURBOC__))
984 # define zfmalloc(sz) farmalloc((unsigned long)(sz))
985 # define zffree(x) farfree(x)
987 # endif /* !(SFX || FUNZIP) */
989 # define Far far /* __far only works for MSC 6.00, not 6.0a or Borland */
991 # define OUTBUFSIZ INBUFSIZ
993 # define RAWBUFSIZ (OUTBUFSIZ>>1)
995 # define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
997 # define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
998 typedef short shrint
; /* short/int or "shrink int" (unshrink) */
1000 # define zfstrcpy(dest, src) strcpy((dest), (src))
1001 # define zfstrcmp(s1, s2) strcmp((s1), (s2))
1002 # define zfmalloc malloc
1003 # define zffree(x) free(x)
1005 # define LoadFarString(x) Qstrfix(x) /* fix up _ for '.' */
1006 # define LoadFarStringSmall(x) Qstrfix(x)
1007 # define LoadFarStringSmall2(x) Qstrfix(x)
1009 # define LoadFarString(x) (char *)(x)
1010 # define LoadFarStringSmall(x) (char *)(x)
1011 # define LoadFarStringSmall2(x) (char *)(x)
1014 # define OUTBUFSIZ 0xFF80 /* can't malloc arrays of 0xFFE8 or more */
1015 # define TRANSBUFSIZ 0xFF80
1016 typedef short shrint
;
1018 # define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
1019 # define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
1021 typedef short shrint
;
1023 typedef int shrint
; /* for efficiency/speed, we hope... */
1025 # endif /* ?MED_MEM */
1026 # define RAWBUFSIZ OUTBUFSIZ
1027 #endif /* ?SMALL_MEM */
1041 #ifdef SFX /* disable some unused features for SFX executables */
1051 # ifdef CHEAP_SFX_AUTORUN
1052 # ifndef NO_SFX_EXDIR
1053 # define NO_SFX_EXDIR
1056 # ifndef NO_SFX_EXDIR
1067 /* user may have defined both by accident... NOTIMESTAMP takes precedence */
1068 #if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
1072 #if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
1073 # define COPYRIGHT_CLEAN
1076 /* The LZW patent is expired worldwide since 2004-Jul-07, so USE_UNSHRINK
1077 * is now enabled by default. See unshrink.c.
1079 #if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
1080 # define USE_UNSHRINK
1091 # define PIPE_ERROR (errno == EPIPE)
1094 /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
1096 # define FOPR "r","ctx=stm"
1097 # define FOPM "r+","ctx=stm","rfm=fix","mrs=512"
1098 # define FOPW "w","ctx=stm","rfm=fix","mrs=512"
1099 # define FOPWR "w+","ctx=stm","rfm=fix","mrs=512"
1103 /* Binary files must be RECFM=F,LRECL=1 for ftell() to get correct pos */
1104 /* ...unless byteseek is used. Let's try that for a while. */
1105 # define FOPR "rb,byteseek"
1106 # define FOPM "r+b,byteseek"
1108 # define FOPW "wb,recfm=u,lrecl=32760,byteseek" /* New binary files */
1109 # define FOPWE "wb" /* Existing binary files */
1110 # define FOPWT "w,lrecl=133" /* New text files */
1111 # define FOPWTE "w" /* Existing text files */
1113 # define FOPW "wb,recfm=v,lrecl=32760"
1116 #endif /* CMS_MVS */
1118 #ifdef TOPS20 /* TOPS-20 MODERN? You kidding? */
1122 /* Defaults when nothing special has been defined previously. */
1137 # define FOPWR "w+b"
1155 #endif /* ?MODERN */
1158 * If <limits.h> exists on most systems, should include that, since it may
1159 * define some or all of the following: NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
1162 #ifdef DOS_FLX_NLM_OS2_W32
1163 # include <limits.h>
1167 * Unfortunately, on VMS, <limits.h> exists, and is included by <stdlib.h>
1168 * (so it's pretty much unavoidable), and it defines PATH_MAX to a fixed
1169 * short value (256, correct only for older systems without ODS-5 support),
1170 * rather than one based on the real RMS NAM[L] situation. So, we
1171 * artificially undefine it here, to allow our better-defined _MAX_PATH
1172 * (see vms/vmscfg.h) to be used.
1180 # define PATH_MAX MAXPATHLEN /* in <sys/param.h> on some systems */
1183 # define PATH_MAX _MAX_PATH
1185 # if FILENAME_MAX > 255
1186 # define PATH_MAX FILENAME_MAX /* used like PATH_MAX on some systems */
1188 # define PATH_MAX 1024
1190 # endif /* ?_MAX_PATH */
1191 # endif /* ?MAXPATHLEN */
1192 #endif /* !PATH_MAX */
1195 * buffer size required to hold the longest legal local filepath
1196 * (including the trailing '\0')
1198 #define FILNAMSIZ PATH_MAX
1200 #ifdef UNICODE_SUPPORT
1201 # if !(defined(UTF8_MAYBE_NATIVE) || defined(UNICODE_WCHAR))
1202 # undef UNICODE_SUPPORT
1206 * Include <locale.h> here if it will be needed later for Unicode.
1207 * Otherwise, SETLOCALE may be defined here, and then defined again
1208 * (differently) when <locale.h> is read later.
1210 #ifdef UNICODE_SUPPORT
1211 # ifdef UNICODE_WCHAR
1212 # if !(defined(_WIN32_WCE) || defined(POCKET_UNZIP))
1216 # ifndef _MBCS /* no need to include <locale.h> twice, see below */
1217 # include <locale.h>
1219 # define SETLOCALE(category, locale) setlocale(category, locale)
1222 #endif /* UNICODE_SUPPORT */
1224 /* DBCS support for Info-ZIP (mainly for japanese (-: )
1225 * by Yoshioka Tsuneo (QWF00133@nifty.ne.jp,tsuneo-y@is.aist-nara.ac.jp)
1228 # include <locale.h>
1229 /* Multi Byte Character Set */
1230 # define ___MBS_TMP_DEF char *___tmp_ptr;
1231 # define ___TMP_PTR ___tmp_ptr
1233 # define NEED_UZMBCLEN
1234 # define CLEN(ptr) (int)uzmbclen((ZCONST unsigned char *)(ptr))
1237 # define PREINCSTR(ptr) (ptr += CLEN(ptr))
1239 # define POSTINCSTR(ptr) (___TMP_PTR=(char *)(ptr), PREINCSTR(ptr),___TMP_PTR)
1240 char *plastchar
OF((ZCONST
char *ptr
, extent len
));
1241 # define lastchar(ptr, len) ((int)(unsigned)*plastchar(ptr, len))
1243 # define NEED_UZMBSCHR
1244 # define MBSCHR(str,c) (char *)uzmbschr((ZCONST unsigned char *)(str), c)
1247 # define NEED_UZMBSRCHR
1248 # define MBSRCHR(str,c) (char *)uzmbsrchr((ZCONST unsigned char *)(str), c)
1251 # define SETLOCALE(category, locale) setlocale(category, locale)
1254 # define ___MBS_TMP_DEF
1256 # define CLEN(ptr) 1
1257 # define PREINCSTR(ptr) (++(ptr))
1258 # define POSTINCSTR(ptr) ((ptr)++)
1259 # define plastchar(ptr, len) (&ptr[(len)-1])
1260 # define lastchar(ptr, len) (ptr[(len)-1])
1261 # define MBSCHR(str, c) strchr(str, c)
1262 # define MBSRCHR(str, c) strrchr(str, c)
1264 # define SETLOCALE(category, locale)
1267 #define INCSTR(ptr) PREINCSTR(ptr)
1270 #if (defined(MALLOC_WORK) && !defined(MY_ZCALLOC))
1271 /* Any system without a special calloc function */
1273 # define zcalloc(items, size) \
1274 (zvoid far *)calloc((unsigned)(items), (unsigned)(size))
1277 # define zcfree free
1279 #endif /* MALLOC_WORK && !MY_ZCALLOC */
1281 #if (defined(CRAY) && defined(ZMEM))
1287 # define memcmp(b1,b2,len) bcmp(b2,b1,len)
1288 # define memcpy(dest,src,len) bcopy(src,dest,len)
1289 # define memzero bzero
1291 # define memzero(dest,len) memset(dest,0,len)
1295 # define TRUE 1 /* sort of obvious */
1307 #if (!defined(S_IEXEC) && defined(S_IXUSR))
1308 # define S_IEXEC S_IXUSR
1311 #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
1314 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
1316 #endif /* UNIX && S_IFLNK && !MTS */
1320 # define S_ISDIR(m) (FALSE)
1322 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1327 # define IS_VOLID(m) ((m) & 0x08)
1330 /***********************************/
1331 /* LARGE_FILE_SUPPORT */
1332 /***********************************/
1333 /* This whole section lifted from Zip 3b tailor.h
1335 * Types are in OS dependent headers (eg, w32cfg.h)
1337 * LARGE_FILE_SUPPORT and ZIP64_SUPPORT are automatically
1338 * set in OS dependent headers (for some ports) based on the port and compiler.
1340 * Function prototypes are below as OF is defined earlier in this file
1341 * but after OS dependent header is included.
1343 * E. Gordon 9/21/2003
1345 * Lifted and placed here 6/7/2004 - Myles Bennett
1347 #ifdef LARGE_FILE_SUPPORT
1348 /* 64-bit Large File Support */
1350 /* ---------------------------- */
1352 # if defined(UNIX) || defined(VMS)
1354 /* 64-bit stat functions */
1356 # define zfstat fstat
1359 # define zlseek lseek
1360 # define zfseeko fseeko
1363 # define zftello ftello
1366 # define zfopen fopen
1367 # define zfdopen fdopen
1369 # endif /* UNIX || VMS */
1371 /* ---------------------------- */
1375 # if defined(_MSC_VER) || defined(__MINGW32__) || defined(__LCC__)
1376 /* MS C (VC), MinGW GCC port and LCC-32 use the MS C Runtime lib */
1378 /* 64-bit stat functions */
1379 # define zstat _stati64
1380 # define zfstat _fstati64
1383 # define zlseek _lseeki64
1385 # if defined(_MSC_VER) && (_MSC_VER >= 1400)
1386 /* Beginning with VS 8.0 (Visual Studio 2005, MSC 14), the Microsoft
1387 C rtl publishes its (previously internal) implmentations of
1388 "fseeko" and "ftello" for 64-bit file offsets. */
1390 # define zfseeko _fseeki64
1392 # define zftello _ftelli64
1394 # else /* not (defined(_MSC_VER) && (_MSC_VER >= 1400)) */
1396 # if defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ >= 0x800)
1397 /* Up-to-date versions of MinGW define the macro __MSVCRT_VERSION__
1398 to denote the version of the MS C rtl dll used for linking. When
1399 configured to link against the runtime of MS Visual Studio 8 (or
1400 newer), the built-in 64-bit fseek/ftell functions are available. */
1402 # define zfseeko _fseeki64
1404 # define zftello _ftelli64
1406 # else /* !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__>=0x800)) */
1407 /* The version of the C runtime is lower than MSC 14 or unknown. */
1409 /* The newest MinGW port contains built-in extensions to the MSC rtl
1410 that provide fseeko and ftello, but our implementations will do
1413 int zfseeko
OF((FILE *, zoff_t
, int));
1416 zoff_t zftello
OF((FILE *));
1418 # endif /* ? (__MSVCRT_VERSION__ >= 0x800) */
1419 # endif /* ? (_MSC_VER >= 1400) */
1422 # define zfopen fopen
1423 # define zfdopen fdopen
1425 # endif /* _MSC_VER || __MINGW__ || __LCC__ */
1428 /* CYGWIN GCC Posix emulator on Windows
1429 (configuration not yet finished/tested) */
1431 /* 64-bit stat functions */
1432 # define zstat _stati64
1433 # define zfstat _fstati64
1436 # define zlseek _lseeki64
1439 # define zfseeko fseeko
1442 # define zftello ftello
1445 # define zfopen fopen
1446 # define zfdopen fdopen
1449 # if defined(__WATCOMC__) || defined(__BORLANDC__)
1450 /* WATCOM C and Borland C provide their own C runtime libraries,
1451 but they are sufficiently compatible with MS CRTL. */
1453 /* 64-bit stat functions */
1454 # define zstat _stati64
1455 # define zfstat _fstati64
1459 # define zlseek _lseeki64
1463 int zfseeko
OF((FILE *, zoff_t
, int));
1466 zoff_t zftello
OF((FILE *));
1469 # define zfopen fopen
1470 # define zfdopen fdopen
1476 /* 64-bit stat functions */
1489 /* No Large File Support */
1491 # ifndef REGULUS /* returns the inode number on success(!)...argh argh argh */
1494 # define zfstat fstat
1495 # define zlseek lseek
1496 # define zfseeko fseek
1497 # define zftello ftell
1498 # define zfopen fopen
1499 # define zfdopen fdopen
1501 # if defined(UNIX) || defined(VMS) || defined(WIN32)
1502 /* For these systems, implement "64bit file vs. 32bit prog" check */
1503 # ifndef DO_SAFECHECK_2GB
1504 # define DO_SAFECHECK_2GB
1510 /* No "64bit file vs. 32bit prog" check for SFX stub, to save space */
1511 #if (defined(DO_SAFECHECK_2GB) && defined(SFX))
1512 # undef DO_SAFECHECK_2GB
1516 # ifdef WILD_STAT_BUG
1517 # define SSTAT(path,pbuf) (iswild(path) || zstat(path,pbuf))
1519 # define SSTAT zstat
1524 /* Default fzofft() format selection. */
1528 # ifdef LARGE_FILE_SUPPORT
1529 # define FZOFFT_FMT "ll"
1530 # define FZOFFT_HEX_WID_VALUE "16"
1531 # else /* def LARGE_FILE_SUPPORT */
1532 # define FZOFFT_FMT "l"
1533 # define FZOFFT_HEX_WID_VALUE "8"
1534 # endif /* def LARGE_FILE_SUPPORT */
1536 #endif /* ndef FZOFFT_FMT */
1538 #define FZOFFT_HEX_WID ((char *) -1)
1539 #define FZOFFT_HEX_DOT_WID ((char *) -2)
1541 #define FZOFFT_NUM 4 /* Number of chambers. */
1542 #define FZOFFT_LEN 24 /* Number of characters/chamber. */
1545 #ifdef SHORT_SYMS /* Mark Williams C, ...? */
1546 # define extract_or_test_files xtr_or_tst_files
1547 # define extract_or_test_member xtr_or_tst_member
1550 #ifdef REALLY_SHORT_SYMS /* TOPS-20 linker: first 6 chars */
1551 # define process_cdir_file_hdr XXpcdfh
1552 # define process_local_file_hdr XXplfh
1553 # define extract_or_test_files XXxotf /* necessary? */
1554 # define extract_or_test_member XXxotm /* necessary? */
1555 # define check_for_newer XXcfn
1556 # define overwrite_all XXoa
1557 # define process_all_files XXpaf
1558 # define extra_field XXef
1559 # define explode_lit8 XXel8
1560 # define explode_lit4 XXel4
1561 # define explode_nolit8 XXnl8
1562 # define explode_nolit4 XXnl4
1563 # define cpdist8 XXcpdist8
1564 # define inflate_codes XXic
1565 # define inflate_stored XXis
1566 # define inflate_fixed XXif
1567 # define inflate_dynamic XXid
1568 # define inflate_block XXib
1569 # define maxcodemax XXmax
1572 #ifndef S_TIME_T_MAX /* max value of signed (>= 32-bit) time_t */
1573 # define S_TIME_T_MAX ((time_t)(ulg)0x7fffffffL)
1575 #ifndef U_TIME_T_MAX /* max value of unsigned (>= 32-bit) time_t */
1576 # define U_TIME_T_MAX ((time_t)(ulg)0xffffffffL)
1578 #ifdef DOSTIME_MINIMUM /* min DOSTIME value (1980-01-01) */
1579 # undef DOSTIME_MINIMUM
1581 #define DOSTIME_MINIMUM ((ulg)0x00210000L)
1582 #ifdef DOSTIME_2038_01_18 /* approximate DOSTIME equivalent of */
1583 # undef DOSTIME_2038_01_18 /* the signed-32-bit time_t limit */
1585 #define DOSTIME_2038_01_18 ((ulg)0x74320000L)
1588 # define ZSUFX "_zip"
1589 # define ALT_ZSUFX ".zip"
1592 # define ZSUFX "/zip"
1594 # define ZSUFX ".zip"
1596 # define ALT_ZSUFX ".ZIP" /* Unix-only so far (only case-sensitive fs) */
1599 #define CENTRAL_HDR_SIG "\001\002" /* the infamous "PK" signature bytes, */
1600 #define LOCAL_HDR_SIG "\003\004" /* w/o "PK" (so unzip executable not */
1601 #define END_CENTRAL_SIG "\005\006" /* mistaken for zipfile itself) */
1602 #define EXTD_LOCAL_SIG "\007\010" /* [ASCII "\113" == EBCDIC "\080" ??] */
1604 /** internal-only return codes **/
1605 #define IZ_DIR 76 /* potential zipfile is a directory */
1606 /* special return codes for mapname() */
1607 #define MPN_OK 0 /* mapname successful */
1608 #define MPN_INF_TRUNC (1<<8) /* caution - filename truncated */
1609 #define MPN_INF_SKIP (2<<8) /* info - skipped because nothing to do */
1610 #define MPN_ERR_SKIP (3<<8) /* error - entry skipped */
1611 #define MPN_ERR_TOOLONG (4<<8) /* error - path too long */
1612 #define MPN_NOMEM (10<<8) /* error - out of memory, file skipped */
1613 #define MPN_CREATED_DIR (16<<8) /* directory created: set time & permission */
1614 #define MPN_VOL_LABEL (17<<8) /* volume label, but can't set on hard disk */
1615 #define MPN_INVALID (99<<8) /* internal logic error, should never reach */
1616 /* mask for internal mapname&checkdir return codes */
1617 #define MPN_MASK 0x7F00
1618 /* error code for extracting/testing extra field blocks */
1619 #define IZ_EF_TRUNC 79 /* local extra field truncated (PKZIP'd) */
1621 /* choice of activities for do_string() */
1622 #define SKIP 0 /* skip header block */
1623 #define DISPLAY 1 /* display archive comment (ASCII) */
1624 #define DISPL_8 5 /* display file comment (ext. ASCII) */
1625 #define DS_FN 2 /* read filename (ext. ASCII, chead) */
1626 #define DS_FN_C 2 /* read filename from central header */
1627 #define DS_FN_L 6 /* read filename from local header */
1628 #define EXTRA_FIELD 3 /* copy extra field into buffer */
1631 # define FILENOTE 4 /* convert file comment to filenote */
1633 #if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
1634 # define CHECK_AUTORUN 7 /* copy command, display remainder */
1635 # define CHECK_AUTORUN_Q 8 /* copy command, skip remainder */
1638 #define DOES_NOT_EXIST -1 /* return values for check_for_newer() */
1639 #define EXISTS_AND_OLDER 0
1640 #define EXISTS_AND_NEWER 1
1642 #define OVERWRT_QUERY 0 /* status values for G.overwrite_mode */
1643 #define OVERWRT_ALWAYS 1
1644 #define OVERWRT_NEVER 2
1646 #define IS_OVERWRT_ALL (G.overwrite_mode == OVERWRT_ALWAYS)
1647 #define IS_OVERWRT_NONE (G.overwrite_mode == OVERWRT_NEVER)
1650 /* return codes for VMS-specific open_outfile() function */
1651 # define OPENOUT_OK 0 /* file openend normally */
1652 # define OPENOUT_FAILED 1 /* file open failed */
1653 # define OPENOUT_SKIPOK 2 /* file not opened, skip at error level OK */
1654 # define OPENOUT_SKIPWARN 3 /* file not opened, skip at error level WARN */
1657 #define ROOT 0 /* checkdir() extract-to path: called once */
1658 #define INIT 1 /* allocate buildpath: called once per member */
1659 #define APPEND_DIR 2 /* append a dir comp.: many times per member */
1660 #define APPEND_NAME 3 /* append actual filename: once per member */
1661 #define GETPATH 4 /* retrieve the complete path and free it */
1662 #define END 5 /* free root path prior to exiting program */
1664 /* version_made_by codes (central dir): make sure these */
1665 /* are not defined on their respective systems!! */
1666 #define FS_FAT_ 0 /* filesystem used by MS-DOS, OS/2, Win32 */
1671 #define ATARI_ 5 /* what if it's a minix filesystem? [cjh] */
1672 #define FS_HPFS_ 6 /* filesystem used by OS/2 (and NT 3.x) */
1673 #define MAC_ 7 /* HFS filesystem used by MacOS */
1677 #define FS_NTFS_ 11 /* filesystem used by Windows NT */
1679 #define ACORN_ 13 /* Archimedes Acorn RISC OS */
1680 #define FS_VFAT_ 14 /* filesystem used by Windows 95, NT */
1682 #define BEOS_ 16 /* hybrid POSIX/database filesystem */
1683 #define TANDEM_ 17 /* Tandem NSK */
1684 #define THEOS_ 18 /* THEOS */
1685 #define MAC_OSX_ 19 /* Mac OS/X (Darwin) */
1686 #define ATHEOS_ 30 /* AtheOS */
1687 #define NUM_HOSTS 31 /* index of last system + 1 */
1688 /* don't forget to update zipinfo.c appropiately if NUM_HOSTS changes! */
1690 #define STORED 0 /* compression methods */
1699 #define ENHDEFLATED 9
1700 #define DCLIMPLODED 10
1703 #define IBMTERSED 18
1704 #define IBMLZ77ED 19
1705 #define WAVPACKED 97
1707 #define NUM_METHODS 17 /* number of known method IDs */
1708 /* don't forget to update list.c (list_files()), extract.c and zipinfo.c
1709 * appropriately if NUM_METHODS changes */
1711 /* (the PK-class error codes are public and have been moved into unzip.h) */
1713 #define DF_MDY 0 /* date format 10/26/91 (USA only) */
1714 #define DF_DMY 1 /* date format 26/10/91 (most of the world) */
1715 #define DF_YMD 2 /* date format 91/10/26 (a few countries) */
1717 /*---------------------------------------------------------------------------
1718 Extra-field block ID values and offset info.
1719 ---------------------------------------------------------------------------*/
1720 /* extra-field ID values, all little-endian: */
1721 #define EF_PKSZ64 0x0001 /* PKWARE's 64-bit filesize extensions */
1722 #define EF_AV 0x0007 /* PKWARE's authenticity verification */
1723 #define EF_EFS 0x0008 /* PKWARE's extended language encoding */
1724 #define EF_OS2 0x0009 /* OS/2 extended attributes */
1725 #define EF_PKW32 0x000a /* PKWARE's Win95/98/WinNT filetimes */
1726 #define EF_PKVMS 0x000c /* PKWARE's VMS */
1727 #define EF_PKUNIX 0x000d /* PKWARE's Unix */
1728 #define EF_PKFORK 0x000e /* PKWARE's future stream/fork descriptors */
1729 #define EF_PKPATCH 0x000f /* PKWARE's patch descriptor */
1730 #define EF_PKPKCS7 0x0014 /* PKWARE's PKCS#7 store for X.509 Certs */
1731 #define EF_PKFX509 0x0015 /* PKWARE's file X.509 Cert&Signature ID */
1732 #define EF_PKCX509 0x0016 /* PKWARE's central dir X.509 Cert ID */
1733 #define EF_PKENCRHD 0x0017 /* PKWARE's Strong Encryption header */
1734 #define EF_PKRMCTL 0x0018 /* PKWARE's Record Management Controls*/
1735 #define EF_PKLSTCS7 0x0019 /* PKWARE's PKCS#7 Encr. Recipient Cert List */
1736 #define EF_PKIBM 0x0065 /* PKWARE's IBM S/390 & AS/400 attributes */
1737 #define EF_PKIBM2 0x0066 /* PKWARE's IBM S/390 & AS/400 compr. attribs */
1738 #define EF_IZVMS 0x4d49 /* Info-ZIP's VMS ("IM") */
1739 #define EF_IZUNIX 0x5855 /* Info-ZIP's first Unix[1] ("UX") */
1740 #define EF_IZUNIX2 0x7855 /* Info-ZIP's second Unix[2] ("Ux") */
1741 #define EF_IZUNIX3 0x7875 /* Info-ZIP's newest Unix[3] ("ux") */
1742 #define EF_TIME 0x5455 /* universal timestamp ("UT") */
1743 #define EF_UNIPATH 0x7075 /* Info-ZIP Unicode Path ("up") */
1744 #define EF_UNICOMNT 0x6375 /* Info-ZIP Unicode Comment ("uc") */
1745 #define EF_MAC3 0x334d /* Info-ZIP's new Macintosh (= "M3") */
1746 #define EF_JLMAC 0x07c8 /* Johnny Lee's old Macintosh (= 1992) */
1747 #define EF_ZIPIT 0x2605 /* Thomas Brown's Macintosh (ZipIt) */
1748 #define EF_ZIPIT2 0x2705 /* T. Brown's Mac (ZipIt) v 1.3.8 and newer ? */
1749 #define EF_SMARTZIP 0x4d63 /* Mac SmartZip by Marco Bambini */
1750 #define EF_VMCMS 0x4704 /* Info-ZIP's VM/CMS ("\004G") */
1751 #define EF_MVS 0x470f /* Info-ZIP's MVS ("\017G") */
1752 #define EF_ACL 0x4c41 /* (OS/2) access control list ("AL") */
1753 #define EF_NTSD 0x4453 /* NT security descriptor ("SD") */
1754 #define EF_ATHEOS 0x7441 /* AtheOS ("At") */
1755 #define EF_BEOS 0x6542 /* BeOS ("Be") */
1756 #define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
1757 #define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
1758 #define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
1759 #define EF_TANDEM 0x4154 /* Tandem NSK ("TA") */
1760 #define EF_THEOS 0x6854 /* Jean-Michel Dubois' Theos "Th" */
1761 #define EF_THEOSO 0x4854 /* old Theos port */
1762 #define EF_MD5 0x4b46 /* Fred Kantor's MD5 ("FK") */
1763 #define EF_ASIUNIX 0x756e /* ASi's Unix ("nu") */
1765 #define EB_HEADSIZE 4 /* length of extra field block header */
1766 #define EB_ID 0 /* offset of block ID in header */
1767 #define EB_LEN 2 /* offset of data length field in header */
1768 #define EB_UCSIZE_P 0 /* offset of ucsize field in compr. data */
1769 #define EB_CMPRHEADLEN 6 /* lenght of compression header */
1771 #define EB_UX_MINLEN 8 /* minimal "UX" field contains atime, mtime */
1772 #define EB_UX_FULLSIZE 12 /* full "UX" field (atime, mtime, uid, gid) */
1773 #define EB_UX_ATIME 0 /* offset of atime in "UX" extra field data */
1774 #define EB_UX_MTIME 4 /* offset of mtime in "UX" extra field data */
1775 #define EB_UX_UID 8 /* byte offset of UID in "UX" field data */
1776 #define EB_UX_GID 10 /* byte offset of GID in "UX" field data */
1778 #define EB_UX2_MINLEN 4 /* minimal "Ux" field contains UID/GID */
1779 #define EB_UX2_UID 0 /* byte offset of UID in "Ux" field data */
1780 #define EB_UX2_GID 2 /* byte offset of GID in "Ux" field data */
1781 #define EB_UX2_VALID (1 << 8) /* UID/GID present */
1783 #define EB_UX3_MINLEN 7 /* minimal "ux" field size (2-byte UID/GID) */
1785 #define EB_UT_MINLEN 1 /* minimal UT field contains Flags byte */
1786 #define EB_UT_FLAGS 0 /* byte offset of Flags field */
1787 #define EB_UT_TIME1 1 /* byte offset of 1st time value */
1788 #define EB_UT_FL_MTIME (1 << 0) /* mtime present */
1789 #define EB_UT_FL_ATIME (1 << 1) /* atime present */
1790 #define EB_UT_FL_CTIME (1 << 2) /* ctime present */
1792 #define EB_FLGS_OFFS 4 /* offset of flags area in generic compressed
1793 extra field blocks (BEOS, MAC, and others) */
1794 #define EB_OS2_HLEN 4 /* size of OS2/ACL compressed data header */
1795 #define EB_BEOS_HLEN 5 /* length of BeOS&AtheOS e.f attribute header */
1796 #define EB_BE_FL_UNCMPR 0x01 /* "BeOS&AtheOS attribs uncompr." bit flag */
1797 #define EB_MAC3_HLEN 14 /* length of Mac3 attribute block header */
1798 #define EB_SMARTZIP_HLEN 64 /* fixed length of the SmartZip extra field */
1799 #define EB_M3_FL_DATFRK 0x01 /* "this entry is data fork" flag */
1800 #define EB_M3_FL_UNCMPR 0x04 /* "Mac3 attributes uncompressed" bit flag */
1801 #define EB_M3_FL_TIME64 0x08 /* "Mac3 time fields are 64 bit wide" flag */
1802 #define EB_M3_FL_NOUTC 0x10 /* "Mac3 timezone offset fields missing" flag */
1804 #define EB_NTSD_C_LEN 4 /* length of central NT security data */
1805 #define EB_NTSD_L_LEN 5 /* length of minimal local NT security data */
1806 #define EB_NTSD_VERSION 4 /* offset of NTSD version byte */
1807 #define EB_NTSD_MAX_VER (0) /* maximum version # we know how to handle */
1809 #define EB_ASI_CRC32 0 /* offset of ASI Unix field's crc32 checksum */
1810 #define EB_ASI_MODE 4 /* offset of ASI Unix permission mode field */
1812 #define EB_IZVMS_HLEN 12 /* length of IZVMS attribute block header */
1813 #define EB_IZVMS_FLGS 4 /* offset of compression type flag */
1814 #define EB_IZVMS_UCSIZ 6 /* offset of ucsize field in IZVMS header */
1815 #define EB_IZVMS_BCMASK 07 /* 3 bits for compression type */
1816 #define EB_IZVMS_BCSTOR 0 /* Stored */
1817 #define EB_IZVMS_BC00 1 /* 0byte -> 0bit compression */
1818 #define EB_IZVMS_BCDEFL 2 /* Deflated */
1821 /*---------------------------------------------------------------------------
1822 True sizes of the various headers (excluding their 4-byte signatures),
1823 as defined by PKWARE--so it is not likely that these will ever change.
1824 But if they do, make sure both these defines AND the typedefs below get
1825 updated accordingly.
1828 The Zip64 End Of Central Directory record is variable size and now
1829 comes in two flavors, version 1 and the new version 2 that supports
1830 central directory encryption. We only use the old fields at the
1831 top of the Zip64 EOCDR, and this block is a fixed size still, but
1832 need to be aware of the stuff following.
1833 ---------------------------------------------------------------------------*/
1834 #define LREC_SIZE 26 /* lengths of local file headers, central */
1835 #define CREC_SIZE 42 /* directory headers, end-of-central-dir */
1836 #define ECREC_SIZE 18 /* record, zip64 end-of-cent-dir locator */
1837 #define ECLOC64_SIZE 16 /* and zip64 end-of-central-dir record, */
1838 #define ECREC64_SIZE 52 /* respectively */
1840 #define MAX_BITS 13 /* used in unshrink() */
1841 #define HSIZE (1 << MAX_BITS) /* size of global work area */
1843 #define LF 10 /* '\n' on ASCII machines; must be 10 due to EBCDIC */
1844 #define CR 13 /* '\r' on ASCII machines; must be 13 due to EBCDIC */
1845 #define CTRLZ 26 /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
1848 # define foreign(c) ascii[(uch)(c)]
1849 # define native(c) ebcdic[(uch)(c)]
1850 # define NATIVE "EBCDIC"
1855 # define ENV_UNZIP "UNZIP_OPTS" /* names of environment variables */
1856 # define ENV_ZIPINFO "ZIPINFO_OPTS"
1859 # define ENV_UNZIP "Unzip$Options"
1860 # define ENV_ZIPINFO "Zipinfo$Options"
1861 # define ENV_UNZIPEXTS "Unzip$Exts"
1864 # define ENV_UNZIP "UNZIP" /* the standard names */
1865 # define ENV_ZIPINFO "ZIPINFO"
1867 #define ENV_UNZIP2 "UNZIPOPT" /* alternate names, for zip compat. */
1868 #define ENV_ZIPINFO2 "ZIPINFOOPT"
1870 #if (!defined(QQ) && !defined(NOQQ))
1874 #ifdef QQ /* Newtware version: no file */
1875 # define QCOND (!uO.qflag) /* comments with -vq or -vqq */
1876 #else /* Bill Davidsen version: no way to */
1877 # define QCOND (longhdr) /* kill file comments when listing */
1881 # define QCOND2 (uO.qflag < 2)
1883 # define QCOND2 (!uO.qflag)
1886 #ifdef WILD_STOP_AT_DIR
1887 # define __WDLPRO , int sepc
1888 # define __WDL , sepc
1889 # define __WDLDEF int sepc;
1890 # define WISEP , (uO.W_flag ? '/' : '\0')
1905 #ifdef ZIP64_SUPPORT
1906 # ifndef Z_UINT8_DEFINED
1907 # if (defined(__GNUC__) || defined(__hpux) || defined(__SUNPRO_C))
1908 typedef unsigned long long z_uint8
;
1910 typedef unsigned __int64 z_uint8
;
1912 # define Z_UINT8_DEFINED
1915 #ifndef Z_UINT4_DEFINED
1916 # if (defined(MODERN) && !defined(NO_LIMITS_H))
1917 # if (defined(UINT_MAX) && (UINT_MAX == 0xffffffffUL))
1918 typedef unsigned int z_uint4
;
1919 # define Z_UINT4_DEFINED
1921 # if (defined(ULONG_MAX) && (ULONG_MAX == 0xffffffffUL))
1922 typedef unsigned long z_uint4
;
1923 # define Z_UINT4_DEFINED
1925 # if (defined(USHRT_MAX) && (USHRT_MAX == 0xffffffffUL))
1926 typedef unsigned short z_uint4
;
1927 # define Z_UINT4_DEFINED
1931 # endif /* MODERN && !NO_LIMITS_H */
1932 #endif /* !Z_UINT4_DEFINED */
1933 #ifndef Z_UINT4_DEFINED
1934 typedef ulg z_uint4
;
1935 # define Z_UINT4_DEFINED
1938 /* The following three user-defined unsigned integer types are used for
1939 holding zipfile entities (required widths without / with Zip64 support):
1940 a) sizes and offset of zipfile entries
1942 b) enumeration and counts of zipfile entries
1944 Remark: internally, we use 4 bytes for archive member counting in the
1945 No-Zip64 case, because UnZip supports more than 64k entries for
1946 classic Zip archives without Zip64 extensions.
1947 c) enumeration and counts of zipfile volumes of multivolume archives
1950 #ifdef ZIP64_SUPPORT
1951 typedef z_uint8 zusz_t
; /* zipentry sizes & offsets */
1952 typedef z_uint8 zucn_t
; /* archive entry counts */
1953 typedef z_uint4 zuvl_t
; /* multivolume numbers */
1954 # define MASK_ZUCN64 (~(zucn_t)0)
1955 /* In case we ever get to support an environment where z_uint8 may be WIDER
1956 than 64 bit wide, we will have to apply a construct similar to
1957 #define MASK_ZUCN64 (~(zucn_t)0 & (zucn_t)0xffffffffffffffffULL)
1958 for the 64-bit mask.
1961 typedef ulg zusz_t
; /* zipentry sizes & offsets */
1962 typedef unsigned int zucn_t
; /* archive entry counts */
1963 typedef unsigned short zuvl_t
; /* multivolume numbers */
1964 # define MASK_ZUCN64 (~(zucn_t)0)
1966 #define MASK_ZUCN16 ((zucn_t)0xFFFF)
1970 typedef unsigned short uid_t
; /* TI SysV.3 */
1971 typedef unsigned short gid_t
;
1973 typedef unsigned int uid_t
; /* SCO Xenix */
1974 typedef unsigned int gid_t
;
1978 #if (defined(GOT_UTIMBUF) || defined(sgi) || defined(ATARI))
1979 typedef struct utimbuf ztimbuf
;
1981 typedef struct ztimbuf
{
1982 time_t actime
; /* new access time */
1983 time_t modtime
; /* new modification time */
1987 typedef struct iztimes
{
1988 time_t atime
; /* new access time */
1989 time_t mtime
; /* new modification time */
1990 time_t ctime
; /* used for creation time; NOT same as st_ctime */
1993 #ifdef SET_DIR_ATTRIB
1994 typedef struct direntry
{ /* head of system-specific struct holding */
1995 struct direntry
*next
; /* defered directory attributes info */
1996 char *fn
; /* filename of directory */
1997 char buf
[1]; /* start of system-specific internal data */
1999 #endif /* SET_DIR_ATTRIB */
2002 typedef struct slinkentry
{ /* info for deferred symlink creation */
2003 struct slinkentry
*next
; /* pointer to next entry in chain */
2004 extent targetlen
; /* length of target filespec */
2005 extent attriblen
; /* length of system-specific attrib data */
2006 char *target
; /* pointer to target filespec */
2007 char *fname
; /* pointer to name of link */
2008 char buf
[1]; /* data/name/link buffer */
2010 #endif /* SYMLINKS */
2012 typedef struct min_info
{
2014 zusz_t compr_size
; /* compressed size (needed if extended header) */
2015 zusz_t uncompr_size
; /* uncompressed size (needed if extended header) */
2016 ulg crc
; /* crc (needed if extended header) */
2017 zuvl_t diskstart
; /* no of volume where this entry starts */
2020 unsigned file_attr
; /* local flavor, as used by creat(), chmod()... */
2021 unsigned encrypted
: 1; /* file encrypted: decrypt before uncompressing */
2022 unsigned ExtLocHdr
: 1; /* use time instead of CRC for decrypt check */
2023 unsigned textfile
: 1; /* file is text (according to zip) */
2024 unsigned textmode
: 1; /* file is to be extracted as text */
2025 unsigned lcflag
: 1; /* convert filename to lowercase */
2026 unsigned vollabel
: 1; /* "file" is an MS-DOS volume (disk) label */
2028 unsigned symlink
: 1; /* file is a symbolic link */
2030 unsigned HasUxAtt
: 1; /* crec ext_file_attr has Unix style mode bits */
2031 #ifdef UNICODE_SUPPORT
2032 unsigned GPFIsUTF8
: 1; /* crec gen_purpose_flag UTF-8 bit 11 is set */
2035 char Far
*cfilname
; /* central header version of filename */
2039 typedef struct VMStimbuf
{
2040 char *revdate
; /* (both roughly correspond to Unix modtime/st_mtime) */
2044 /*---------------------------------------------------------------------------
2045 Zipfile work area declarations.
2046 ---------------------------------------------------------------------------*/
2050 struct { /* unshrink(): */
2051 shrint
*Parent
; /* pointer to (8192 * sizeof(shrint)) */
2052 uch
*value
; /* pointer to 8KB char buffer */
2053 uch
*Stack
; /* pointer to another 8KB char buffer */
2055 uch
*Slide
; /* explode(), inflate(), unreduce() */
2057 #else /* !MALLOC_WORK */
2059 struct { /* unshrink(): */
2060 shrint Parent
[HSIZE
]; /* (8192 * sizeof(shrint)) == 16KB minimum */
2061 uch value
[HSIZE
]; /* 8KB */
2062 uch Stack
[HSIZE
]; /* 8KB */
2063 } shrink
; /* total = 32KB minimum; 80KB on Cray/Alpha */
2064 uch Slide
[WSIZE
]; /* explode(), inflate(), unreduce() */
2066 #endif /* ?MALLOC_WORK */
2068 #define slide G.area.Slide
2070 #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
2071 # define redirSlide G.redirect_sldptr
2073 # define redirSlide G.area.Slide
2076 /*---------------------------------------------------------------------------
2077 Zipfile layout declarations. If these headers ever change, make sure the
2078 xxREC_SIZE defines (above) change with them!
2079 ---------------------------------------------------------------------------*/
2081 typedef uch local_byte_hdr
[ LREC_SIZE
];
2082 # define L_VERSION_NEEDED_TO_EXTRACT_0 0
2083 # define L_VERSION_NEEDED_TO_EXTRACT_1 1
2084 # define L_GENERAL_PURPOSE_BIT_FLAG 2
2085 # define L_COMPRESSION_METHOD 4
2086 # define L_LAST_MOD_DOS_DATETIME 6
2088 # define L_COMPRESSED_SIZE 14
2089 # define L_UNCOMPRESSED_SIZE 18
2090 # define L_FILENAME_LENGTH 22
2091 # define L_EXTRA_FIELD_LENGTH 24
2093 typedef uch cdir_byte_hdr
[ CREC_SIZE
];
2094 # define C_VERSION_MADE_BY_0 0
2095 # define C_VERSION_MADE_BY_1 1
2096 # define C_VERSION_NEEDED_TO_EXTRACT_0 2
2097 # define C_VERSION_NEEDED_TO_EXTRACT_1 3
2098 # define C_GENERAL_PURPOSE_BIT_FLAG 4
2099 # define C_COMPRESSION_METHOD 6
2100 # define C_LAST_MOD_DOS_DATETIME 8
2102 # define C_COMPRESSED_SIZE 16
2103 # define C_UNCOMPRESSED_SIZE 20
2104 # define C_FILENAME_LENGTH 24
2105 # define C_EXTRA_FIELD_LENGTH 26
2106 # define C_FILE_COMMENT_LENGTH 28
2107 # define C_DISK_NUMBER_START 30
2108 # define C_INTERNAL_FILE_ATTRIBUTES 32
2109 # define C_EXTERNAL_FILE_ATTRIBUTES 34
2110 # define C_RELATIVE_OFFSET_LOCAL_HEADER 38
2112 typedef uch ec_byte_rec
[ ECREC_SIZE
+4 ];
2113 /* define SIGNATURE 0 space-holder only */
2114 # define NUMBER_THIS_DISK 4
2115 # define NUM_DISK_WITH_START_CEN_DIR 6
2116 # define NUM_ENTRIES_CEN_DIR_THS_DISK 8
2117 # define TOTAL_ENTRIES_CENTRAL_DIR 10
2118 # define SIZE_CENTRAL_DIRECTORY 12
2119 # define OFFSET_START_CENTRAL_DIRECTORY 16
2120 # define ZIPFILE_COMMENT_LENGTH 20
2122 typedef uch ec_byte_loc64
[ ECLOC64_SIZE
+4 ];
2123 # define NUM_DISK_START_EOCDR64 4
2124 # define OFFSET_START_EOCDR64 8
2125 # define NUM_THIS_DISK_LOC64 16
2127 typedef uch ec_byte_rec64
[ ECREC64_SIZE
+4 ];
2128 # define ECREC64_LENGTH 4
2129 # define EC_VERSION_MADE_BY_0 12
2130 # define EC_VERSION_NEEDED_0 14
2131 # define NUMBER_THIS_DSK_REC64 16
2132 # define NUM_DISK_START_CEN_DIR64 20
2133 # define NUM_ENTRIES_CEN_DIR_THS_DISK64 24
2134 # define TOTAL_ENTRIES_CENTRAL_DIR64 32
2135 # define SIZE_CENTRAL_DIRECTORY64 40
2136 # define OFFSET_START_CENTRAL_DIRECT64 48
2139 /* The following structs are used to hold all header data of a zip entry.
2140 Traditionally, the structs' layouts followed the data layout of the
2141 corresponding zipfile header structures. However, the zipfile header
2142 layouts were designed in the old ages of 16-bit CPUs, they are subject
2143 to structure padding and/or alignment issues on newer systems with a
2144 "natural word width" of more than 2 bytes.
2145 Please note that the structure members are now reordered by size
2146 (top-down), to prevent internal padding and optimize memory usage!
2148 typedef struct local_file_header
{ /* LOCAL */
2151 ulg last_mod_dos_datetime
;
2153 uch version_needed_to_extract
[2];
2154 ush general_purpose_bit_flag
;
2155 ush compression_method
;
2156 ush filename_length
;
2157 ush extra_field_length
;
2160 typedef struct central_directory_file_header
{ /* CENTRAL */
2163 zusz_t relative_offset_local_header
;
2164 ulg last_mod_dos_datetime
;
2166 ulg external_file_attributes
;
2167 zuvl_t disk_number_start
;
2168 ush internal_file_attributes
;
2169 uch version_made_by
[2];
2170 uch version_needed_to_extract
[2];
2171 ush general_purpose_bit_flag
;
2172 ush compression_method
;
2173 ush filename_length
;
2174 ush extra_field_length
;
2175 ush file_comment_length
;
2178 typedef struct end_central_dir_record
{ /* END CENTRAL */
2179 zusz_t size_central_directory
;
2180 zusz_t offset_start_central_directory
;
2181 zucn_t num_entries_centrl_dir_ths_disk
;
2182 zucn_t total_entries_central_dir
;
2183 zuvl_t number_this_disk
;
2184 zuvl_t num_disk_start_cdir
;
2185 int have_ecr64
; /* valid Zip64 ecdir-record exists */
2186 int is_zip64_archive
; /* Zip64 ecdir-record is mandatory */
2187 ush zipfile_comment_length
;
2191 /* Huffman code lookup table entry--this entry is four bytes for machines
2192 that have 16-bit pointers (e.g. PC's in the small or medium model).
2193 Valid extra bits are 0..16. e == 31 is EOB (end of block), e == 32
2194 means that v is a literal, 32 < e < 64 means that v is a pointer to
2195 the next table, which codes (e & 31) bits, and lastly e == 99 indicates
2196 an unused code. If a code with e == 99 is looked up, this implies an
2197 error in the data. */
2200 uch e
; /* number of extra bits or operation */
2201 uch b
; /* number of bits in this code or subcode */
2203 ush n
; /* literal, length base, or distance base */
2204 struct huft
*t
; /* pointer to next level of table */
2209 typedef struct _APIDocStruct
{
2223 #if (defined(OS2) && !defined(FUNZIP))
2224 # include "os2/os2data.h"
2227 #include "globals.h"
2231 /*************************/
2232 /* Function Prototypes */
2233 /*************************/
2235 /*---------------------------------------------------------------------------
2236 Functions in unzip.c (initialization routines):
2237 ---------------------------------------------------------------------------*/
2240 int MAIN
OF((int argc
, char **argv
));
2241 int unzip
OF((__GPRO__
int argc
, char **argv
));
2242 int uz_opts
OF((__GPRO__
int *pargc
, char ***pargv
));
2243 int usage
OF((__GPRO__
int error
));
2244 #endif /* !WINDLL */
2246 /*---------------------------------------------------------------------------
2247 Functions in process.c (main driver routines):
2248 ---------------------------------------------------------------------------*/
2250 int process_zipfiles
OF((__GPRO
));
2251 void free_G_buffers
OF((__GPRO
));
2252 /* static int do_seekable OF((__GPRO__ int lastchance)); */
2253 /* static int find_ecrec OF((__GPRO__ long searchlen)); */
2254 /* static int process_central_comment OF((__GPRO)); */
2255 int process_cdir_file_hdr
OF((__GPRO
));
2256 int process_local_file_hdr
OF((__GPRO
));
2257 int getZip64Data
OF((__GPRO__ ZCONST uch
*ef_buf
,
2259 #ifdef UNICODE_SUPPORT
2260 int getUnicodeData
OF((__GPRO__ ZCONST uch
*ef_buf
,
2263 unsigned ef_scan_for_izux
OF((ZCONST uch
*ef_buf
, unsigned ef_len
,
2264 int ef_is_c
, ulg dos_mdatetime
,
2265 iztimes
*z_utim
, ulg
*z_uidgid
));
2266 #if (defined(RISCOS) || defined(ACORN_FTYPE_NFS))
2267 zvoid
*getRISCOSexfield
OF((ZCONST uch
*ef_buf
, unsigned ef_len
));
2272 /*---------------------------------------------------------------------------
2273 Functions in zipinfo.c (`zipinfo-style' listing routines):
2274 ---------------------------------------------------------------------------*/
2278 int zi_opts
OF((__GPRO__
int *pargc
, char ***pargv
));
2280 void zi_end_central
OF((__GPRO
));
2281 int zipinfo
OF((__GPRO
));
2282 /* static int zi_long OF((__GPRO__ zusz_t *pEndprev)); */
2283 /* static int zi_short OF((__GPRO)); */
2284 /* static char *zi_time OF((__GPRO__ ZCONST ulg *datetimez,
2285 ZCONST time_t *modtimez, char *d_t_str));*/
2286 #endif /* !NO_ZIPINFO */
2288 /*---------------------------------------------------------------------------
2289 Functions in list.c (generic zipfile-listing routines):
2290 ---------------------------------------------------------------------------*/
2292 int list_files
OF((__GPRO
));
2294 int get_time_stamp
OF((__GPRO__
time_t *last_modtime
,
2297 int ratio
OF((zusz_t uc
, zusz_t c
));
2298 void fnprint
OF((__GPRO
));
2302 /*---------------------------------------------------------------------------
2303 Functions in fileio.c:
2304 ---------------------------------------------------------------------------*/
2306 int open_input_file
OF((__GPRO
));
2307 int open_outfile
OF((__GPRO
)); /* also vms.c */
2308 void undefer_input
OF((__GPRO
));
2309 void defer_leftover_input
OF((__GPRO
));
2310 unsigned readbuf
OF((__GPRO__
char *buf
, register unsigned len
));
2311 int readbyte
OF((__GPRO
));
2312 int fillinbuf
OF((__GPRO
));
2313 int seek_zipf
OF((__GPRO__ zoff_t abs_offset
));
2315 int flush
OF((__GPRO__ ulg size
)); /* actually funzip.c */
2317 int flush
OF((__GPRO__ uch
*buf
, ulg size
, int unshrink
));
2319 /* static int disk_error OF((__GPRO)); */
2320 void handler
OF((int signal
));
2321 time_t dos_to_unix_time
OF((ulg dos_datetime
));
2322 int check_for_newer
OF((__GPRO__
char *filename
)); /* os2,vmcms,vms */
2323 int do_string
OF((__GPRO__
unsigned int length
, int option
));
2324 ush makeword
OF((ZCONST uch
*b
));
2325 ulg makelong
OF((ZCONST uch
*sig
));
2326 zusz_t makeint64
OF((ZCONST uch
*sig
));
2327 char *fzofft
OF((__GPRO__ zoff_t val
,
2328 ZCONST
char *pre
, ZCONST
char *post
));
2329 #if (!defined(STR_TO_ISO) || defined(NEED_STR2ISO))
2330 char *str2iso
OF((char *dst
, ZCONST
char *src
));
2332 #if (!defined(STR_TO_OEM) || defined(NEED_STR2OEM))
2333 char *str2oem
OF((char *dst
, ZCONST
char *src
));
2336 int zstrnicmp
OF((register ZCONST
char *s1
,
2337 register ZCONST
char *s2
,
2338 register unsigned n
));
2341 int zstat
OF((ZCONST
char *p
, struct stat
*s
));
2343 #ifdef ZMEM /* MUST be ifdef'd because of conflicts with the standard def. */
2344 zvoid
*memset
OF((register zvoid
*, register int, register unsigned int));
2345 int memcmp
OF((register ZCONST zvoid
*, register ZCONST zvoid
*,
2346 register unsigned int));
2347 zvoid
*memcpy
OF((register zvoid
*, register ZCONST zvoid
*,
2348 register unsigned int));
2350 #ifdef NEED_UZMBCLEN
2351 extent uzmbclen
OF((ZCONST
unsigned char *ptr
));
2353 #ifdef NEED_UZMBSCHR
2354 unsigned char *uzmbschr
OF((ZCONST
unsigned char *str
, unsigned int c
));
2356 #ifdef NEED_UZMBSRCHR
2357 unsigned char *uzmbsrchr
OF((ZCONST
unsigned char *str
, unsigned int c
));
2360 char *fLoadFarString
OF((__GPRO__
const char Far
*sz
));
2361 char *fLoadFarStringSmall
OF((__GPRO__
const char Far
*sz
));
2362 char *fLoadFarStringSmall2
OF((__GPRO__
const char Far
*sz
));
2364 char Far
* Far zfstrcpy
OF((char Far
*s1
, const char Far
*s2
));
2366 #if (!defined(SFX) && !defined(zfstrcmp))
2367 int Far zfstrcmp
OF((const char Far
*s1
, const char Far
*s2
));
2372 /*---------------------------------------------------------------------------
2373 Functions in extract.c:
2374 ---------------------------------------------------------------------------*/
2376 int extract_or_test_files
OF((__GPRO
));
2377 /* static int store_info OF((void)); */
2378 /* static int extract_or_test_member OF((__GPRO)); */
2379 /* static int TestExtraField OF((__GPRO__ uch *ef, unsigned ef_len)); */
2380 /* static int test_OS2 OF((__GPRO__ uch *eb, unsigned eb_size)); */
2381 /* static int test_NT OF((__GPRO__ uch *eb, unsigned eb_size)); */
2383 unsigned find_compr_idx
OF((unsigned compr_methodnum
));
2385 int memextract
OF((__GPRO__ uch
*tgt
, ulg tgtsize
,
2386 ZCONST uch
*src
, ulg srcsize
));
2387 int memflush
OF((__GPRO__ ZCONST uch
*rawbuf
, ulg size
));
2388 #if (defined(VMS) || defined(VMS_TEXT_CONV))
2389 uch
*extract_izvms_block
OF((__GPRO__ ZCONST uch
*ebdata
,
2390 unsigned size
, unsigned *retlen
,
2391 ZCONST uch
*init
, unsigned needlen
));
2393 char *fnfilter
OF((ZCONST
char *raw
, uch
*space
,
2396 /*---------------------------------------------------------------------------
2397 Decompression functions:
2398 ---------------------------------------------------------------------------*/
2400 #if (!defined(SFX) && !defined(FUNZIP))
2401 int explode
OF((__GPRO
)); /* explode.c */
2403 int huft_free
OF((struct huft
*t
)); /* inflate.c */
2404 int huft_build
OF((__GPRO__ ZCONST
unsigned *b
, unsigned n
,
2405 unsigned s
, ZCONST ush
*d
, ZCONST uch
*e
,
2406 struct huft
**t
, unsigned *m
));
2408 int UZinflate
OF((__GPRO__
int is_defl64
)); /* inflate.c */
2409 # define inflate_free(x) inflateEnd(&((Uz_Globs *)(&G))->dstrm)
2411 int inflate
OF((__GPRO__
int is_defl64
)); /* inflate.c */
2412 int inflate_free
OF((__GPRO
)); /* inflate.c */
2413 #endif /* ?USE_ZLIB */
2414 #if (!defined(SFX) && !defined(FUNZIP))
2415 #ifndef COPYRIGHT_CLEAN
2416 int unreduce
OF((__GPRO
)); /* unreduce.c */
2417 /* static void LoadFollowers OF((__GPRO__ f_array *follower, uch *Slen));
2419 #endif /* !COPYRIGHT_CLEAN */
2421 int unshrink
OF((__GPRO
)); /* unshrink.c */
2422 /* static void partial_clear OF((__GPRO)); * unshrink.c */
2423 #endif /* !LZW_CLEAN */
2424 #endif /* !SFX && !FUNZIP */
2426 int UZbunzip2
OF((__GPRO
)); /* extract.c */
2427 void bz_internal_error
OF((int bzerrcode
)); /* ubz2err.c */
2430 /*---------------------------------------------------------------------------
2431 Internal API functions (only included in DLL versions):
2432 ---------------------------------------------------------------------------*/
2435 void setFileNotFound
OF((__GPRO
)); /* api.c */
2436 int unzipToMemory
OF((__GPRO__
char *zip
, char *file
,
2437 UzpBuffer
*retstr
)); /* api.c */
2438 int redirect_outfile
OF((__GPRO
)); /* api.c */
2439 int writeToMemory
OF((__GPRO__ ZCONST uch
*rawbuf
,
2440 extent size
)); /* api.c */
2441 int close_redirect
OF((__GPRO
)); /* api.c */
2442 /* this obsolescent entry point kept for compatibility: */
2443 int UzpUnzip
OF((int argc
, char **argv
));/* use UzpMain */
2445 int varmessage
OF((__GPRO__ ZCONST uch
*buf
, ulg size
));
2446 int varputchar
OF((__GPRO__
int c
)); /* rexxapi.c */
2447 int finish_REXX_redirect
OF((__GPRO
)); /* rexxapi.c */
2450 void APIhelp
OF((__GPRO__
int argc
, char **argv
));
2451 #endif /* apihelp.c */
2454 /*---------------------------------------------------------------------------
2455 MSDOS-only functions:
2456 ---------------------------------------------------------------------------*/
2459 #if (!defined(FUNZIP) && !defined(SFX) && !defined(WINDLL))
2460 void check_for_windows
OF((ZCONST
char *app
)); /* msdos.c */
2462 #if (defined(__GO32__) || defined(__EMX__))
2463 unsigned _dos_getcountryinfo(void *); /* msdos.c */
2464 #if (!defined(__DJGPP__) || (__DJGPP__ < 2))
2465 unsigned _dos_setftime(int, unsigned, unsigned); /* msdos.c */
2466 unsigned _dos_setfileattr(const char *, unsigned); /* msdos.c */
2467 unsigned _dos_creat(const char *, unsigned, int *); /* msdos.c */
2468 void _dos_getdrive(unsigned *); /* msdos.c */
2469 unsigned _dos_close(int); /* msdos.c */
2470 #endif /* !__DJGPP__ || (__DJGPP__ < 2) */
2471 #endif /* __GO32__ || __EMX__ */
2474 /*---------------------------------------------------------------------------
2475 OS/2-only functions:
2476 ---------------------------------------------------------------------------*/
2478 #ifdef OS2 /* GetFileTime conflicts with something in Win32 header files */
2479 #if (defined(REENTRANT) && defined(USETHREADID))
2480 ulg GetThreadId
OF((void));
2482 int GetCountryInfo
OF((void)); /* os2.c */
2483 long GetFileTime
OF((ZCONST
char *name
)); /* os2.c */
2484 /* static void SetPathAttrTimes OF((__GPRO__ int flags, int dir)); os2.c */
2485 /* static int SetEAs OF((__GPRO__ const char *path,
2486 void *eablock)); os2.c */
2487 /* static int SetACL OF((__GPRO__ const char *path,
2488 void *eablock)); os2.c */
2489 /* static int IsFileNameValid OF((const char *name)); os2.c */
2490 /* static void map2fat OF((char *pathcomp, char **pEndFAT)); os2.c */
2491 /* static int SetLongNameEA OF((char *name, char *longname)); os2.c */
2492 /* static void InitNLS OF((void)); os2.c */
2493 int IsUpperNLS
OF((int nChr
)); /* os2.c */
2494 int ToLowerNLS
OF((int nChr
)); /* os2.c */
2495 void DebugMalloc
OF((void)); /* os2.c */
2498 /*---------------------------------------------------------------------------
2499 QDOS-only functions:
2500 ---------------------------------------------------------------------------*/
2503 int QMatch (uch
, uch
);
2504 void QFilename (__GPRO__
char *);
2505 char *Qstrfix (char *);
2506 int QReturn (int zip_error
);
2509 /*---------------------------------------------------------------------------
2510 TOPS20-only functions:
2511 ---------------------------------------------------------------------------*/
2514 int upper
OF((char *s
)); /* tops20.c */
2515 int enquote
OF((char *s
)); /* tops20.c */
2516 int dequote
OF((char *s
)); /* tops20.c */
2517 int fnlegal
OF(()); /* error if prototyped? */ /* tops20.c */
2520 /*---------------------------------------------------------------------------
2521 VM/CMS- and MVS-only functions:
2522 ---------------------------------------------------------------------------*/
2525 extent getVMMVSexfield
OF((char *type
, uch
*ef_block
, unsigned datalen
));
2526 FILE *vmmvs_open_infile
OF((__GPRO
)); /* vmmvs.c */
2527 void close_infile
OF((__GPRO
)); /* vmmvs.c */
2530 /*---------------------------------------------------------------------------
2532 ---------------------------------------------------------------------------*/
2535 int check_format
OF((__GPRO
)); /* vms.c */
2536 /* int open_outfile OF((__GPRO)); * (see fileio.c) vms.c */
2537 /* int flush OF((__GPRO__ uch *rawbuf, unsigned size,
2538 int final_flag)); * (see fileio.c) vms.c */
2539 char *vms_msg_text
OF((void)); /* vms.c */
2541 void return_VMS
OF((__GPRO__
int zip_error
)); /* vms.c */
2543 void return_VMS
OF((int zip_error
)); /* vms.c */
2546 ulg vms_unzip_cmdline
OF((int *, char ***)); /* cmdline.c */
2547 int VMSCLI_usage
OF((__GPRO__
int error
)); /* cmdline.c */
2551 /*---------------------------------------------------------------------------
2552 WIN32-only functions:
2553 ---------------------------------------------------------------------------*/
2556 int IsWinNT
OF((void)); /* win32.c */
2558 void process_defer_NT
OF((__GPRO
)); /* win32.c */
2559 int test_NTSD
OF((__GPRO__ uch
*eb
, unsigned eb_size
,
2560 uch
*eb_ucptr
, ulg eb_ucsize
)); /* win32.c */
2561 # define TEST_NTSD test_NTSD
2563 #ifdef W32_STAT_BANDAID
2564 int zstat_win32
OF((__W32STAT_GLOBALS__
2565 const char *path
, z_stat
*buf
)); /* win32.c */
2569 /*---------------------------------------------------------------------------
2570 Miscellaneous/shared functions:
2571 ---------------------------------------------------------------------------*/
2573 Uz_Globs
*globalsCtor
OF((void)); /* globals.c */
2575 int envargs
OF((int *Pargc
, char ***Pargv
,
2576 ZCONST
char *envstr
, ZCONST
char *envstr2
));
2578 void mksargs
OF((int *argcp
, char ***argvp
)); /* envargs.c */
2580 int match
OF((ZCONST
char *s
, ZCONST
char *p
,
2581 int ic __WDLPRO
)); /* match.c */
2582 int iswild
OF((ZCONST
char *p
)); /* match.c */
2584 /* declarations of public CRC-32 functions have been moved into crc32.h
2585 (free_crc_table(), get_crc_table(), crc32()) crc32.c */
2587 int dateformat
OF((void)); /* local */
2588 char dateseparator
OF((void)); /* local */
2590 void version
OF((__GPRO
)); /* local */
2592 int mapattr
OF((__GPRO
)); /* local */
2593 int mapname
OF((__GPRO__
int renamed
)); /* local */
2594 int checkdir
OF((__GPRO__
char *pathcomp
, int flag
)); /* local */
2595 char *do_wild
OF((__GPRO__ ZCONST
char *wildzipfn
)); /* local */
2596 char *GetLoadPath
OF((__GPRO
)); /* local */
2597 #if (defined(MORE) && (defined(ATH_BEO_UNX) || defined(QDOS) || defined(VMS)))
2598 int screensize
OF((int *tt_rows
, int *tt_cols
)); /* local */
2600 int screenlinewrap
OF((void)); /* local */
2602 #endif /* MORE && (ATH_BEO_UNX || QDOS || VMS) */
2604 int SetFileSize
OF((FILE *file
, zusz_t filesize
)); /* local */
2606 #ifndef MTS /* macro in MTS */
2607 void close_outfile
OF((__GPRO
)); /* local */
2609 #ifdef SET_SYMLINK_ATTRIBS
2610 int set_symlnk_attribs
OF((__GPRO__ slinkentry
*slnk_entry
)); /* local */
2612 #ifdef SET_DIR_ATTRIB
2613 int defer_dir_attribs
OF((__GPRO__ direntry
**pd
)); /* local */
2614 int set_direc_attribs
OF((__GPRO__ direntry
*d
)); /* local */
2618 int stamp_file
OF((__GPRO__
2619 ZCONST
char *fname
, time_t modtime
)); /* local */
2621 int stamp_file
OF((ZCONST
char *fname
, time_t modtime
)); /* local */
2624 #ifdef NEED_ISO_OEM_INIT
2625 void prepare_ISO_OEM_translat
OF((__GPRO
)); /* local */
2627 #if (defined(MALLOC_WORK) && defined(MY_ZCALLOC))
2628 zvoid far
*zcalloc
OF((unsigned int, unsigned int));
2629 zvoid zcfree
OF((zvoid far
*));
2630 #endif /* MALLOC_WORK && MY_ZCALLOC */
2631 #ifdef SYSTEM_SPECIFIC_CTOR
2632 void SYSTEM_SPECIFIC_CTOR
OF((__GPRO
)); /* local */
2634 #ifdef SYSTEM_SPECIFIC_DTOR
2635 void SYSTEM_SPECIFIC_DTOR
OF((__GPRO
)); /* local */
2647 # define MAX(a,b) ((a) > (b) ? (a) : (b))
2650 # define MIN(a,b) ((a) < (b) ? (a) : (b))
2654 # if (defined(THEOS) && defined(NO_BOGUS_SPC))
2655 # define NO_DEBUG_IN_MACROS
2656 # define Trace(x) _fprintf x
2658 # define Trace(x) fprintf x
2665 # define TTrace(x) fprintf x
2670 #ifdef NO_DEBUG_IN_MACROS
2673 # define MTrace(x) Trace(x)
2676 #if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
2677 # define ToLower(x) ((char)(isupper((int)x)? tolower((int)x) : x))
2679 # define ToLower tolower /* assumed "smart"; used in match() */
2682 #ifdef USE_STRM_INPUT
2683 /* ``Replace'' the unbuffered UNIX style I/O function with similar
2684 * standard C functions from <stdio.h>.
2686 # define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
2690 # define zlseek(fd,o,w) zfseeko((FILE *)(fd),(o),(w))
2691 # define close(fd) fclose((FILE *)(fd))
2692 #endif /* USE_STRM_INPUT */
2694 /* The return value of the Info() "macro function" is never checked in
2695 * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
2696 * Info() definition for "FUNZIP" would have to be corrected:
2697 * #define Info(buf,flag,sprf_arg) \
2698 * (fputs((char *)(sprintf sprf_arg, (buf)), \
2699 * (flag)&1? stderr : stdout) < 0)
2701 static inline void noop(void) {}
2702 #define Info(...) noop()
2703 #ifndef Info /* may already have been defined for redirection */
2705 # define Info(buf,flag,sprf_arg) \
2706 fputs((char *)(sprintf sprf_arg, (buf)), (flag)&1? stderr : stdout)
2708 # ifdef INT_SPRINTF /* optimized version for "int sprintf()" flavour */
2709 # define Info(buf,flag,sprf_arg) \
2710 (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
2711 # else /* generic version, does not use sprintf() return value */
2712 # define Info(buf,flag,sprf_arg) \
2713 (*G.message)((zvoid *)&G, (uch *)(buf), \
2714 (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
2719 /* This wrapper macro around fzofft() is just defined to "hide" the
2720 * argument needed to reference the global storage buffers.
2722 #define FmZofft(val, pre, post) fzofft(__G__ val, pre, post)
2724 /* The following macro wrappers around the fnfilter function are used many
2725 * times to prepare archive entry names or name components for displaying
2726 * listings and (warning/error) messages. They use sections in the upper half
2727 * of 'slide' as buffer, since their output is normally fed through the
2728 * Info() macro with 'slide' (the start of this area) as message buffer.
2730 #define FnFilter1(fname) \
2731 fnfilter((fname), slide + (extent)(WSIZE>>1), (extent)(WSIZE>>2))
2732 #define FnFilter2(fname) \
2733 fnfilter((fname), slide + (extent)((WSIZE>>1) + (WSIZE>>2)),\
2736 #ifndef FUNZIP /* used only in inflate.c */
2737 # define MESSAGE(str,len,flag) (*G.message)((zvoid *)&G,(str),(len),(flag))
2740 #if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
2741 # define CRCVAL_INITIAL crc32(0L, NULL, 0)
2743 # define CRCVAL_INITIAL 0L
2747 /* This macro defines the Zip "made by" hosts that are considered
2748 to support storing symbolic link entries. */
2749 # define SYMLINK_HOST(hn) ((hn) == UNIX_ || (hn) == ATARI_ || \
2750 (hn) == ATHEOS_ || (hn) == BEOS_ || (hn) == VMS_)
2753 #ifndef TEST_NTSD /* "NTSD valid?" checking function */
2754 # define TEST_NTSD NULL /* ... is not available */
2757 #define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
2758 {error_in_archive=error; if(error>1) return error;}
2761 * Skip a variable-length field, and report any errors. Used in zipinfo.c
2762 * and unzip.c in several functions.
2764 * macro SKIP_(length)
2767 * if (length && ((error = do_string(length, SKIP)) != 0)) {
2768 * error_in_archive = error; /-* might be warning *-/
2769 * if (error > 1) /-* fatal *-/
2778 # define FLUSH(w) flush(__G__ (ulg)(w))
2779 # define NEXTBYTE getc(G.in) /* redefined in crypt.h if full version */
2781 # define FLUSH(w) ((G.mem_mode) ? memflush(__G__ redirSlide,(ulg)(w)) \
2782 : flush(__G__ redirSlide,(ulg)(w),0))
2783 # define NEXTBYTE (G.incnt-- > 0 ? (int)(*G.inptr++) : readbyte(__G))
2787 #define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
2788 while (G.bits_left<=8*(int)(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
2789 G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
2790 zdest=(shrint)((unsigned)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
2791 G.bits_left-=nbits;}
2794 * macro READBITS(nbits,zdest) * only used by unreduce and unshrink *
2796 * if (nbits > G.bits_left) { * fill G.bitbuf, 8*sizeof(ulg) bits *
2800 * while (G.bits_left <= 8*(int)(sizeof(G.bitbuf)-1) &&
2801 * (temp = NEXTBYTE) != EOF) {
2802 * G.bitbuf |= (ulg)temp << G.bits_left;
2807 * zdest = (shrint)((unsigned)G.bitbuf & mask_bits[nbits]);
2808 * G.bitbuf >>= nbits;
2809 * G.bits_left -= nbits;
2815 /* GRR: should use StringLower for STRLOWER macro if possible */
2818 * Copy the zero-terminated string in str1 into str2, converting any
2819 * uppercase letters to lowercase as we go. str2 gets zero-terminated
2820 * as well, of course. str1 and str2 may be the same character array.
2823 # define STRLOWER(str1, str2) \
2825 char *p, *q, c; unsigned i; \
2826 p = (char *)(str1); \
2827 q = (char *)(str2); \
2828 while ((c = *p) != '\0') { \
2829 if ((i = CLEN(p)) > 1) { \
2830 while (i--) *q++ = *p++; \
2832 *q++ = (char)(isupper((int)(c))? tolower((int)(c)) : c); \
2839 # define STRLOWER(str1, str2) \
2842 p = (char *)(str1) - 1; \
2843 q = (char *)(str2); \
2845 *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
2850 * NOTES: This macro makes no assumptions about the characteristics of
2851 * the tolower() function or macro (beyond its existence), nor does it
2852 * make assumptions about the structure of the character set (i.e., it
2853 * should work on EBCDIC machines, too). The fact that either or both
2854 * of isupper() and tolower() may be macros has been taken into account;
2855 * watch out for "side effects" (in the C sense) when modifying this
2860 # define foreign(c) (c)
2864 # define native(c) (c)
2865 # define A_TO_N(str1)
2868 # define NATIVE "native chars"
2870 # define A_TO_N(str1) {register uch *p;\
2871 for (p=(uch *)(str1); *p; p++) *p=native(*p);}
2874 * Translate the zero-terminated string in str1 from ASCII to the native
2875 * character set. The translation is performed in-place and uses the
2876 * "native" macro to translate each character.
2878 * NOTE: Using the "native" macro means that is it the only part of unzip
2879 * which knows which translation table (if any) is actually in use to
2880 * produce the native character set. This makes adding new character set
2881 * translation tables easy, insofar as all that is needed is an appropriate
2882 * "native" macro definition and the translation table itself. Currently,
2883 * the only non-ASCII native character set implemented is EBCDIC, but this
2884 * may not always be so.
2888 /* default setup for internal codepage: assume ISO 8859-1 compatibility!! */
2889 #if (!defined(NATIVE) && !defined(CRTL_CP_IS_ISO) && !defined(CRTL_CP_IS_OEM))
2890 # define CRTL_CP_IS_ISO
2894 /* Translate "extended ASCII" chars (OEM coding for DOS and OS/2; else
2895 * ISO-8859-1 [ISO Latin 1, Win Ansi,...]) into the internal "native"
2896 * code page. As with A_TO_N(), conversion is done in place.
2899 # ifdef CRTL_CP_IS_OEM
2900 # ifndef IZ_ISO2OEM_ARRAY
2901 # define IZ_ISO2OEM_ARRAY
2903 # define _ISO_INTERN(str1) if (iso2oem) {register uch *p;\
2904 for (p=(uch *)(str1); *p; p++)\
2905 *p = native((*p & 0x80) ? iso2oem[*p & 0x7f] : *p);}
2907 # define _ISO_INTERN(str1) A_TO_N(str1)
2912 # ifdef CRTL_CP_IS_OEM
2913 # define _OEM_INTERN(str1) A_TO_N(str1)
2915 # ifndef IZ_OEM2ISO_ARRAY
2916 # define IZ_OEM2ISO_ARRAY
2918 # define _OEM_INTERN(str1) if (oem2iso) {register uch *p;\
2919 for (p=(uch *)(str1); *p; p++)\
2920 *p = native((*p & 0x80) ? oem2iso[*p & 0x7f] : *p);}
2925 # ifdef CRTL_CP_IS_ISO
2926 # define STR_TO_ISO strcpy
2928 # define STR_TO_ISO str2iso
2929 # define NEED_STR2ISO
2934 # ifdef CRTL_CP_IS_OEM
2935 # define STR_TO_OEM strcpy
2937 # define STR_TO_OEM str2oem
2938 # define NEED_STR2OEM
2942 #if (!defined(INTERN_TO_ISO) && !defined(ASCII2ISO))
2943 # ifdef CRTL_CP_IS_OEM
2944 /* know: "ASCII" is "OEM" */
2945 # define ASCII2ISO(c) \
2946 ((((c) & 0x80) && oem2iso) ? oem2iso[(c) & 0x7f] : (c))
2947 # if (defined(NEED_STR2ISO) && !defined(CRYP_USES_OEM2ISO))
2948 # define CRYP_USES_OEM2ISO
2951 /* assume: "ASCII" is "ISO-ANSI" */
2952 # define ASCII2ISO(c) (c)
2956 #if (!defined(INTERN_TO_OEM) && !defined(ASCII2OEM))
2957 # ifdef CRTL_CP_IS_OEM
2958 /* know: "ASCII" is "OEM" */
2959 # define ASCII2OEM(c) (c)
2961 /* assume: "ASCII" is "ISO-ANSI" */
2962 # define ASCII2OEM(c) \
2963 ((((c) & 0x80) && iso2oem) ? iso2oem[(c) & 0x7f] : (c))
2964 # if (defined(NEED_STR2OEM) && !defined(CRYP_USES_ISO2OEM))
2965 # define CRYP_USES_ISO2OEM
2970 /* codepage conversion setup for testp() in crypt.c */
2971 #ifdef CRTL_CP_IS_ISO
2973 # define STR_TO_CP2 STR_TO_OEM
2976 # ifdef CRTL_CP_IS_OEM
2978 # define STR_TO_CP2 STR_TO_ISO
2980 # else /* native internal CP is neither ISO nor OEM */
2982 # define STR_TO_CP1 STR_TO_ISO
2985 # define STR_TO_CP2 STR_TO_OEM
2991 /* Convert filename (and file comment string) into "internal" charset.
2992 * This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
2993 * codepage when made on
2994 * -> DOS (this includes 16-bit Windows 3.1) (FS_FAT_)
2995 * -> OS/2 (FS_HPFS_)
2996 * -> Win95/WinNT with Nico Mak's WinZip (FS_NTFS_ && hostver == "5.0")
2998 * PKZIP for Windows 2.5, 2.6, and 4.0 flag their entries as "FS_FAT_", but
2999 * the filename stored in the local header is coded in Windows ANSI (CP 1252
3000 * resp. ISO 8859-1 on US and western Europe locale settings).
3001 * Likewise, PKZIP for UNIX 2.51 flags its entries as "FS_FAT_", but the
3002 * filenames stored in BOTH the local and the central header are coded
3003 * in the local system's codepage (usually ANSI codings like ISO 8859-1).
3005 * All other ports are assumed to code zip entry filenames in ISO 8859-1.
3007 #ifndef Ext_ASCII_TO_Native
3008 # define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
3009 if (((hostnum) == FS_FAT_ && \
3010 !(((islochdr) || (isuxatt)) && \
3011 ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
3012 (hostnum) == FS_HPFS_ || \
3013 ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
3014 _OEM_INTERN((string)); \
3016 _ISO_INTERN((string)); \
3022 /**********************/
3023 /* Global constants */
3024 /**********************/
3026 extern ZCONST
unsigned near mask_bits
[17];
3027 extern ZCONST
char *fnames
[2];
3030 extern ZCONST uch ebcdic
[];
3032 #ifdef IZ_ISO2OEM_ARRAY
3033 extern ZCONST uch Far
*iso2oem
;
3034 extern ZCONST uch Far iso2oem_850
[];
3036 #ifdef IZ_OEM2ISO_ARRAY
3037 extern ZCONST uch Far
*oem2iso
;
3038 extern ZCONST uch Far oem2iso_850
[];
3041 extern ZCONST
char Far VersionDate
[];
3042 extern ZCONST
char Far CentSigMsg
[];
3044 extern ZCONST
char Far EndSigMsg
[];
3046 extern ZCONST
char Far SeekMsg
[];
3047 extern ZCONST
char Far FilenameNotMatched
[];
3048 extern ZCONST
char Far ExclFilenameNotMatched
[];
3049 extern ZCONST
char Far ReportMsg
[];
3052 extern ZCONST
char Far Zipnfo
[];
3053 extern ZCONST
char Far CompiledWith
[];
3058 /***********************************/
3059 /* Global (shared?) RTL variables */
3060 /***********************************/
3062 #ifdef DECLARE_ERRNO
3066 /*---------------------------------------------------------------------
3069 ---------------------------------------------------------------------*/
3070 #if (defined(UNICODE_SUPPORT) && defined(UNICODE_WCHAR))
3072 /* Default character when a zwchar too big for wchar_t */
3073 # define zwchar_to_wchar_t_default_char '_'
3075 /* Default character string when wchar_t does not convert to mb */
3076 # define wide_to_mb_default_string "_"
3078 /* wide character type */
3079 typedef unsigned long zwchar
;
3081 /* UTF-8 related conversion functions, currently found in process.c */
3083 # if 0 /* currently unused */
3084 /* check if string is all ASCII */
3085 int is_ascii_string
OF((ZCONST
char *mbstring
));
3086 # endif /* unused */
3088 /* convert UTF-8 string to multi-byte string */
3089 char *utf8_to_local_string
OF((ZCONST
char *utf8_string
, int escape_all
));
3091 /* convert UTF-8 string to wide string */
3092 zwchar
*utf8_to_wide_string
OF((ZCONST
char *utf8_string
));
3094 /* convert wide string to multi-byte string */
3095 char *wide_to_local_string
OF((ZCONST zwchar
*wide_string
, int escape_all
));
3097 # if 0 /* currently unused */
3098 /* convert local string to multi-byte display string */
3099 char *local_to_display_string
OF((ZCONST
char *local_string
));
3100 # endif /* unused */
3102 /* convert wide character to escape string */
3103 char *wide_to_escape_string
OF((unsigned long));
3105 # define utf8_to_escaped_string(utf8_string) \
3106 utf8_to_local_string(utf8_string, TRUE)
3108 # if 0 /* currently unused */
3109 /* convert escape string to wide character */
3110 unsigned long escape_string_to_wide
OF((ZCONST
char *escape_string
));
3112 /* convert local to UTF-8 */
3113 char *local_to_utf8_string
OF ((ZCONST
char *local_string
));
3115 /* convert local to wide string */
3116 zwchar
*local_to_wide_string
OF ((ZCONST
char *local_string
));
3118 /* convert wide string to UTF-8 */
3119 char *wide_to_utf8_string
OF((ZCONST zwchar
*wide_string
));
3120 # endif /* unused */
3122 #endif /* UNICODE_SUPPORT && UNICODE_WCHAR */
3125 #endif /* !__unzpriv_h */