1 /*---------------------------------------------------------------------------
5 This header file contains private (internal) macros, typedefs, prototypes
6 and global-variable declarations used by all of the UnZip source files.
7 In a prior life it was part of the main unzip.h header, but now it is only
8 included by that header if UNZIP_INTERNAL is defined.
10 ---------------------------------------------------------------------------*/
14 #ifndef __unzpriv_h /* prevent multiple inclusions */
17 /* First thing: Signal all following code that we compile UnZip utilities! */
22 /* GRR 960204: MORE defined here in preparation for removal altogether */
27 /* fUnZip should never need to be reentrant */
37 #if (defined(DLL) && !defined(REENTRANT))
41 #if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
42 # define DYNAMIC_CRC_TABLE
45 #if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
46 # ifndef DYNALLOC_CRCTAB
47 # define DYNALLOC_CRCTAB
51 /*---------------------------------------------------------------------------
52 OS-dependent configuration for UnZip internals
53 ---------------------------------------------------------------------------*/
55 /* bad or (occasionally?) missing stddef.h: */
56 #if (defined(M_XENIX) || defined(DNIX))
60 #if (defined(M_XENIX) && !defined(M_UNIX)) /* SCO Xenix only, not SCO Unix */
62 # define NO_LIMITS_H /* no limits.h, but MODERN defined */
63 # define NO_UID_GID /* no uid_t/gid_t */
67 #ifdef realix /* Modcomp Real/IX, real-time SysV.3 variant */
69 # define NO_UID_GID /* no uid_t/gid_t */
72 #if (defined(_AIX) && !defined(_ALL_SOURCE))
76 #if defined(apollo) /* defines __STDC__ */
82 # define SHORT_NAMES /* 14-char limitation on path components */
83 /* # define FILENAME_MAX 14 */
84 # define FILENAME_MAX NAME_MAX /* GRR: experiment */
87 #if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
91 #endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
92 #if (defined(M_SYSV) || defined(M_SYS5))
96 #endif /* M_SYSV || M_SYS5 */
97 /* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
98 #if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
102 #endif /* __SVR4 || __svr4__ || sgi || __hpux */
103 #if (defined(LINUX) || defined(__QNX__))
107 #endif /* LINUX || __QNX__ */
109 #if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
110 # if (!defined(BSD) && !defined(SYSV))
113 #endif /* ultrix || __ultrix || bsd4_2 */
114 #if (defined(sun) || defined(pyr) || defined(CONVEX))
115 # if (!defined(BSD) && !defined(SYSV))
118 #endif /* sun || pyr || CONVEX */
120 #ifdef pyr /* Pyramid: has BSD and AT&T "universes" */
123 # define USE_STRINGS_H /* instead of more common string.h */
124 # define ZMEM /* ZMEM now uses bcopy/bzero: not in AT&T universe */
125 # endif /* (AT&T memcpy claimed to be very slow, though) */
126 # define DECLARE_ERRNO
129 /* stat() bug for Borland, VAX C (also GNU?), and Atari ST MiNT on TOS
130 * filesystems: returns 0 for wildcards! (returns 0xffffffff on Minix
131 * filesystem or `U:' drive under Atari MiNT.) Watcom C was previously
132 * included on this list; it would be good to know what version the problem
133 * was fixed at, if it did exist. Watcom 10.6 has a separate stat() problem:
134 * it fails on "." when the current directory is a root. This is covered by
135 * giving it a separate definition of SSTAT in OS-specific header files. */
136 #if (defined(__TURBOC__) || defined(VMS) || defined(__MINT__))
137 # define WILD_STAT_BUG
141 # define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
146 #ifdef REGULUS /* returns the inode number on success(!)...argh argh argh */
147 # define stat(p,s) zstat((p),(s))
150 #define STRNICMP zstrnicmp
152 /*---------------------------------------------------------------------------
153 OS-dependent includes
154 ---------------------------------------------------------------------------*/
157 # define LONGINT off_t /* Amdahl UTS nonsense ("extended file types") */
159 # define LONGINT long
167 # include <stdlib.h> /* standard library prototypes, malloc(), etc. */
169 typedef size_t extent
;
171 # ifndef AOS_VS /* mostly modern? */
173 # ifdef VAXC /* not fully modern, but does have stdlib.h and void */
178 # endif /* !AOS_VS */
179 typedef unsigned int extent
;
183 #ifndef MINIX /* Minix needs it after all the other includes (?) */
186 #include <ctype.h> /* skip for VMS, to use tolower() function? */
187 #include <errno.h> /* used in mapname() */
189 # include <strings.h> /* strcpy, strcmp, memcpy, index/rindex, etc. */
191 # include <string.h> /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
193 #if (defined(MODERN) && !defined(NO_LIMITS_H))
194 # include <limits.h> /* GRR: EXPERIMENTAL! (can be deleted) */
197 /* this include must be down here for SysV.4, for some reason... */
198 #include <signal.h> /* used in unzip.c, fileio.c */
201 /*---------------------------------------------------------------------------
203 ---------------------------------------------------------------------------*/
206 # define MAIN UZ_EXP UzpMain /* was UzpUnzip */
209 # define REDIRECTC(c) varputchar(__G__ c)
210 # define REDIRECTPRINT(buf,size) varmessage(__G__ buf, size)
211 # define FINISH_REDIRECT() finish_REXX_redirect(__G)
213 # define REDIRECTC(c)
214 # define REDIRECTPRINT(buf,size) 0
215 # define FINISH_REDIRECT() close_redirect(__G)
219 /*---------------------------------------------------------------------------
220 Acorn RISCOS section:
221 ---------------------------------------------------------------------------*/
224 # include "acorn/riscos.h"
227 /*---------------------------------------------------------------------------
229 ---------------------------------------------------------------------------*/
232 # include "amiga/amiga.h"
235 /*---------------------------------------------------------------------------
236 AOS/VS section (somewhat similar to Unix, apparently):
237 ---------------------------------------------------------------------------*/
241 # include "aosvs/aosvs.h"
245 /*---------------------------------------------------------------------------
247 ---------------------------------------------------------------------------*/
255 # define EXE_EXTENSION ".tos"
257 # define DATE_FORMAT DF_DMY
261 # define timezone _timezone
263 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
265 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
270 /*---------------------------------------------------------------------------
272 ---------------------------------------------------------------------------*/
275 # include <sys/types.h> /* [cjh]: This is pretty much a generic */
276 # include <sys/stat.h> /* POSIX 1003.1 system; see beos/ for */
277 # include <fcntl.h> /* extra code to deal with our extra file */
278 # include <sys/param.h> /* attributes. */
284 # define DATE_FORMAT DF_MDY /* GRR: customize with locale.h somehow? */
287 # define PutNativeEOL *q++ = native(LF);
288 # define SCREENLINES screenlines()
289 # define USE_EF_UT_TIME
290 # define SET_DIR_ATTRIB
291 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
294 # define RESTORE_UIDGID
295 # define NO_GMTIME /* maybe DR10 will have timezones... */
298 # define MAIN main_stub /* now that we're using a wrapper... */
301 /*---------------------------------------------------------------------------
302 Human68k/X68000 section:
303 ---------------------------------------------------------------------------*/
305 #ifdef __human68k__ /* DO NOT DEFINE DOS_OS2 HERE! If Human68k is so much */
306 # include <time.h> /* like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
311 # include <sys/stat.h>
313 # define DATE_FORMAT DF_YMD /* Japanese standard */
315 /* GRR: these EOL macros are guesses */
317 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
318 # define EXE_EXTENSION ".exe" /* just a guess... */
321 /*---------------------------------------------------------------------------
323 ---------------------------------------------------------------------------*/
329 /*---------------------------------------------------------------------------
330 MS-DOS, OS/2, FLEXOS section:
331 ---------------------------------------------------------------------------*/
343 #if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
345 # define MSC /* This should work for older MSC, too! */
349 #if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
350 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
351 # include <sys/stat.h>
352 # include <io.h> /* lseek(), open(), setftime(), dup(), creat() */
353 # include <time.h> /* localtime() */
354 # include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
356 # ifdef OS2 /* defined for all OS/2 compilers */
357 # include "os2/os2cfg.h"
360 # include "flexos/flxcfg.h"
362 # include "msdos/doscfg.h"
366 # if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
368 * ARGH. MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
369 * 1970 Jan 1 00:00. So we have to diddle time_t's appropriately: add or
370 * subtract 70 years' worth of seconds; i.e., number of days times 86400;
371 * i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
372 * (25550 + 17 + 1) * 86400 == 2209075200 seconds. We know time_t is an
373 * unsigned long (ulg) on the only system with this bug.
375 # define TIMET_TO_NATIVE(x) (x) += (ulg)2209075200L;
376 # define NATIVE_TO_TIMET(x) (x) -= (ulg)2209075200L;
378 # if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
379 # define timezone _timezone
381 # if (defined(__GO32__) || defined(FLEXOS))
384 # define DIR_END '\\' /* OS uses '\\' as directory separator */
385 # define DIR_END2 '/' /* also check for '/' (RTL may convert) */
391 # define DATE_FORMAT dateformat()
394 # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
395 # define USE_EF_UT_TIME
396 #endif /* MSDOS || OS2 || FLEXOS */
398 /*---------------------------------------------------------------------------
399 MTS section (piggybacks UNIX, I think):
400 ---------------------------------------------------------------------------*/
403 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
404 # include <sys/stat.h>
405 # include <sys/file.h> /* MTS uses this instead of fcntl.h */
408 # include <unix.h> /* some important non-ANSI routines */
409 # define mkdir(s,n) (-1) /* no "make directory" capability */
410 # define EBCDIC /* set EBCDIC conversion on */
411 # define NO_STRNICMP /* unzip's is as good the one in MTS */
413 # define close_outfile() fclose(G.outfile) /* can't set time on files */
414 # define umask(n) /* don't have umask() on MTS */
415 # define FOPWT "w" /* open file for writing in TEXT mode */
417 # define DATE_FORMAT DF_MDY
420 # define PutNativeEOL *q++ = native(LF);
423 /*---------------------------------------------------------------------------
425 ---------------------------------------------------------------------------*/
431 # include <sys/stat.h>
433 # include "qdos/izqdos.h"
435 # define DATE_FORMAT DF_MDY
438 # define PutNativeEOL *q++ = native(LF);
440 # define RETURN QReturn
443 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
448 /*---------------------------------------------------------------------------
450 ---------------------------------------------------------------------------*/
455 /* use a single LF delimiter so that writes to 101 text files work */
456 # define PutNativeEOL *q++ = native(LF);
459 # define DATE_FORMAT DF_DMY
461 # define USE_EF_UT_TIME
462 # define RESTORE_UIDGID
465 /*---------------------------------------------------------------------------
467 ---------------------------------------------------------------------------*/
470 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
471 # include <sys/stat.h>
472 # include <sys/param.h>
473 # include <sys/time.h>
474 # include <sys/timeb.h>
475 # include <sys/file.h>
477 # include <monsym.h> /* get amazing monsym() macro */
478 extern int open(), close(), read();
479 extern int stat(), unlink(), jsys(), fcntl();
480 extern long lseek(), dup(), creat();
481 # define strchr index /* GRR: necessary? */
482 # define strrchr rindex
483 # define REALLY_SHORT_SYMS
487 # define DIR_EXT ".directory"
489 # define DATE_FORMAT DF_MDY
491 # define EXE_EXTENSION ".exe" /* just a guess... */
494 /*---------------------------------------------------------------------------
496 ---------------------------------------------------------------------------*/
499 # include <sys/types.h> /* off_t, time_t, dev_t, ... */
500 # include <sys/stat.h>
503 # include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
504 # else /* COHERENT */
506 # include <fcntl.h> /* Coherent 4.0.x, Mark Williams C */
508 # include <sys/fcntl.h> /* Coherent 3.10, Mark Williams C */
511 # ifndef __COHERENT__ /* Coherent 4.2 has tzset() */
514 # endif /* ?COHERENT */
518 # undef NGROUPS_MAX /* SCO bug: defined again in <sys/param.h> */
521 # define TEMP_BSD /* may be defined again in <sys/param.h> */
524 # include <sys/param.h> /* conflict with <sys/types.h>, some systems? */
531 # endif /* !NO_PARAM_H */
538 # endif /* __osf__ */
541 # include <sys/time.h>
542 # include <sys/timeb.h>
548 struct tm
*gmtime(), *localtime();
551 # if (defined(BSD4_4) || (defined(SYSV) && defined(MODERN)))
552 # include <unistd.h> /* this includes utime.h on SGIs */
553 # if (defined(BSD4_4) || defined(linux))
559 # if (defined(V7) || defined(pyr_bsd))
560 # define strchr index
561 # define strrchr rindex
573 # define DATE_FORMAT DF_MDY /* GRR: customize with locale.h somehow? */
577 # define PutNativeEOL *q++ = '\n';
579 # define PutNativeEOL *q++ = native(LF);
581 # define SCREENLINES screenlines()
582 # define USE_EF_UT_TIME
583 # define SET_DIR_ATTRIB
584 # if (!defined(TIMESTAMP) && !defined(NOTIMESTAMP)) /* GRR 970513 */
587 # define RESTORE_UIDGID
590 /*---------------------------------------------------------------------------
591 VM/CMS and MVS section:
592 ---------------------------------------------------------------------------*/
596 # define CLOSE_INFILE() close_infile(__G)
599 /*---------------------------------------------------------------------------
601 ---------------------------------------------------------------------------*/
604 # include <types.h> /* GRR: experimenting... */
606 # include <time.h> /* the usual non-BSD time functions */
607 # include <file.h> /* same things as fcntl.h has */
610 # define _MAX_PATH (NAM$C_MAXRSS+1) /* to define FILNAMSIZ below */
611 # ifdef RETURN_CODES /* VMS interprets standard PK return codes incorrectly */
612 # define RETURN(ret) return_VMS(__G__ (ret)) /* verbose version */
613 # define EXIT(ret) return_VMS(__G__ (ret))
615 # define RETURN return_VMS /* quiet version */
616 # define EXIT return_VMS
619 # define USAGE(ret) VMSCLI_usage(__G__ (ret))
623 # define DIR_EXT ".dir"
625 # define DATE_FORMAT DF_MDY
628 # define PutNativeEOL *q++ = native(LF);
629 # define SCREENLINES screenlines()
630 # if (defined(__VMS_VERSION) && !defined(VMS_VERSION))
631 # define VMS_VERSION __VMS_VERSION
633 # if (defined(__VMS_VER) && !defined(__CRTL_VER))
634 # define __CRTL_VER __VMS_VER
636 # if ((!defined(__CRTL_VER)) || (__CRTL_VER < 70000000))
637 # define NO_GMTIME /* gmtime() of earlier VMS C RTLs is broken */
639 # if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
640 # define USE_EF_UT_TIME
643 # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
646 # define RESTORE_UIDGID
649 /*---------------------------------------------------------------------------
650 Win32 (Windows 95/NT) section:
651 ---------------------------------------------------------------------------*/
653 #if (defined(WIN32) && !defined(POCKET_UNZIP))
665 #define UNZIP_VERSION 20 /* compatible with PKUNZIP 2.0 */
666 #define VMS_UNZIP_VERSION 42 /* if OS-needed-to-extract is VMS: can do */
668 #if (defined(MSDOS) || defined(OS2))
672 #if (defined(OS2) || defined(WIN32))
676 #if (defined(DOS_OS2) || defined(WIN32))
678 # define DOS_W32_OS2 /* historical: don't use */
681 #if (defined(DOS_OS2_W32) || defined(__human68k__))
682 # define DOS_H68_OS2_W32
685 #if (defined(DOS_OS2) || defined(FLEXOS))
689 #if (defined(DOS_OS2_W32) || defined(FLEXOS))
690 # define DOS_FLX_OS2_W32
693 #if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
694 # define DOS_FLX_H68_OS2_W32
697 #if (defined(TOPS20) || defined(VMS))
701 #if (defined(MSDOS) || defined(T20_VMS))
705 /* clean up with a few defaults */
707 # define DIR_END '/' /* last char before program name or filename */
710 # define DATE_FORMAT DF_MDY /* defaults to US convention */
713 # define CLOSE_INFILE() close(G.zipfd)
716 # define RETURN return /* only used in main() */
722 # define USAGE(ret) usage(__G__ (ret)) /* used in unzip.c, zipinfo.c */
724 #ifndef TIMET_TO_NATIVE /* everybody but MSC 7.0 and Macintosh */
725 # define TIMET_TO_NATIVE(x)
726 # define NATIVE_TO_TIMET(x)
729 #if (defined(DOS_FLX_OS2_W32) || defined(UNIX) || defined(RISCOS))
734 #if (defined(AOS_VS) || defined(ATARI) || defined(__BEOS__)) /* GRR: others? */
740 /* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
742 #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
743 # if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
744 # define INT_SPRINTF /* sprintf() returns int: SysVish/Posix */
746 # if (defined(DOS_FLX_OS2_W32) || defined(VMS) || defined(AMIGA))
747 # define INT_SPRINTF /* sprintf() returns int: ANSI */
749 # if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
750 # if (defined(POSIX) || defined(__POSIX))
751 # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
754 # define PCHAR_SPRINTF /* undetermined actual return value */
757 # if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS))
758 # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
761 # define PCHAR_SPRINTF /* sprintf() returns char *: SunOS cc *and* gcc */
765 /* defaults that we hope will take care of most machines in the future */
767 #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
769 # define INT_SPRINTF /* sprintf() returns int: ANSI */
772 # define PCHAR_SPRINTF /* sprintf() returns char *: BSDish */
776 #define MSG_STDERR(f) (f & 1) /* bit 0: 0 = stdout, 1 = stderr */
777 #define MSG_INFO(f) ((f & 6) == 0) /* bits 1 and 2: 0 = info */
778 #define MSG_WARN(f) ((f & 6) == 2) /* bits 1 and 2: 1 = warning */
779 #define MSG_ERROR(f) ((f & 6) == 4) /* bits 1 and 2: 2 = error */
780 #define MSG_FATAL(f) ((f & 6) == 6) /* bits 1 and 2: (3 = fatal error) */
781 #define MSG_ZFN(f) (f & 0x0008) /* bit 3: 1 = print zipfile name */
782 #define MSG_FN(f) (f & 0x0010) /* bit 4: 1 = print filename */
783 #define MSG_LNEWLN(f) (f & 0x0020) /* bit 5: 1 = leading newline if !SOL */
784 #define MSG_TNEWLN(f) (f & 0x0040) /* bit 6: 1 = trailing newline if !SOL */
785 #define MSG_MNEWLN(f) (f & 0x0080) /* bit 7: 1 = trailing NL for prompts */
786 /* the following are subject to change */
787 #define MSG_NO_WGUI(f) (f & 0x0100) /* bit 8: 1 = skip if Windows GUI */
788 #define MSG_NO_AGUI(f) (f & 0x0200) /* bit 9: 1 = skip if Acorn GUI */
789 #define MSG_NO_DLL2(f) (f & 0x0400) /* bit 10: 1 = skip if OS/2 DLL */
790 #define MSG_NO_NDLL(f) (f & 0x0800) /* bit 11: 1 = skip if WIN32 DLL */
791 #define MSG_NO_WDLL(f) (f & 0x1000) /* bit 12: 1 = skip if Windows DLL */
793 #if (defined(MORE) && !defined(SCREENLINES))
794 # ifdef DOS_FLX_OS2_W32
795 # define SCREENLINES 25 /* can be (should be) a function instead */
797 # define SCREENLINES 24 /* VT-100s are assumed to be minimal hardware */
801 #define DIR_BLKSIZ 64 /* number of directory entries per block
802 * (should fit in 4096 bytes, usually) */
804 # define WSIZE 0x8000 /* window size--must be a power of two, and */
805 #endif /* at least 32K for zip's deflate method */
808 # if (defined(MED_MEM) || defined(SMALL_MEM))
809 # define INBUFSIZ 2048 /* works for MS-DOS small model */
811 # define INBUFSIZ 8192 /* larger buffers for real OSes */
816 # define nearmalloc malloc
817 # define nearfree free
818 # if (!defined(__IBMC__) || !defined(OS2))
828 #if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
829 # undef DYNALLOC_CRCTAB
832 #if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
833 # undef DYNALLOC_CRCTAB /* not safe with reentrant code */
836 #if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
837 # ifdef DYNALLOC_CRCTAB
838 # undef DYNALLOC_CRCTAB
842 #if (defined(USE_ZLIB) && defined(ASM_CRC))
846 /* Logic for case of small memory, length of EOL > 1: if OUTBUFSIZ == 2048,
847 * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
848 * and transbuf 1040 bytes. Have room for 32 extra EOL chars; 1008/32 == 31.5
849 * chars/line, smaller than estimated 35-70 characters per line for C source
850 * and normal text. Hence difference is sufficient for most "average" files.
851 * (Argument scales for larger OUTBUFSIZ.)
853 #ifdef SMALL_MEM /* i.e., 16-bit OSes: MS-DOS, OS/2 1.x, etc. */
854 # define LoadFarString(x) fLoadFarString(__G__ (x))
855 # define LoadFarStringSmall(x) fLoadFarStringSmall(__G__ (x))
856 # define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
857 # if (defined(_MSC_VER) && (_MSC_VER >= 600))
858 # define zfstrcpy(dest, src) _fstrcpy((dest), (src))
861 # define Far far /* __far only works for MSC 6.00, not 6.0a or Borland */
863 # define OUTBUFSIZ INBUFSIZ
865 # define RAWBUFSIZ (OUTBUFSIZ>>1)
867 # define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
869 # define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
870 typedef short shrint
; /* short/int or "shrink int" (unshrink) */
872 # define zfstrcpy(dest, src) strcpy((dest), (src))
874 # define LoadFarString(x) Qstrfix(x) /* fix up _ for '.' */
875 # define LoadFarStringSmall(x) Qstrfix(x)
876 # define LoadFarStringSmall2(x) Qstrfix(x)
878 # define LoadFarString(x) x
879 # define LoadFarStringSmall(x) x
880 # define LoadFarStringSmall2(x) x
883 # define OUTBUFSIZ 0xFF80 /* can't malloc arrays of 0xFFE8 or more */
884 # define TRANSBUFSIZ 0xFF80
885 typedef short shrint
;
887 # define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
888 # define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
890 typedef short shrint
;
892 typedef int shrint
; /* for efficiency/speed, we hope... */
894 # endif /* ?MED_MEM */
895 # define RAWBUFSIZ OUTBUFSIZ
896 #endif /* ?SMALL_MEM */
906 #ifdef SFX /* disable some unused features for SFX executables */
915 /* user may have defined both by accident... NOTIMESTAMP takes precedence */
916 #if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
920 #if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
921 # define COPYRIGHT_CLEAN
924 #if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
933 # define PIPE_ERROR (errno == EPIPE)
936 /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
938 # define FOPR "r","ctx=stm"
939 # define FOPM "r+","ctx=stm","rfm=fix","mrs=512"
940 # define FOPW "w","ctx=stm","rfm=fix","mrs=512"
944 /* Binary files must be RECFM=F,LRECL=1 for ftell() to get correct pos */
945 /* ...unless byteseek is used. Let's try that for a while. */
946 # define FOPR "rb,byteseek"
947 # define FOPM "r+b,byteseek"
948 # define FOPW "wb,recfm=v,lrecl=32760"
950 # define FOPWT "w,lrecl=133"
956 #ifdef TOPS20 /* TOPS-20 MODERN? You kidding? */
960 /* Defaults when nothing special has been defined previously. */
990 * If <limits.h> exists on most systems, should include that, since it may
991 * define some or all of the following: NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
1000 # define PATH_MAX MAXPATHLEN /* in <sys/param.h> on some systems */
1003 # define PATH_MAX _MAX_PATH
1005 # if FILENAME_MAX > 255
1006 # define PATH_MAX FILENAME_MAX /* used like PATH_MAX on some systems */
1008 # define PATH_MAX 1024
1010 # endif /* ?_MAX_PATH */
1011 # endif /* ?MAXPATHLEN */
1012 #endif /* !PATH_MAX */
1014 #define FILNAMSIZ PATH_MAX
1016 #ifdef SHORT_SYMS /* Mark Williams C, ...? */
1017 # define extract_or_test_files xtr_or_tst_files
1018 # define extract_or_test_member xtr_or_tst_member
1021 #ifdef REALLY_SHORT_SYMS /* TOPS-20 linker: first 6 chars */
1022 # define process_cdir_file_hdr XXpcdfh
1023 # define process_local_file_hdr XXplfh
1024 # define extract_or_test_files XXxotf /* necessary? */
1025 # define extract_or_test_member XXxotm /* necessary? */
1026 # define check_for_newer XXcfn
1027 # define overwrite_all XXoa
1028 # define process_all_files XXpaf
1029 # define extra_field XXef
1030 # define explode_lit8 XXel8
1031 # define explode_lit4 XXel4
1032 # define explode_nolit8 XXnl8
1033 # define explode_nolit4 XXnl4
1034 # define cpdist8 XXcpdist8
1035 # define inflate_codes XXic
1036 # define inflate_stored XXis
1037 # define inflate_fixed XXif
1038 # define inflate_dynamic XXid
1039 # define inflate_block XXib
1040 # define maxcodemax XXmax
1043 #ifndef S_TIME_T_MAX /* max value of signed (>= 32-bit) time_t */
1044 # define S_TIME_T_MAX ((time_t)(ulg)0x7fffffffL)
1046 #ifndef U_TIME_T_MAX /* max value of unsigned (>= 32-bit) time_t */
1047 # define U_TIME_T_MAX ((time_t)(ulg)0xffffffffL)
1049 #ifdef DOSTIME_MINIMUM /* min DOSTIME value (1980-01-01) */
1050 # undef DOSTIME_MINIMUM
1052 #define DOSTIME_MINIMUM ((ulg)0x00210000L)
1053 #ifdef DOSTIME_2038_01_18 /* approximate DOSTIME equivalent of */
1054 # undef DOSTIME_2038_01_18 /* the signed-32-bit time_t limit */
1056 #define DOSTIME_2038_01_18 ((ulg)0x74320000L)
1059 # define ZSUFX "_zip"
1060 # define ALT_ZSUFX ".zip"
1063 # define ZSUFX "/zip"
1065 # define ZSUFX ".zip"
1067 # define ALT_ZSUFX ".ZIP" /* Unix-only so far (only case-sensitive fs) */
1070 #define CENTRAL_HDR_SIG "\001\002" /* the infamous "PK" signature bytes, */
1071 #define LOCAL_HDR_SIG "\003\004" /* sans "PK" (so unzip executable not */
1072 #define END_CENTRAL_SIG "\005\006" /* mistaken for zipfile itself) */
1073 #define EXTD_LOCAL_SIG "\007\010" /* [ASCII "\113" == EBCDIC "\080" ??] */
1075 /* choice of activities for do_string() */
1076 #define SKIP 0 /* skip header block */
1077 #define DISPLAY 1 /* display archive comment (ASCII) */
1078 #define DISPL_8 5 /* display file comment (ext. ASCII) */
1079 #define DS_FN 2 /* read filename (ext. ASCII) */
1080 #define EXTRA_FIELD 3 /* copy extra field into buffer */
1086 #define DOES_NOT_EXIST -1 /* return values for check_for_newer() */
1087 #define EXISTS_AND_OLDER 0
1088 #define EXISTS_AND_NEWER 1
1090 #define ROOT 0 /* checkdir() extract-to path: called once */
1091 #define INIT 1 /* allocate buildpath: called once per member */
1092 #define APPEND_DIR 2 /* append a dir comp.: many times per member */
1093 #define APPEND_NAME 3 /* append actual filename: once per member */
1094 #define GETPATH 4 /* retrieve the complete path and free it */
1095 #define END 5 /* free root path prior to exiting program */
1097 /* version_made_by codes (central dir): make sure these */
1098 /* are not defined on their respective systems!! */
1099 #define FS_FAT_ 0 /* filesystem used by MS-DOS, OS/2, Win32 */
1104 #define ATARI_ 5 /* what if it's a minix filesystem? [cjh] */
1105 #define FS_HPFS_ 6 /* filesystem used by OS/2 (and NT 3.x) */
1106 #define MAC_ 7 /* HFS filesystem used by MacOS */
1110 #define FS_NTFS_ 11 /* filesystem used by Windows NT */
1112 #define ACORN_ 13 /* Archimedes Acorn RISC OS */
1113 #define FS_VFAT_ 14 /* filesystem used by Windows 95, NT */
1115 #define BEOS_ 16 /* hybrid POSIX/database filesystem */
1116 #define TANDEM_ 17 /* Tandem/NSK */
1117 #define NUM_HOSTS 18 /* index of last system + 1 */
1119 #define STORED 0 /* compression methods */
1128 #define ENHDEFLATED 9
1129 #define DCLIMPLODED 10
1130 #define NUM_METHODS 11 /* index of last method + 1 */
1131 /* don't forget to update list_files(), extract.c and zipinfo.c appropriately
1132 * if NUM_METHODS changes */
1134 /* (the PK-class error codes are public and have been moved into unzip.h) */
1136 #define DF_MDY 0 /* date format 10/26/91 (USA only) */
1137 #define DF_DMY 1 /* date format 26/10/91 (most of the world) */
1138 #define DF_YMD 2 /* date format 91/10/26 (a few countries) */
1140 /*---------------------------------------------------------------------------
1141 Extra-field block ID values and offset info.
1142 ---------------------------------------------------------------------------*/
1143 /* extra-field ID values, all little-endian: */
1144 #define EF_AV 0x0007 /* PKWARE's authenticity verification */
1145 #define EF_OS2 0x0009 /* OS/2 extended attributes */
1146 #define EF_PKW32 0x000a /* PKWARE's Win95/98/WinNT filetimes */
1147 #define EF_PKVMS 0x000c /* PKWARE's VMS */
1148 #define EF_PKUNIX 0x000d /* PKWARE's Unix */
1149 #define EF_IZVMS 0x4d49 /* Info-ZIP's VMS ("IM") */
1150 #define EF_IZUNIX 0x5855 /* Info-ZIP's old Unix[1] ("UX") */
1151 #define EF_IZUNIX2 0x7855 /* Info-ZIP's new Unix[2] ("Ux") */
1152 #define EF_TIME 0x5455 /* universal timestamp ("UT") */
1153 #define EF_MAC3 0x334d /* Info-ZIP's new Macintosh (= "M3") */
1154 #define EF_JLMAC 0x07c8 /* Johnny Lee's old Macintosh (= 1992) */
1155 #define EF_ZIPIT 0x2605 /* Thomas Brown's Macintosh (ZipIt) */
1156 #define EF_ZIPIT2 0x2705 /* T. Brown's Mac (ZipIt) v 1.3.8 and newer ? */
1157 #define EF_VMCMS 0x4704 /* Info-ZIP's VM/CMS ("\004G") */
1158 #define EF_MVS 0x470f /* Info-ZIP's MVS ("\017G") */
1159 #define EF_ACL 0x4c41 /* (OS/2) access control list ("AL") */
1160 #define EF_NTSD 0x4453 /* NT security descriptor ("SD") */
1161 #define EF_BEOS 0x6542 /* BeOS ("Be") */
1162 #define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
1163 #define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
1164 #define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
1165 #define EF_MD5 0x4b46 /* Fred Kantor's MD5 ("FK") */
1166 #define EF_ASIUNIX 0x756e /* ASi's Unix ("nu") */
1168 #define EB_HEADSIZE 4 /* length of extra field block header */
1169 #define EB_ID 0 /* offset of block ID in header */
1170 #define EB_LEN 2 /* offset of data length field in header */
1171 #define EB_UCSIZE_P 0 /* offset of ucsize field in compr. data */
1172 #define EB_CMPRHEADLEN 6 /* lenght of compression header */
1174 #define EB_UX_MINLEN 8 /* minimal "UX" field contains atime, mtime */
1175 #define EB_UX_FULLSIZE 12 /* full "UX" field (atime, mtime, uid, gid) */
1176 #define EB_UX_ATIME 0 /* offset of atime in "UX" extra field data */
1177 #define EB_UX_MTIME 4 /* offset of mtime in "UX" extra field data */
1178 #define EB_UX_UID 8 /* byte offset of UID in "UX" field data */
1179 #define EB_UX_GID 10 /* byte offset of GID in "UX" field data */
1181 #define EB_UX2_MINLEN 4 /* minimal "Ux" field contains UID/GID */
1182 #define EB_UX2_UID 0 /* byte offset of UID in "Ux" field data */
1183 #define EB_UX2_GID 2 /* byte offset of GID in "Ux" field data */
1184 #define EB_UX2_VALID (1 << 8) /* UID/GID present */
1186 #define EB_UT_MINLEN 1 /* minimal UT field contains Flags byte */
1187 #define EB_UT_FLAGS 0 /* byte offset of Flags field */
1188 #define EB_UT_TIME1 1 /* byte offset of 1st time value */
1189 #define EB_UT_FL_MTIME (1 << 0) /* mtime present */
1190 #define EB_UT_FL_ATIME (1 << 1) /* atime present */
1191 #define EB_UT_FL_CTIME (1 << 2) /* ctime present */
1193 #define EB_FLGS_OFFS 4 /* offset of flags area in generic compressed
1194 extra field blocks (OS2, NT, and others) */
1195 #define EB_OS2_HLEN 4 /* size of OS2/ACL compressed data header */
1196 #define EB_BEOS_HLEN 5 /* length of BeOS e.f attribute header */
1197 #define EB_BE_FL_UNCMPR 0x01 /* "BeOS attributes uncompressed" bit flag */
1198 #define EB_MAC3_HLEN 14 /* length of Mac3 attribute block header */
1199 #define EB_M3_FL_DATFRK 0x01 /* "this entry is data fork" flag */
1200 #define EB_M3_FL_UNCMPR 0x04 /* "Mac3 attributes uncompressed" bit flag */
1201 #define EB_M3_FL_TIME64 0x08 /* "Mac3 time fields are 64 bit wide" flag */
1202 #define EB_M3_FL_NOUTC 0x10 /* "Mac3 timezone offset fields missing" flag */
1204 #define EB_NTSD_C_LEN 4 /* length of central NT security data */
1205 #define EB_NTSD_L_LEN 5 /* length of minimal local NT security data */
1206 #define EB_NTSD_VERSION 4 /* offset of NTSD version byte */
1207 #define EB_NTSD_MAX_VER (0) /* maximum version # we know how to handle */
1209 #define EB_ASI_CRC32 0 /* offset of ASI Unix field's crc32 checksum */
1210 #define EB_ASI_MODE 4 /* offset of ASI Unix permission mode field */
1212 /*---------------------------------------------------------------------------
1213 True sizes of the various headers, as defined by PKWARE--so it is not
1214 likely that these will ever change. But if they do, make sure both these
1215 defines AND the typedefs below get updated accordingly.
1216 ---------------------------------------------------------------------------*/
1217 #define LREC_SIZE 26 /* lengths of local file headers, central */
1218 #define CREC_SIZE 42 /* directory headers, and the end-of- */
1219 #define ECREC_SIZE 18 /* central-dir record, respectively */
1221 #define MAX_BITS 13 /* used in unshrink() */
1222 #define HSIZE (1 << MAX_BITS) /* size of global work area */
1224 #define LF 10 /* '\n' on ASCII machines; must be 10 due to EBCDIC */
1225 #define CR 13 /* '\r' on ASCII machines; must be 13 due to EBCDIC */
1226 #define CTRLZ 26 /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
1229 # define foreign(c) ascii[(uch)(c)]
1230 # define native(c) ebcdic[(uch)(c)]
1231 # define NATIVE "EBCDIC"
1235 #if (defined(CRAY) && defined(ZMEM))
1241 # define memcmp(b1,b2,len) bcmp(b2,b1,len)
1242 # define memcpy(dest,src,len) bcopy(src,dest,len)
1243 # define memzero bzero
1245 # define memzero(dest,len) memset(dest,0,len)
1249 # define ENV_UNZIP "UNZIP_OPTS" /* names of environment variables */
1250 # define ENV_ZIPINFO "ZIPINFO_OPTS"
1253 # define ENV_UNZIP "Unzip$Options"
1254 # define ENV_ZIPINFO "Zipinfo$Options"
1255 # define ENV_UNZIPEXTS "Unzip$Exts"
1258 # define ENV_UNZIP "UNZIP" /* the standard names */
1259 # define ENV_ZIPINFO "ZIPINFO"
1261 #define ENV_UNZIP2 "UNZIPOPT" /* alternate names, for zip compat. */
1262 #define ENV_ZIPINFO2 "ZIPINFOOPT"
1264 #if (!defined(QQ) && !defined(NOQQ))
1268 #ifdef QQ /* Newtware version: no file */
1269 # define QCOND (!uO.qflag) /* comments with -vq or -vqq */
1270 #else /* Bill Davidsen version: no way to */
1271 # define QCOND (longhdr) /* kill file comments when listing */
1275 # define QCOND2 (uO.qflag < 2)
1277 # define QCOND2 (!uO.qflag)
1281 # define TRUE 1 /* sort of obvious */
1293 #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
1296 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
1298 #endif /* UNIX && S_IFLNK && !MTS */
1302 # define S_ISDIR(m) (FALSE)
1304 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1309 # define IS_VOLID(m) ((m) & 0x08)
1322 typedef unsigned short uid_t
; /* TI SysV.3 */
1323 typedef unsigned short gid_t
;
1325 typedef unsigned int uid_t
; /* SCO Xenix */
1326 typedef unsigned int gid_t
;
1330 #if (defined(WIN32) || defined(sgi) || defined(GOT_UTIMBUF) || defined(ATARI))
1331 typedef struct utimbuf ztimbuf
;
1333 typedef struct ztimbuf
{
1334 time_t actime
; /* new access time */
1335 time_t modtime
; /* new modification time */
1339 typedef struct iztimes
{
1340 time_t atime
; /* new access time */
1341 time_t mtime
; /* new modification time */
1342 time_t ctime
; /* used for creation time; NOT same as st_ctime */
1345 #ifdef SET_DIR_ATTRIB
1346 typedef struct dirtime
{ /* temporary struct for holding directory info */
1347 struct dirtime
*next
; /* until can be sorted and set at end */
1348 char *fn
; /* filename of directory */
1350 iztimes t3
; /* mtime, atime, ctime */
1351 ztimbuf t2
; /* modtime, actime */
1353 unsigned perms
; /* same as min_info.file_attr */
1354 int have_uidgid
; /* flag */
1357 #endif /* SET_DIR_ATTRIB */
1359 typedef struct min_info
{
1361 ulg crc
; /* crc (needed if extended header) */
1362 ulg compr_size
; /* compressed size (needed if extended header) */
1363 ulg uncompr_size
; /* uncompressed size (needed if extended header) */
1365 unsigned file_attr
; /* local flavor, as used by creat(), chmod()... */
1366 unsigned encrypted
: 1; /* file encrypted: decrypt before uncompressing */
1367 unsigned ExtLocHdr
: 1; /* use time instead of CRC for decrypt check */
1368 unsigned textfile
: 1; /* file is text (according to zip) */
1369 unsigned textmode
: 1; /* file is to be extracted as text */
1370 unsigned lcflag
: 1; /* convert filename to lowercase */
1371 unsigned vollabel
: 1; /* "file" is an MS-DOS volume (disk) label */
1374 typedef struct VMStimbuf
{
1375 char *revdate
; /* (both roughly correspond to Unix modtime/st_mtime) */
1379 /*---------------------------------------------------------------------------
1380 Zipfile work area declarations.
1381 ---------------------------------------------------------------------------*/
1385 struct { /* unshrink(): */
1386 shrint
*Parent
; /* (8193 * sizeof(shrint)) */
1390 uch
*Slide
; /* explode(), inflate(), unreduce() */
1392 #else /* !MALLOC_WORK */
1394 struct { /* unshrink(): */
1395 shrint Parent
[HSIZE
]; /* (8192 * sizeof(shrint)) == 16KB minimum */
1396 uch value
[HSIZE
]; /* 8KB */
1397 uch Stack
[HSIZE
]; /* 8KB */
1398 } shrink
; /* total = 32KB minimum; 80KB on Cray/Alpha */
1399 uch Slide
[WSIZE
]; /* explode(), inflate(), unreduce() */
1401 #endif /* ?MALLOC_WORK */
1403 #define slide G.area.Slide
1405 #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
1406 # define redirSlide G.redirect_sldptr
1408 # define redirSlide G.area.Slide
1411 /*---------------------------------------------------------------------------
1412 Zipfile layout declarations. If these headers ever change, make sure the
1413 xxREC_SIZE defines (above) change with them!
1414 ---------------------------------------------------------------------------*/
1416 typedef uch local_byte_hdr
[ LREC_SIZE
];
1417 # define L_VERSION_NEEDED_TO_EXTRACT_0 0
1418 # define L_VERSION_NEEDED_TO_EXTRACT_1 1
1419 # define L_GENERAL_PURPOSE_BIT_FLAG 2
1420 # define L_COMPRESSION_METHOD 4
1421 # define L_LAST_MOD_DOS_DATETIME 6
1423 # define L_COMPRESSED_SIZE 14
1424 # define L_UNCOMPRESSED_SIZE 18
1425 # define L_FILENAME_LENGTH 22
1426 # define L_EXTRA_FIELD_LENGTH 24
1428 typedef uch cdir_byte_hdr
[ CREC_SIZE
];
1429 # define C_VERSION_MADE_BY_0 0
1430 # define C_VERSION_MADE_BY_1 1
1431 # define C_VERSION_NEEDED_TO_EXTRACT_0 2
1432 # define C_VERSION_NEEDED_TO_EXTRACT_1 3
1433 # define C_GENERAL_PURPOSE_BIT_FLAG 4
1434 # define C_COMPRESSION_METHOD 6
1435 # define C_LAST_MOD_DOS_DATETIME 8
1437 # define C_COMPRESSED_SIZE 16
1438 # define C_UNCOMPRESSED_SIZE 20
1439 # define C_FILENAME_LENGTH 24
1440 # define C_EXTRA_FIELD_LENGTH 26
1441 # define C_FILE_COMMENT_LENGTH 28
1442 # define C_DISK_NUMBER_START 30
1443 # define C_INTERNAL_FILE_ATTRIBUTES 32
1444 # define C_EXTERNAL_FILE_ATTRIBUTES 34
1445 # define C_RELATIVE_OFFSET_LOCAL_HEADER 38
1447 typedef uch ec_byte_rec
[ ECREC_SIZE
+4 ];
1448 /* define SIGNATURE 0 space-holder only */
1449 # define NUMBER_THIS_DISK 4
1450 # define NUM_DISK_WITH_START_CENTRAL_DIR 6
1451 # define NUM_ENTRIES_CENTRL_DIR_THS_DISK 8
1452 # define TOTAL_ENTRIES_CENTRAL_DIR 10
1453 # define SIZE_CENTRAL_DIRECTORY 12
1454 # define OFFSET_START_CENTRAL_DIRECTORY 16
1455 # define ZIPFILE_COMMENT_LENGTH 20
1458 typedef struct local_file_header
{ /* LOCAL */
1459 uch version_needed_to_extract
[2];
1460 ush general_purpose_bit_flag
;
1461 ush compression_method
;
1462 ulg last_mod_dos_datetime
;
1466 ush filename_length
;
1467 ush extra_field_length
;
1471 typedef struct central_directory_file_header
{ /* CENTRAL */
1472 uch version_made_by
[2];
1473 uch version_needed_to_extract
[2];
1474 ush general_purpose_bit_flag
;
1475 ush compression_method
;
1476 ulg last_mod_dos_datetime
;
1480 ush filename_length
;
1481 ush extra_field_length
;
1482 ush file_comment_length
;
1483 ush disk_number_start
;
1484 ush internal_file_attributes
;
1485 ulg external_file_attributes
;
1486 ulg relative_offset_local_header
;
1490 typedef struct end_central_dir_record
{ /* END CENTRAL */
1491 ush number_this_disk
;
1492 ush num_disk_start_cdir
;
1493 ush num_entries_centrl_dir_ths_disk
;
1494 ush total_entries_central_dir
;
1495 ulg size_central_directory
;
1496 ulg offset_start_central_directory
;
1497 ush zipfile_comment_length
;
1501 /* Huffman code lookup table entry--this entry is four bytes for machines
1502 that have 16-bit pointers (e.g. PC's in the small or medium model).
1503 Valid extra bits are 0..13. e == 15 is EOB (end of block), e == 16
1504 means that v is a literal, 16 < e < 32 means that v is a pointer to
1505 the next table, which codes e - 16 bits, and lastly e == 99 indicates
1506 an unused code. If a code with e == 99 is looked up, this implies an
1507 error in the data. */
1510 uch e
; /* number of extra bits or operation */
1511 uch b
; /* number of bits in this code or subcode */
1513 ush n
; /* literal, length base, or distance base */
1514 struct huft
*t
; /* pointer to next level of table */
1519 typedef struct _APIDocStruct
{
1533 #if (defined(OS2) && !defined(FUNZIP))
1534 # include "os2/os2data.h"
1537 #include "globals.h"
1541 /*************************/
1542 /* Function Prototypes */
1543 /*************************/
1545 /*---------------------------------------------------------------------------
1546 Functions in unzip.c (initialization routines):
1547 ---------------------------------------------------------------------------*/
1550 int MAIN
OF((int argc
, char **argv
));
1551 int unzip
OF((__GPRO__
int argc
, char **argv
));
1552 int uz_opts
OF((__GPRO__
int *pargc
, char ***pargv
));
1553 int usage
OF((__GPRO__
int error
));
1554 #endif /* !WINDLL */
1556 /*---------------------------------------------------------------------------
1557 Functions in process.c (main driver routines):
1558 ---------------------------------------------------------------------------*/
1560 int process_zipfiles
OF((__GPRO
));
1561 void free_G_buffers
OF((__GPRO
));
1562 /* static int do_seekable OF((__GPRO__ int lastchance)); */
1563 /* static int find_ecrec OF((__GPRO__ long searchlen)); */
1564 int uz_end_central
OF((__GPRO
));
1565 int process_cdir_file_hdr
OF((__GPRO
));
1566 int get_cdir_ent
OF((__GPRO
));
1567 int process_local_file_hdr
OF((__GPRO
));
1568 unsigned ef_scan_for_izux
OF((uch
*ef_buf
, unsigned ef_len
, int ef_is_c
,
1570 iztimes
*z_utim
, ush
*z_uidgid
));
1574 /*---------------------------------------------------------------------------
1575 Functions in zipinfo.c (`zipinfo-style' listing routines):
1576 ---------------------------------------------------------------------------*/
1580 int zi_opts
OF((__GPRO__
int *pargc
, char ***pargv
));
1582 int zi_end_central
OF((__GPRO
));
1583 int zipinfo
OF((__GPRO
));
1584 /* static int zi_long OF((__GPRO__ ulg *pEndprev)); */
1585 /* static int zi_short OF((__GPRO)); */
1586 /* static char *zi_time OF((__GPRO__ ZCONST ulg *datetimez,
1587 ZCONST time_t *modtimez, char *d_t_str));*/
1588 #endif /* !NO_ZIPINFO */
1590 /*---------------------------------------------------------------------------
1591 Functions in list.c (generic zipfile-listing routines):
1592 ---------------------------------------------------------------------------*/
1594 int list_files
OF((__GPRO
));
1596 int get_time_stamp
OF((__GPRO__
time_t *last_modtime
,
1597 unsigned *nmember
));
1599 int ratio
OF((ulg uc
, ulg c
));
1600 void fnprint
OF((__GPRO
));
1604 /*---------------------------------------------------------------------------
1605 Functions in fileio.c:
1606 ---------------------------------------------------------------------------*/
1608 int open_input_file
OF((__GPRO
));
1609 int open_outfile
OF((__GPRO
)); /* also vms.c */
1610 void undefer_input
OF((__GPRO
));
1611 void defer_leftover_input
OF((__GPRO
));
1612 unsigned readbuf
OF((__GPRO__
char *buf
, register unsigned len
));
1613 int readbyte
OF((__GPRO
));
1614 int fillinbuf
OF((__GPRO
));
1616 int flush
OF((__GPRO__ ulg size
)); /* actually funzip.c */
1618 int flush
OF((__GPRO__ uch
*buf
, ulg size
, int unshrink
));
1620 /* static int disk_error OF((__GPRO)); */
1621 void handler
OF((int signal
));
1622 time_t dos_to_unix_time
OF((ulg dos_datetime
));
1623 int check_for_newer
OF((__GPRO__
char *filename
)); /* os2,vmcms,vms */
1624 int do_string
OF((__GPRO__
unsigned int len
, int option
));
1625 ush makeword
OF((ZCONST uch
*b
));
1626 ulg makelong
OF((ZCONST uch
*sig
));
1627 #if (!defined(STR_TO_ISO) || defined(NEED_STR2ISO))
1628 char *str2iso
OF((char *dst
, ZCONST
char *src
));
1630 #if (!defined(STR_TO_OEM) || defined(NEED_STR2OEM))
1631 char *str2oem
OF((char *dst
, ZCONST
char *src
));
1633 int zstrnicmp
OF((register ZCONST
char *s1
,
1634 register ZCONST
char *s2
,
1635 register unsigned n
));
1637 int zstat
OF((char *p
, struct stat
*s
));
1639 #ifdef ZMEM /* MUST be ifdef'd because of conflicts with the standard def. */
1640 zvoid
*memset
OF((register zvoid
*, register int, register unsigned int));
1641 int memcmp
OF((register ZCONST zvoid
*, register ZCONST zvoid
*,
1642 register unsigned int));
1643 zvoid
*memcpy
OF((register zvoid
*, register ZCONST zvoid
*,
1644 register unsigned int));
1647 char *fLoadFarString
OF((__GPRO__
const char Far
*sz
));
1648 char *fLoadFarStringSmall
OF((__GPRO__
const char Far
*sz
));
1649 char *fLoadFarStringSmall2
OF((__GPRO__
const char Far
*sz
));
1651 char Far
* Far zfstrcpy
OF((char Far
*s1
, const char Far
*s2
));
1656 /*---------------------------------------------------------------------------
1657 Functions in extract.c:
1658 ---------------------------------------------------------------------------*/
1660 int extract_or_test_files
OF((__GPRO
));
1661 /* static int store_info OF((void)); */
1662 /* static int extract_or_test_member OF((__GPRO)); */
1663 /* static int TestExtraField OF((__GPRO__ uch *ef, unsigned ef_len)); */
1664 /* static int test_OS2 OF((__GPRO__ uch *eb, unsigned eb_size)); */
1665 /* static int test_NT OF((__GPRO__ uch *eb, unsigned eb_size)); */
1666 int memextract
OF((__GPRO__ uch
*tgt
, ulg tgtsize
,
1667 uch
*src
, ulg srcsize
));
1668 int memflush
OF((__GPRO__ uch
*rawbuf
, ulg size
));
1669 char *fnfilter
OF((ZCONST
char *raw
, uch
*space
));
1671 /*---------------------------------------------------------------------------
1672 Decompression functions:
1673 ---------------------------------------------------------------------------*/
1675 #if (!defined(SFX) && !defined(FUNZIP))
1676 int explode
OF((__GPRO
)); /* explode.c */
1678 int huft_free
OF((struct huft
*t
)); /* inflate.c */
1679 int huft_build
OF((__GPRO__ ZCONST
unsigned *b
, unsigned n
,
1680 unsigned s
, ZCONST ush
*d
, ZCONST ush
*e
,
1681 struct huft
**t
, int *m
));
1683 int UZinflate
OF((__GPRO
)); /* inflate.c */
1684 # define inflate_free(x) inflateEnd(&((Uz_Globs *)(&G))->dstrm)
1686 int inflate
OF((__GPRO
)); /* inflate.c */
1687 int inflate_free
OF((__GPRO
)); /* inflate.c */
1688 #endif /* ?USE_ZLIB */
1689 #if (!defined(SFX) && !defined(FUNZIP))
1690 void unreduce
OF((__GPRO
)); /* unreduce.c */
1691 /* static void LoadFollowers OF((__GPRO__ f_array *follower, uch *Slen));
1693 int unshrink
OF((__GPRO
)); /* unshrink.c */
1694 /* static void partial_clear OF((__GPRO)); * unshrink.c */
1695 #endif /* !SFX && !FUNZIP */
1697 /*---------------------------------------------------------------------------
1698 Internal API functions (only included in DLL versions):
1699 ---------------------------------------------------------------------------*/
1702 void setFileNotFound
OF((__GPRO
)); /* api.c */
1703 int unzipToMemory
OF((__GPRO__
char *zip
, char *file
,
1704 UzpBuffer
*retstr
)); /* api.c */
1705 int redirect_outfile
OF((__GPRO
)); /* api.c */
1706 int writeToMemory
OF((__GPRO__ uch
*rawbuf
, ulg size
));
1707 int close_redirect
OF((__GPRO
)); /* api.c */
1708 /* this obsolescent entry point kept for compatibility: */
1709 int UzpUnzip
OF((int argc
, char **argv
));/* use UzpMain */
1711 int varmessage
OF((__GPRO__ uch
*buf
, ulg size
));
1712 int varputchar
OF((__GPRO__
int c
)); /* rexxapi.c */
1713 int finish_REXX_redirect
OF((__GPRO
)); /* rexxapi.c */
1716 void APIhelp
OF((__GPRO__
int argc
, char **argv
));
1717 #endif /* apihelp.c */
1720 /*---------------------------------------------------------------------------
1721 Acorn RISC OS-only functions:
1722 ---------------------------------------------------------------------------*/
1725 int isRISCOSexfield
OF((void *extra_field
)); /* acorn.c */
1726 void setRISCOSexfield
OF((char *path
, void *extra_field
)); /* acorn.c */
1727 void printRISCOSexfield
OF((int isdir
, void *extra_field
)); /* acorn.c */
1730 /*---------------------------------------------------------------------------
1731 Human68K-only functions:
1732 ---------------------------------------------------------------------------*/
1735 void InitTwentyOne
OF((void));
1738 /*---------------------------------------------------------------------------
1739 Macintosh-only functions:
1740 ---------------------------------------------------------------------------*/
1743 void screenOpen
OF((char *)); /* macscreen.c */
1744 void screenControl
OF((char *, int)); /* macscreen.c */
1745 void screenDump
OF((char *, long)); /* macscreen.c */
1746 void screenUpdate
OF((WindowPtr
)); /* macscreen.c */
1747 void screenClose
OF((void)); /* macscreen.c */
1748 int macgetch
OF((void)); /* macscreen.c */
1750 int macmkdir
OF((char *)); /* mac.c */
1751 short macopen
OF((char *, short)); /* mac.c */
1752 short maccreat
OF((char *)); /* mac.c */
1753 short macread
OF((short, char *, unsigned)); /* mac.c */
1754 long macwrite
OF((short, char *, unsigned)); /* mac.c */
1755 short macclose
OF((short)); /* mac.c */
1756 long maclseek
OF((short, long, short)); /* mac.c */
1757 char *macfgets
OF((char *, int, FILE *)); /* mac.c */
1758 int macfprintf
OF((FILE *, char *, ...)); /* mac.c */
1759 int macprintf
OF((char *, ...)); /* mac.c */
1762 /*---------------------------------------------------------------------------
1763 MSDOS-only functions:
1764 ---------------------------------------------------------------------------*/
1766 #if (defined(MSDOS) && (defined(__GO32__) || defined(__EMX__)))
1767 unsigned _dos_getcountryinfo(void *); /* msdos.c */
1768 #if (!defined(__DJGPP__) || (__DJGPP__ < 2))
1769 unsigned _dos_setftime(int, unsigned short, unsigned short); /* msdos.c */
1770 unsigned _dos_setfileattr(char *, unsigned); /* msdos.c */
1771 unsigned _dos_creat(char *, unsigned, int *); /* msdos.c */
1772 void _dos_getdrive(unsigned *); /* msdos.c */
1773 unsigned _dos_close(int); /* msdos.c */
1774 #endif /* !__DJGPP__ || (__DJGPP__ < 2) */
1777 /*---------------------------------------------------------------------------
1778 OS/2-only functions:
1779 ---------------------------------------------------------------------------*/
1781 #ifdef OS2 /* GetFileTime conflicts with something in Win32 header files */
1782 #if (defined(REENTRANT) && defined(USETHREADID))
1783 ulg GetThreadId
OF((void));
1785 int GetCountryInfo
OF((void)); /* os2.c */
1786 long GetFileTime
OF((ZCONST
char *name
)); /* os2.c */
1787 /* static void SetPathAttrTimes OF((__GPRO__ int flags, int dir)); os2.c */
1788 /* static int SetEAs OF((__GPRO__ const char *path,
1789 void *eablock)); os2.c */
1790 /* static int SetACL OF((__GPRO__ const char *path,
1791 void *eablock)); os2.c */
1792 /* static int IsFileNameValid OF((const char *name)); os2.c */
1793 /* static void map2fat OF((char *pathcomp, char **pEndFAT)); os2.c */
1794 /* static int SetLongNameEA OF((char *name, char *longname)); os2.c */
1795 /* static void InitNLS OF((void)); os2.c */
1796 int IsUpperNLS
OF((int nChr
)); /* os2.c */
1797 int ToLowerNLS
OF((int nChr
)); /* os2.c */
1798 void DebugMalloc
OF((void)); /* os2.c */
1801 /*---------------------------------------------------------------------------
1802 QDOS-only functions:
1803 ---------------------------------------------------------------------------*/
1806 int QMatch (uch
, uch
);
1807 void QFilename (__GPRO__
char *);
1808 char *Qstrfix (char *);
1809 int QReturn (int zip_error
);
1812 /*---------------------------------------------------------------------------
1813 TOPS20-only functions:
1814 ---------------------------------------------------------------------------*/
1817 int upper
OF((char *s
)); /* tops20.c */
1818 int enquote
OF((char *s
)); /* tops20.c */
1819 int dequote
OF((char *s
)); /* tops20.c */
1820 int fnlegal
OF(()); /* error if prototyped? */ /* tops20.c */
1823 /*---------------------------------------------------------------------------
1824 VM/CMS- and MVS-only functions:
1825 ---------------------------------------------------------------------------*/
1828 extent getVMMVSexfield
OF((char *type
, uch
*ef_block
, unsigned datalen
));
1829 FILE *vmmvs_open_infile
OF((__GPRO
)); /* vmmvs.c */
1830 void close_infile
OF((__GPRO
)); /* vmmvs.c */
1833 /*---------------------------------------------------------------------------
1835 ---------------------------------------------------------------------------*/
1838 int check_format
OF((__GPRO
)); /* vms.c */
1839 /* int open_outfile OF((__GPRO)); * (see fileio.c) vms.c */
1840 /* int flush OF((__GPRO__ uch *rawbuf, unsigned size,
1841 int final_flag)); * (see fileio.c) vms.c */
1843 void return_VMS
OF((__GPRO__
int zip_error
)); /* vms.c */
1845 void return_VMS
OF((int zip_error
)); /* vms.c */
1848 ulg vms_unzip_cmdline
OF((int *, char ***)); /* cmdline.c */
1849 int VMSCLI_usage
OF((__GPRO__
int error
)); /* cmdline.c */
1853 /*---------------------------------------------------------------------------
1854 WIN32-only functions:
1855 ---------------------------------------------------------------------------*/
1858 int IsWinNT
OF((void)); /* win32.c */
1860 void process_defer_NT
OF((__GPRO
)); /* win32.c */
1861 int test_NTSD
OF((__GPRO__ uch
*eb
, unsigned eb_size
,
1862 uch
*eb_ucptr
, ulg eb_ucsize
)); /* win32.c */
1863 # define TEST_NTSD test_NTSD
1865 #ifdef W32_STAT_BANDAID
1866 int zstat_win32
OF((__W32STAT_GLOBALS__
1867 const char *path
, struct stat
*buf
)); /* win32.c */
1871 /*---------------------------------------------------------------------------
1872 Miscellaneous/shared functions:
1873 ---------------------------------------------------------------------------*/
1875 Uz_Globs
*globalsCtor
OF((void)); /* globals.c */
1877 void envargs
OF((__GPRO__
int *Pargc
, char ***Pargv
,
1878 ZCONST
char *envstr
, ZCONST
char *envstr2
));
1880 void mksargs
OF((int *argcp
, char ***argvp
)); /* envargs.c */
1882 int match
OF((ZCONST
char *s
, ZCONST
char *p
,
1883 int ic
)); /* match.c */
1884 int iswild
OF((ZCONST
char *p
)); /* match.c */
1886 #ifdef DYNALLOC_CRCTAB
1887 void free_crc_table
OF((void)); /* crctab.c */
1890 ZCONST ulg near
*get_crc_table
OF((void)); /* funzip.c, crctab.c */
1891 ulg crc32
OF((ulg crc
, ZCONST uch
*buf
, extent len
));
1892 #endif /* !USE_ZLIB */ /* assembler source or crc32.c */
1894 int dateformat
OF((void)); /* currently, only msdos.c */
1896 void version
OF((__GPRO
)); /* local */
1898 int mapattr
OF((__GPRO
)); /* local */
1899 int mapname
OF((__GPRO__
int renamed
)); /* local */
1900 int checkdir
OF((__GPRO__
char *pathcomp
, int flag
)); /* local */
1901 char *do_wild
OF((__GPRO__
char *wildzipfn
)); /* local */
1902 char *GetLoadPath
OF((__GPRO
)); /* local */
1903 #if (defined(MORE) && (defined(UNIX) || defined(VMS) || defined(__BEOS__)))
1904 int screenlines
OF((void)); /* local */
1906 #ifndef MTS /* macro in MTS */
1907 void close_outfile
OF((__GPRO
)); /* local */
1909 #ifdef SET_DIR_ATTRIB
1910 int set_direc_attribs
OF((__GPRO__ dirtime
*d
)); /* local */
1914 int stamp_file
OF((__GPRO__
1915 ZCONST
char *fname
, time_t modtime
)); /* local */
1917 int stamp_file
OF((ZCONST
char *fname
, time_t modtime
)); /* local */
1920 #ifdef SYSTEM_SPECIFIC_CTOR
1921 void SYSTEM_SPECIFIC_CTOR
OF((__GPRO
)); /* local */
1933 # define MAX(a,b) ((a) > (b) ? (a) : (b))
1936 # define MIN(a,b) ((a) < (b) ? (a) : (b))
1940 # define Trace(x) fprintf x
1946 # define TTrace(x) fprintf x
1951 #ifdef NO_DEBUG_IN_MACROS
1954 # define MTrace(x) Trace(x)
1957 #if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
1958 # define ToLower(x) ((char)(isupper((int)x)? tolower((int)x) : x))
1960 # define ToLower tolower /* assumed "smart"; used in match() */
1963 #ifdef USE_STRM_INPUT
1964 /* ``Replace'' the unbuffered UNIX style I/O function with similar
1965 * standard C functions from <stdio.h>.
1967 # define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
1968 # define lseek(fd,o,w) fseek((FILE *)(fd),(o),(w))
1969 # define close(fd) fclose((FILE *)(fd))
1970 #endif /* USE_STRM_INPUT */
1972 /* The return value of the Info() "macro function" is never checked in
1973 * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
1974 * Info() definition for "FUNZIP" would have to be corrected:
1975 * #define Info(buf,flag,sprf_arg) \
1976 * (fprintf((flag)&1? stderr : stdout, \
1977 * (char *)(sprintf sprf_arg, (buf))) == EOF)
1979 #ifndef Info /* may already have been defined for redirection */
1981 # define Info(buf,flag,sprf_arg) \
1982 fprintf((flag)&1? stderr : stdout, (char *)(sprintf sprf_arg, (buf)))
1984 # ifdef INT_SPRINTF /* optimized version for "int sprintf()" flavour */
1985 # define Info(buf,flag,sprf_arg) \
1986 (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
1987 # else /* generic version, does not use sprintf() return value */
1988 # define Info(buf,flag,sprf_arg) \
1989 (*G.message)((zvoid *)&G, (uch *)(buf), \
1990 (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
1996 #define Info(buf,flag,sprf_arg) (0)
1998 /* The following macros wrappers around the fnfilter function are used many
1999 * times to prepare archive entry names or name components for displaying
2000 * listings and (warning/error) messages. They use sections in the upper half
2001 * of 'slide' as buffer, since their output is normally fed through the
2002 * Info() macro with 'slide' (the start of this area) as message buffer.
2004 #define FnFilter1(fname) fnfilter((fname), slide + (WSIZE>>1))
2005 #define FnFilter2(fname) fnfilter((fname), slide + ((WSIZE>>1) + (WSIZE>>2)))
2007 #ifndef FUNZIP /* used only in inflate.c */
2008 # define MESSAGE(str,len,flag) (*G.message)((zvoid *)&G,(str),(len),(flag))
2011 #if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
2012 # define CRCVAL_INITIAL crc32(0L, NULL, 0)
2014 # define CRCVAL_INITIAL 0L
2017 #ifndef TEST_NTSD /* "NTSD valid?" checking function */
2018 # define TEST_NTSD NULL /* ... is not available */
2022 * Seek to the block boundary of the block which includes abs_offset,
2023 * then read block into input buffer and set pointers appropriately.
2024 * If block is already in the buffer, just set the pointers. This macro
2025 * is used by uz_end_central (process.c), zi_end_central (zipinfo.c) and
2026 * do_string (fileio.c). A slightly modified version is embedded within
2027 * extract_or_test_files (extract.c). readbyte() and readbuf() (fileio.c)
2028 * are compatible. NOTE THAT abs_offset is intended to be the "proper off-
2029 * set" (i.e., if there were no extra bytes prepended); cur_zipfile_bufstart
2030 * contains the corrected offset.
2032 * Since ZLSEEK is never used during decompression, it is safe to use the
2033 * slide[] buffer for the error message.
2035 * The awkward "%cbs_offset" construct is provided for the obnoxious Solaris
2036 * compiler, which wants to do macro substitution inside strings.
2040 # ifdef USE_STRM_INPUT
2041 # define _ZLS_RELOAD(abs_offset) {\
2042 MTrace((stderr, "ZLSEEK: %cbs_offset = %ld, G.extra_bytes = %ld\n",\
2043 'a', (abs_offset), G.extra_bytes));\
2044 fseek(G.zipfd,(LONGINT)bufstart,SEEK_SET);\
2045 G.cur_zipfile_bufstart = ftell(G.zipfd);\
2047 " request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",\
2048 request, ((abs_offset)+G.extra_bytes), inbuf_offset));\
2049 MTrace((stderr, " bufstart = %ld, cur_zipfile_bufstart = %ld\n",\
2050 bufstart, G.cur_zipfile_bufstart));\
2051 if ((G.incnt = fread((char *)G.inbuf,1,INBUFSIZ,G.zipfd)) <= 0)\
2053 G.inptr = G.inbuf + (int)inbuf_offset;\
2054 G.incnt -= (int)inbuf_offset;\
2056 # else /* !USE_STRM_INPUT */
2057 # define _ZLS_RELOAD(abs_offset) {\
2058 MTrace((stderr, "ZLSEEK: %cbs_offset = %ld, G.extra_bytes = %ld\n",\
2059 'a', (abs_offset), G.extra_bytes));\
2060 G.cur_zipfile_bufstart = lseek(G.zipfd,(LONGINT)bufstart,SEEK_SET);\
2062 " request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",\
2063 request, ((abs_offset)+G.extra_bytes), inbuf_offset));\
2064 MTrace((stderr, " bufstart = %ld, cur_zipfile_bufstart = %ld\n",\
2065 bufstart, G.cur_zipfile_bufstart));\
2066 if ((G.incnt = read(G.zipfd,(char *)G.inbuf,INBUFSIZ)) <= 0)\
2068 G.inptr = G.inbuf + (int)inbuf_offset;\
2069 G.incnt -= (int)inbuf_offset;\
2071 # endif /* ?USE_STRM_INPUT */
2073 # define ZLSEEK(abs_offset) {\
2074 LONGINT request = (abs_offset) + G.extra_bytes;\
2075 LONGINT inbuf_offset = request % INBUFSIZ;\
2076 LONGINT bufstart = request - inbuf_offset;\
2079 Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),\
2080 G.zipfn, LoadFarString(ReportMsg)));\
2082 } else if (bufstart != G.cur_zipfile_bufstart)\
2083 _ZLS_RELOAD(abs_offset)\
2085 G.incnt += (G.inptr-G.inbuf) - (int)inbuf_offset;\
2086 G.inptr = G.inbuf + (int)inbuf_offset;\
2089 #endif /* !ZLSEEK */
2091 #define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
2092 {error_in_archive=error; if(error>1) return error;}
2095 * Skip a variable-length field, and report any errors. Used in zipinfo.c
2096 * and unzip.c in several functions.
2098 * macro SKIP_(length)
2101 * if (length && ((error = do_string(length, SKIP)) != 0)) {
2102 * error_in_archive = error; /-* might be warning *-/
2103 * if (error > 1) /-* fatal *-/
2112 # define FLUSH(w) flush(__G__ (ulg)(w))
2113 # define NEXTBYTE getc(G.in) /* redefined in crypt.h if full version */
2115 # define FLUSH(w) if (G.mem_mode) memflush(__G__ redirSlide,(ulg)(w)); \
2116 else flush(__G__ redirSlide,(ulg)(w),0)
2117 # define NEXTBYTE (--G.incnt >= 0 ? (int)(*G.inptr++) : readbyte(__G))
2121 #define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
2122 while (G.bits_left<=8*(int)(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
2123 G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
2124 zdest=(shrint)((ush)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
2125 G.bits_left-=nbits;}
2128 * macro READBITS(nbits,zdest) * only used by unreduce and unshrink *
2130 * if (nbits > G.bits_left) { * fill G.bitbuf, 8*sizeof(ulg) bits *
2134 * while (G.bits_left <= 8*(int)(sizeof(G.bitbuf)-1) &&
2135 * (temp = NEXTBYTE) != EOF) {
2136 * G.bitbuf |= (ulg)temp << G.bits_left;
2141 * zdest = (shrint)((ush)G.bitbuf & mask_bits[nbits]);
2142 * G.bitbuf >>= nbits;
2143 * G.bits_left -= nbits;
2149 /* GRR: should change name to STRLOWER and use StringLower if possible */
2152 * Copy the zero-terminated string in str1 into str2, converting any
2153 * uppercase letters to lowercase as we go. str2 gets zero-terminated
2154 * as well, of course. str1 and str2 may be the same character array.
2157 # define TOLOWER(str1, str2) \
2159 char *p=(str1), *q=(str2); \
2161 while ((c = *p++) != '\0') { \
2168 *q++ = isupper(c) ? tolower(c) : c; \
2173 # define TOLOWER(str1, str2) \
2179 *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
2184 * NOTES: This macro makes no assumptions about the characteristics of
2185 * the tolower() function or macro (beyond its existence), nor does it
2186 * make assumptions about the structure of the character set (i.e., it
2187 * should work on EBCDIC machines, too). The fact that either or both
2188 * of isupper() and tolower() may be macros has been taken into account;
2189 * watch out for "side effects" (in the C sense) when modifying this
2194 # define foreign(c) (c)
2198 # define native(c) (c)
2199 # define A_TO_N(str1)
2202 # define NATIVE "native chars"
2204 # define A_TO_N(str1) {register uch *p;\
2205 for (p=(uch *)(str1); *p; p++) *p=native(*p);}
2208 * Translate the zero-terminated string in str1 from ASCII to the native
2209 * character set. The translation is performed in-place and uses the
2210 * "native" macro to translate each character.
2212 * NOTE: Using the "native" macro means that is it the only part of unzip
2213 * which knows which translation table (if any) is actually in use to
2214 * produce the native character set. This makes adding new character set
2215 * translation tables easy, insofar as all that is needed is an appropriate
2216 * "native" macro definition and the translation table itself. Currently,
2217 * the only non-ASCII native character set implemented is EBCDIC, but this
2218 * may not always be so.
2222 /* default setup for internal codepage: assume ISO 8859-1 compatibility!! */
2223 #if (!defined(NATIVE) && !defined(CRTL_CP_IS_ISO) && !defined(CRTL_CP_IS_OEM))
2224 # define CRTL_CP_IS_ISO
2228 /* Translate "extended ASCII" chars (OEM coding for DOS and OS/2; else
2229 * ISO-8859-1 [ISO Latin 1, Win Ansi,...]) into the internal "native"
2230 * code page. As with A_TO_N(), conversion is done in place.
2233 # ifdef CRTL_CP_IS_OEM
2234 # ifndef IZ_ISO2OEM_ARRAY
2235 # define IZ_ISO2OEM_ARRAY
2237 # define _ISO_INTERN(str1) {register uch *p;\
2238 for (p=(uch *)(str1); *p; p++)\
2239 *p = native((*p & 0x80) ? iso2oem[*p & 0x7f] : *p);}
2241 # define _ISO_INTERN(str1) A_TO_N(str1)
2246 # ifdef CRTL_CP_IS_OEM
2247 # define _OEM_INTERN(str1) A_TO_N(str1)
2249 # ifndef IZ_OEM2ISO_ARRAY
2250 # define IZ_OEM2ISO_ARRAY
2252 # define _OEM_INTERN(str1) {register uch *p;\
2253 for (p=(uch *)(str1); *p; p++)\
2254 *p = native((*p & 0x80) ? oem2iso[*p & 0x7f] : *p);}
2259 # ifdef CRTL_CP_IS_ISO
2260 # define STR_TO_ISO strcpy
2262 # define STR_TO_ISO str2iso
2263 # define NEED_STR2ISO
2268 # ifdef CRTL_CP_IS_OEM
2269 # define STR_TO_OEM strcpy
2271 # define STR_TO_OEM str2oem
2272 # define NEED_STR2OEM
2276 #if (!defined(INTERN_TO_ISO) && !defined(ASCII2ISO))
2277 # ifdef CRTL_CP_IS_OEM
2278 /* know: "ASCII" is "OEM" */
2279 # define ASCII2ISO(c) (((c) & 0x80) ? oem2iso[(c) & 0x7f] : (c))
2280 # if (defined(NEED_STR2ISO) && !defined(CRYP_USES_OEM2ISO))
2281 # define CRYP_USES_OEM2ISO
2284 /* assume: "ASCII" is "ISO-ANSI" */
2285 # define ASCII2ISO(c) (c)
2289 #if (!defined(INTERN_TO_OEM) && !defined(ASCII2OEM))
2290 # ifdef CRTL_CP_IS_OEM
2291 /* know: "ASCII" is "OEM" */
2292 # define ASCII2OEM(c) (c)
2294 /* assume: "ASCII" is "ISO-ANSI" */
2295 # define ASCII2OEM(c) (((c) & 0x80) ? iso2oem[(c) & 0x7f] : (c))
2296 # if (defined(NEED_STR2OEM) && !defined(CRYP_USES_ISO2OEM))
2297 # define CRYP_USES_ISO2OEM
2302 /* codepage conversion setup for testp() in crypt.c */
2303 #ifdef CRTL_CP_IS_ISO
2305 # define STR_TO_CP2 STR_TO_OEM
2308 # ifdef CRTL_CP_IS_OEM
2310 # define STR_TO_CP2 STR_TO_ISO
2312 # else /* native internal CP is neither ISO nor OEM */
2314 # define STR_TO_CP1 STR_TO_ISO
2317 # define STR_TO_CP2 STR_TO_OEM
2323 /* Convert filename (and file comment string) into "internal" charset.
2324 * This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
2325 * codepage when made on
2326 * -> DOS (this includes 16-bit Windows 3.1) (FS_FAT_)
2327 * -> OS/2 (FS_HPFS_)
2328 * -> Win95/WinNT with Nico Mak's WinZip (FS_NTFS_ && hostver == "5.0")
2330 * All other ports are assumed to code zip entry filenames in ISO 8859-1.
2332 #ifndef Ext_ASCII_TO_Native
2333 # define Ext_ASCII_TO_Native(string, hostnum, hostver) \
2334 if ((hostnum) == FS_FAT_ || (hostnum) == FS_HPFS_ || \
2335 ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
2336 _OEM_INTERN((string)); \
2338 _ISO_INTERN((string)); \
2344 /**********************/
2345 /* Global constants */
2346 /**********************/
2348 extern ZCONST ush near mask_bits
[];
2349 extern ZCONST
char *fnames
[2];
2352 extern ZCONST uch ebcdic
[];
2354 #ifdef IZ_ISO2OEM_ARRAY
2355 extern ZCONST uch Far iso2oem
[];
2357 #ifdef IZ_OEM2ISO_ARRAY
2358 extern ZCONST uch Far oem2iso
[];
2361 extern ZCONST
char Far VersionDate
[];
2362 extern ZCONST
char Far CentSigMsg
[];
2363 extern ZCONST
char Far EndSigMsg
[];
2364 extern ZCONST
char Far SeekMsg
[];
2365 extern ZCONST
char Far FilenameNotMatched
[];
2366 extern ZCONST
char Far ExclFilenameNotMatched
[];
2367 extern ZCONST
char Far ReportMsg
[];
2370 extern ZCONST
char Far CompiledWith
[];
2375 /***********************************/
2376 /* Global (shared?) RTL variables */
2377 /***********************************/
2379 #ifdef DECLARE_ERRNO
2384 #endif /* !__unzpriv_h */