home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip532.zip / unzpriv.h < prev    next >
C/C++ Source or Header  |  1997-10-21  |  83KB  |  2,354 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzpriv.h
  4.  
  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.
  9.  
  10.   ---------------------------------------------------------------------------*/
  11.  
  12.  
  13.  
  14. #ifndef __unzpriv_h   /* prevent multiple inclusions */
  15. #define __unzpriv_h
  16.  
  17. /* First thing: Signal all following code that we compile UnZip utilities! */
  18. #ifndef UNZIP
  19. #  define UNZIP
  20. #endif
  21.  
  22. /* GRR 960204:  MORE defined here in preparation for removal altogether */
  23. #ifndef MORE
  24. #  define MORE
  25. #endif
  26.  
  27. /* fUnZip should never need to be reentrant */
  28. #ifdef FUNZIP
  29. #  ifdef REENTRANT
  30. #    undef REENTRANT
  31. #  endif
  32. #  ifdef DLL
  33. #    undef DLL
  34. #  endif
  35. #endif
  36.  
  37. #if (defined(DLL) && !defined(REENTRANT))
  38. #  define REENTRANT
  39. #endif
  40.  
  41. #if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
  42. #  define DYNAMIC_CRC_TABLE
  43. #endif
  44.  
  45. #if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
  46. #  ifndef DYNALLOC_CRCTAB
  47. #    define DYNALLOC_CRCTAB
  48. #  endif
  49. #endif
  50.  
  51. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  52. #  include <stdio.h>
  53. #endif
  54. #include <ctype.h>       /* skip for VMS, to use tolower() function? */
  55. #include <errno.h>       /* used in mapname() */
  56. #ifdef USE_STRINGS_H
  57. #  include <strings.h>   /* strcpy, strcmp, memcpy, index/rindex, etc. */
  58. #else
  59. #  include <string.h>    /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
  60. #endif
  61. #if (defined(MODERN) && !defined(NO_LIMITS_H))
  62. #  include <limits.h>    /* GRR:  EXPERIMENTAL!  (can be deleted) */
  63. #endif
  64.  
  65. /* this include must be down here for SysV.4, for some reason... */
  66. #include <signal.h>      /* used in unzip.c, fileio.c */
  67.  
  68.  
  69. /*---------------------------------------------------------------------------
  70.     API (DLL) section:
  71.   ---------------------------------------------------------------------------*/
  72.  
  73. #ifdef DLL
  74. #  define MAIN   UZ_EXP UzpMain   /* was UzpUnzip */
  75. #  ifdef OS2DLL
  76. #    undef Info
  77. #    define REDIRECTC(c)             varputchar(__G__ c)
  78. #    define REDIRECTPRINT(buf,size)  varmessage(__G__ buf, size)
  79. #    define FINISH_REDIRECT()        finish_REXX_redirect(__G)
  80. #  else
  81. #    define REDIRECTC(c)
  82. #    define REDIRECTPRINT(buf,size)  0
  83. #    ifdef WINDLL
  84. #      define FINISH_REDIRECT()      FLUSH(G.outcnt)
  85. #    else
  86. #      define FINISH_REDIRECT()
  87. #    endif
  88. #  endif
  89. #endif
  90.  
  91. /*---------------------------------------------------------------------------
  92.     Acorn RISCOS section:
  93.   ---------------------------------------------------------------------------*/
  94.  
  95. #ifdef RISCOS
  96. #  include "acorn/riscos.h"
  97. #endif
  98.  
  99. /*---------------------------------------------------------------------------
  100.     Amiga section:
  101.   ---------------------------------------------------------------------------*/
  102.  
  103. #ifdef AMIGA
  104. #  include "amiga/amiga.h"
  105. #endif
  106.  
  107. /*---------------------------------------------------------------------------
  108.     AOS/VS section (somewhat similar to Unix, apparently):
  109.   ---------------------------------------------------------------------------*/
  110.  
  111. #ifdef AOS_VS
  112. #  ifdef FILEIO_C
  113. #    include "aosvs/aosvs.h"
  114. #  endif
  115. #endif
  116.  
  117. /*---------------------------------------------------------------------------
  118.     Atari ST section:
  119.   ---------------------------------------------------------------------------*/
  120.  
  121. #ifdef ATARI
  122. #  include <time.h>
  123. #  include <stat.h>
  124. #  include <fcntl.h>
  125. #  include <limits.h>
  126. #  define SYMLINKS
  127. #  define EXE_EXTENSION  ".tos"
  128. #  ifndef DATE_FORMAT
  129. #    define DATE_FORMAT  DF_DMY
  130. #  endif
  131. #  define DIR_END        '/'
  132. #  define INT_SPRINTF
  133. #  define timezone      _timezone
  134. #  define lenEOL        2
  135. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  136. #  undef SHORT_NAMES
  137. #  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
  138. #    define TIMESTAMP
  139. #  endif
  140. #endif
  141.  
  142. /*---------------------------------------------------------------------------
  143.     BeOS section:
  144.   ---------------------------------------------------------------------------*/
  145.  
  146. #ifdef __BEOS__
  147. #  include <sys/types.h>          /* [cjh]:  This is pretty much a generic  */
  148. #  include <sys/stat.h>           /* POSIX 1003.1 system; see beos/ for     */
  149. #  include <fcntl.h>              /* extra code to deal with our extra file */
  150. #  include <sys/param.h>          /* attributes. */
  151. #  include <unistd.h>
  152. #  include <utime.h>
  153. #  define DIRENT
  154. #  include <time.h>
  155. #  ifndef DATE_FORMAT
  156. #    define DATE_FORMAT DF_MDY  /* GRR:  customize with locale.h somehow? */
  157. #  endif
  158. #  define lenEOL        1
  159. #  define PutNativeEOL  *q++ = native(LF);
  160. #  define SCREENLINES   screenlines()
  161. #  define USE_EF_UT_TIME
  162. #  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
  163. #    define TIMESTAMP
  164. #  endif
  165. #  define NO_GMTIME               /* maybe DR10 will have timezones... */
  166. #  define INT_SPRINTF
  167. #  define SYMLINKS
  168. #  ifdef __GNUC__
  169.      /* Not only does it have screwed up unistd.h and stdlib.h (see unzip.h
  170.       * for that fix: #define __USE_FIXED_PROTOTYPES__), GeekGadgets' unistd.h
  171.       * leaves out at least two functions supported by BeOS: */
  172.      extern int ioctl(int fd, int op, ...);
  173.      extern int symlink(const char *from, const char *to);
  174. #  endif
  175. #endif
  176.  
  177. /*---------------------------------------------------------------------------
  178.     Human68k/X68000 section:
  179.   ---------------------------------------------------------------------------*/
  180.  
  181. #ifdef __human68k__    /* DO NOT DEFINE DOS_OS2 HERE!  If Human68k is so much */
  182. #  include <time.h>    /*  like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
  183. #  include <fcntl.h>
  184. #  include <io.h>
  185. #  include <conio.h>
  186. #  include <jctype.h>
  187. #  include <sys/stat.h>
  188. #  ifndef DATE_FORMAT
  189. #    define DATE_FORMAT DF_YMD   /* Japanese standard */
  190. #  endif
  191.       /* GRR:  these EOL macros are guesses */
  192. #  define lenEOL        2
  193. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  194. #  define EXE_EXTENSION ".exe"   /* just a guess... */
  195. #endif
  196.  
  197. /*---------------------------------------------------------------------------
  198.     Mac section:
  199.   ---------------------------------------------------------------------------*/
  200.  
  201. #if defined(__MWERKS__) && defined(macintosh)
  202. #  include <OSUtils.h>
  203.  
  204. #  define AddResMenu    AppendResMenu
  205. #  define Date2Secs     DateToSeconds
  206. #  define DisposDialog  DisposeDialog
  207. #  define GetDItem      GetDialogItem
  208. #  define GetItem       GetMenuItemText
  209. #  define GetIText      GetDialogItemText
  210. #  define GetMHandle    GetMenuHandle
  211.  
  212.    typedef unsigned long mode_t;
  213. #  define _STAT
  214.  
  215. #  define CREATOR  'R*ch'
  216. #  define MAIN     _dummy_main
  217. #endif
  218.  
  219. #ifdef THINK_C
  220. #  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  221. #    define __STDC__ 1        /*   make sure it's defined: it needs it */
  222. #  else
  223. #    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  224. #      undef __STDC__         /*   it needs to be 1 or required header */
  225. #      define __STDC__ 1      /*   files are not properly included. */
  226. #    endif /* !__STDC__ */
  227. #  endif
  228. #  define IOCompletionUPP   ProcPtr
  229. #  define CREATOR  'KAHL'
  230. #  define MAIN     _dummy_main
  231. #endif /* THINK_C */
  232.  
  233. #ifdef MPW
  234. #  include <Errors.h>
  235. #  include <Files.h>
  236. #  include <Memory.h>
  237. #  include <Quickdraw.h>
  238. #  include <ToolUtils.h>
  239. #  ifdef fileno
  240. #    undef fileno
  241. #  endif
  242. #  ifdef MCH_MACINTOSH
  243. #    define CREATOR     'Manx'
  244. #  else
  245. #    define CREATOR     'MPS '
  246. #  endif
  247. #endif /* MPW */
  248.  
  249. #ifdef MACOS
  250. #  include <fcntl.h>            /* O_BINARY for open() w/o CR/LF translation */
  251. #  define fileno(x)     ((x) == stdout ? 1 : ((x) == stderr ? 2 : (short)(x)))
  252. #  define open(x,y)     macopen((x), (y), G.gnVRefNum, G.glDirID)
  253. #  define fopen(x,y)    macfopen((x), (y), G.gnVRefNum, G.glDirID)
  254. #  define close         macclose
  255. #  define fclose(x)     macclose(fileno((x)))
  256. #  define read          macread
  257. #  define write         macwrite
  258. #  define lseek         maclseek
  259. #  define creat(x,y) \
  260.                maccreat((x), G.gnVRefNum, G.glDirID, G.gostCreator, G.gostType)
  261. #  define stat(x,y)     macstat((x), (y), G.gnVRefNum, G.glDirID)
  262. #  define dup
  263. #  ifndef MCH_MACINTOSH
  264. #    define NO_STRNICMP
  265. #  endif
  266. #  define DIR_END ':'
  267. #  ifndef DATE_FORMAT
  268. #    define DATE_FORMAT DF_MDY
  269. #  endif
  270. #  define lenEOL        1
  271. #  define PutNativeEOL  *q++ = native(CR);
  272. #  define MALLOC_WORK
  273. #  define INT_SPRINTF
  274. #  define USE_EF_UT_TIME
  275. #  define NO_GMTIME
  276. #  undef DYNAMIC_CRC_TABLE
  277.   /*
  278.    * ARGH.  Mac times are based on 1904 Jan 1 00:00, not 1970 Jan 1 00:00.
  279.    *  So we have to diddle time_t's appropriately:  add or subtract 66 years'
  280.    *  worth of seconds == number of days times 86400 == (66*365 regular days +
  281.    *  17 leap days) * 86400 == (24090 + 17) * 86400 == 2082844800 seconds.  We
  282.    *  hope time_t is an unsigned long (ulg) on the Macintosh...
  283.    */
  284. #  define TIMET_TO_NATIVE(x)  (x) += (ulg)2082844800L;
  285. #  define NATIVE_TO_TIMET(x)  (x) -= (ulg)2082844800L;
  286.  
  287. #  ifndef MPW
  288. #    define fgets       wfgets
  289. #    define fflush(f)
  290. #    define fprintf     wfprintf
  291. #    define fputs(s,f)  wfprintf((f), "%s", (s))
  292. #    define isatty(f)   (((f) >= 0) || ((f) <= 2))
  293. #    define printf      wprintf
  294. #    ifdef putc
  295. #      undef putc
  296. #    endif
  297. #    define putc(c,f)   wfprintf((f), "%c", (c))
  298. #    define getenv      macgetenv
  299. #  endif
  300.  
  301. #  ifndef isascii
  302. #    define isascii(c)  ((unsigned char)(c) <= 0x3F)
  303. #  endif
  304.  
  305. #  include "macstat.h"
  306. #  include "macdir.h"
  307.  
  308. #  ifdef CR
  309. #    undef  CR
  310. #  endif
  311.  
  312.    typedef struct _ZipExtraHdr {
  313.        ush header;               /*    2 bytes */
  314.        ush data;                 /*    2 bytes */
  315.    } ZIP_EXTRA_HEADER;
  316.  
  317.    typedef struct _MacInfoMin {
  318.        ush header;               /*    2 bytes */
  319.        ush data;                 /*    2 bytes */
  320.        ulg signature;            /*    4 bytes */
  321.        FInfo finfo;              /*   16 bytes */
  322.        ulg lCrDat;               /*    4 bytes */
  323.        ulg lMdDat;               /*    4 bytes */
  324.        ulg flags ;               /*    4 bytes */
  325.        ulg lDirID;               /*    4 bytes */
  326.                                  /*------------*/
  327.    } MACINFOMIN;                 /* = 40 bytes for size of data */
  328.  
  329.    typedef struct _MacInfo {
  330.        ush header;               /*    2 bytes */
  331.        ush data;                 /*    2 bytes */
  332.        ulg signature;            /*    4 bytes */
  333.        FInfo finfo;              /*   16 bytes */
  334.        ulg lCrDat;               /*    4 bytes */
  335.        ulg lMdDat;               /*    4 bytes */
  336.        ulg flags ;               /*    4 bytes */
  337.        ulg lDirID;               /*    4 bytes */
  338.        char rguchVolName[28];    /*   28 bytes */
  339.                                  /*------------*/
  340.    } MACINFO;                    /* = 68 bytes for size of data */
  341.  
  342. #endif /* MACOS */
  343.  
  344. /*---------------------------------------------------------------------------
  345.     MS-DOS, OS/2, FLEXOS section:
  346.   ---------------------------------------------------------------------------*/
  347.  
  348. #ifdef WINDLL
  349. #  define MSWIN
  350. #  ifdef MORE
  351. #    undef MORE
  352. #  endif
  353. #  ifdef OS2_EAS
  354. #    undef OS2_EAS
  355. #  endif
  356. #endif
  357.  
  358. #if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
  359. #  ifndef MSC
  360. #    define MSC               /* This should work for older MSC, too!  */
  361. #  endif
  362. #endif
  363.  
  364. #if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
  365. #  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  366. #  include <sys/stat.h>
  367. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  368. #  include <time.h>           /* localtime() */
  369. #  include <fcntl.h>          /* O_BINARY for open() w/o CR/LF translation */
  370.  
  371. #  ifdef OS2                  /* defined for all OS/2 compilers */
  372. #    include "os2/os2cfg.h"
  373. #  else
  374. #    ifdef FLEXOS
  375. #      include "flexos/flxcfg.h"
  376. #    else
  377. #      include "msdos/doscfg.h"
  378. #    endif
  379. #  endif
  380.  
  381. #  if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
  382.     /*
  383.      * ARGH.  MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
  384.      *  1970 Jan 1 00:00.  So we have to diddle time_t's appropriately:  add or
  385.      *  subtract 70 years' worth of seconds; i.e., number of days times 86400;
  386.      *  i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
  387.      *  (25550 + 17 + 1) * 86400 == 2209075200 seconds.  We know time_t is an
  388.      *  unsigned long (ulg) on the only system with this bug.
  389.      */
  390. #    define TIMET_TO_NATIVE(x)  (x) += (ulg)2209075200L;
  391. #    define NATIVE_TO_TIMET(x)  (x) -= (ulg)2209075200L;
  392. #  endif
  393. #  if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
  394. #    define timezone      _timezone
  395. #  endif
  396. #  if (defined(__GO32__) || defined(FLEXOS))
  397. #    define DIR_END       '/'
  398. #  else
  399. #    define DIR_END       '\\'
  400. #  endif
  401. #  ifndef WIN32
  402. #    ifdef DATE_FORMAT
  403. #      undef DATE_FORMAT
  404. #    endif
  405. #    define DATE_FORMAT   dateformat()
  406. #  endif
  407. #  define lenEOL          2
  408. #  define PutNativeEOL    {*q++ = native(CR); *q++ = native(LF);}
  409. #  define USE_EF_UT_TIME
  410. #endif /* MSDOS || OS2 || FLEXOS */
  411.  
  412. /*---------------------------------------------------------------------------
  413.     MTS section (piggybacks UNIX, I think):
  414.   ---------------------------------------------------------------------------*/
  415.  
  416. #ifdef MTS
  417. #  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  418. #  include <sys/stat.h>
  419. #  include <sys/file.h>       /* MTS uses this instead of fcntl.h */
  420. #  include <timeb.h>
  421. #  include <time.h>
  422. #  include <unix.h>           /* some important non-ANSI routines */
  423. #  define mkdir(s,n) (-1)     /* no "make directory" capability */
  424. #  define EBCDIC              /* set EBCDIC conversion on */
  425. #  define NO_STRNICMP         /* unzip's is as good the one in MTS */
  426. #  define USE_FWRITE
  427. #  define close_outfile()  fclose(G.outfile)   /* can't set time on files */
  428. #  define umask(n)            /* don't have umask() on MTS */
  429. #  define FOPWT         "w"   /* open file for writing in TEXT mode */
  430. #  ifndef DATE_FORMAT
  431. #    define DATE_FORMAT DF_MDY
  432. #  endif
  433. #  define lenEOL        1
  434. #  define PutNativeEOL  *q++ = native(LF);
  435. #endif /* MTS */
  436.  
  437.  /*---------------------------------------------------------------------------
  438.     QDOS section
  439.   ---------------------------------------------------------------------------*/
  440.  
  441. #ifdef QDOS
  442. #  define DIRENT
  443. #  include <fcntl.h>
  444. #  include <unistd.h>
  445. #  include <sys/stat.h>
  446. #  include <time.h>
  447. #  include "qdos/izqdos.h"
  448. #  ifndef DATE_FORMAT
  449. #    define DATE_FORMAT DF_MDY
  450. #  endif
  451. #  define lenEOL        1
  452. #  define PutNativeEOL  *q++ = native(LF);
  453. #  define DIR_END       '_'
  454. #  define RETURN        QReturn
  455. #  undef PATH_MAX
  456. #  define PATH_MAX      36
  457. #  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
  458. #    define TIMESTAMP
  459. #  endif
  460. #endif
  461.  
  462. /*---------------------------------------------------------------------------
  463.     Tandem NSK section:
  464.   ---------------------------------------------------------------------------*/
  465.  
  466. #ifdef TANDEM
  467. #  include "tandem.h"
  468. #  include <fcntl.h>
  469.    /* use a single LF delimiter so that writes to 101 text files work */
  470. #  define PutNativeEOL  *q++ = native(LF);
  471. #  define lenEOL        1
  472. #endif
  473.  
  474. /*---------------------------------------------------------------------------
  475.     TOPS-20 section:
  476.   ---------------------------------------------------------------------------*/
  477.  
  478. #ifdef TOPS20
  479. #  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
  480. #  include <sys/stat.h>
  481. #  include <sys/param.h>
  482. #  include <sys/time.h>
  483. #  include <sys/timeb.h>
  484. #  include <sys/file.h>
  485. #  include <timex.h>
  486. #  include <monsym.h>           /* get amazing monsym() macro */
  487.    extern int open(), close(), read();
  488.    extern int stat(), unlink(), jsys(), fcntl();
  489.    extern long lseek(), dup(), creat();
  490. #  define strchr    index       /* GRR: necessary? */
  491. #  define strrchr   rindex
  492. #  define REALLY_SHORT_SYMS
  493. #  define NO_MKDIR
  494. #  define DIR_BEG       '<'
  495. #  define DIR_END       '>'
  496. #  define DIR_EXT       ".directory"
  497. #  ifndef DATE_FORMAT
  498. #    define DATE_FORMAT DF_MDY
  499. #  endif
  500. #  define EXE_EXTENSION ".exe"  /* just a guess... */
  501. #endif /* TOPS20 */
  502.  
  503. /*---------------------------------------------------------------------------
  504.     Unix section:
  505.   ---------------------------------------------------------------------------*/
  506.  
  507. #ifdef UNIX
  508. #  include <sys/types.h>       /* off_t, time_t, dev_t, ... */
  509. #  include <sys/stat.h>
  510.  
  511. #  ifndef COHERENT
  512. #    include <fcntl.h>         /* O_BINARY for open() w/o CR/LF translation */
  513. #  else /* COHERENT */
  514. #    ifdef _I386
  515. #      include <fcntl.h>       /* Coherent 4.0.x, Mark Williams C */
  516. #    else
  517. #      include <sys/fcntl.h>   /* Coherent 3.10, Mark Williams C */
  518. #    endif
  519. #    define SHORT_SYMS
  520. #    ifndef __COHERENT__       /* Coherent 4.2 has tzset() */
  521. #      define tzset  settz
  522. #    endif
  523. #  endif /* ?COHERENT */
  524.  
  525. #  ifndef NO_PARAM_H
  526. #    ifdef NGROUPS_MAX
  527. #      undef NGROUPS_MAX       /* SCO bug:  defined again in <sys/param.h> */
  528. #    endif
  529. #    ifdef BSD
  530. #      define TEMP_BSD         /* may be defined again in <sys/param.h> */
  531. #      undef BSD
  532. #    endif
  533. #    include <sys/param.h>     /* conflict with <sys/types.h>, some systems? */
  534. #    ifdef TEMP_BSD
  535. #      undef TEMP_BSD
  536. #      ifndef BSD
  537. #        define BSD
  538. #      endif
  539. #    endif
  540. #  endif /* !NO_PARAM_H */
  541.  
  542. #  ifdef __osf__
  543. #    define DIRENT
  544. #    ifdef BSD
  545. #      undef BSD
  546. #    endif
  547. #  endif /* __osf__ */
  548.  
  549. #  ifdef BSD
  550. #    include <sys/time.h>
  551. #    include <sys/timeb.h>
  552. #    ifdef _AIX
  553. #      include <time.h>
  554. #    endif
  555. #  else
  556. #    include <time.h>
  557.      struct tm *gmtime(), *localtime();
  558. #  endif
  559.  
  560. #  if (defined(BSD4_4) || (defined(SYSV) && defined(MODERN)))
  561. #    include <unistd.h>        /* this includes utime.h on SGIs */
  562. #    if (defined(BSD4_4) || defined(linux))
  563. #      include <utime.h>
  564. #      define GOT_UTIMBUF
  565. #    endif
  566. #  endif
  567.  
  568. #  if (defined(V7) || defined(pyr_bsd))
  569. #    define strchr   index
  570. #    define strrchr  rindex
  571. #  endif
  572. #  ifdef V7
  573. #    define O_RDONLY 0
  574. #    define O_WRONLY 1
  575. #    define O_RDWR   2
  576. #  endif
  577.  
  578. #  ifdef MINIX
  579. #    include <stdio.h>
  580. #  endif
  581. #  ifndef DATE_FORMAT
  582. #    define DATE_FORMAT DF_MDY    /* GRR:  customize with locale.h somehow? */
  583. #  endif
  584. #  define lenEOL        1
  585. #  define PutNativeEOL  *q++ = native(LF);
  586. #  define SCREENLINES   screenlines()
  587. #  define USE_EF_UT_TIME
  588. #  if (!defined(TIMESTAMP) && !defined(NOTIMESTAMP))   /* GRR 970513 */
  589. #    define TIMESTAMP
  590. #  endif
  591. #endif /* UNIX */
  592.  
  593. /*---------------------------------------------------------------------------
  594.     VM/CMS and MVS section:
  595.   ---------------------------------------------------------------------------*/
  596.  
  597. #ifdef CMS_MVS
  598. #  include "vmmvs.h"
  599. #  define CLOSE_INFILE()  close_infile(__G)
  600. #endif
  601.  
  602. /*---------------------------------------------------------------------------
  603.     VMS section:
  604.   ---------------------------------------------------------------------------*/
  605.  
  606. #ifdef VMS
  607. #  include <types.h>                    /* GRR:  experimenting... */
  608. #  include <stat.h>
  609. #  include <time.h>                     /* the usual non-BSD time functions */
  610. #  include <file.h>                     /* same things as fcntl.h has */
  611. #  include <unixio.h>
  612. #  include <rms.h>
  613. #  define _MAX_PATH (NAM$C_MAXRSS+1)    /* to define FILNAMSIZ below */
  614. #  ifdef RETURN_CODES  /* VMS interprets standard PK return codes incorrectly */
  615. #    define RETURN(ret) return_VMS(__G__ (ret))   /* verbose version */
  616. #    define EXIT(ret)   return_VMS(__G__ (ret))
  617. #  else
  618. #    define RETURN      return_VMS                /* quiet version */
  619. #    define EXIT        return_VMS
  620. #  endif
  621. #  ifdef VMSCLI
  622. #    define USAGE(ret)  VMSCLI_usage(__G__ (ret));
  623. #  endif
  624. #  define DIR_BEG       '['
  625. #  define DIR_END       ']'
  626. #  define DIR_EXT       ".dir"
  627. #  ifndef DATE_FORMAT
  628. #    define DATE_FORMAT DF_MDY
  629. #  endif
  630. #  define lenEOL        1
  631. #  define PutNativeEOL  *q++ = native(LF);
  632. #  define SCREENLINES   screenlines()
  633. #  if ((!defined(__VMS_VER)) || (__VMS_VER < 70000000))
  634. #    define NO_GMTIME           /* gmtime() of earlier VMS C RTLs is broken */
  635. #  else
  636. #    if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
  637. #      define USE_EF_UT_TIME
  638. #    endif
  639. #  endif
  640. #  if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
  641. #    define TIMESTAMP
  642. #  endif
  643. #endif /* VMS */
  644.  
  645. /*---------------------------------------------------------------------------
  646.     Win32 (Windows 95/NT) section:
  647.   ---------------------------------------------------------------------------*/
  648.  
  649. #if (defined(WIN32) && !defined(POCKET_UNZIP))
  650. #  include "win32/w32cfg.h"
  651. #endif
  652.  
  653.  
  654.  
  655.  
  656.  
  657. /*************/
  658. /*  Defines  */
  659. /*************/
  660.  
  661. #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  662. #define VMS_UNZIP_VERSION 42   /* if OS-needed-to-extract is VMS:  can do */
  663.  
  664. #if (defined(MSDOS) || defined(OS2))
  665. #  define DOS_OS2
  666. #endif
  667.  
  668. #if (defined(OS2) || defined(WIN32))
  669. #  define OS2_W32
  670. #endif
  671.  
  672. #if (defined(DOS_OS2) || defined(WIN32))
  673. #  define DOS_OS2_W32
  674. #  define DOS_W32_OS2          /* historical:  don't use */
  675. #endif
  676.  
  677. #if (defined(DOS_OS2_W32) || defined(__human68k__))
  678. #  define DOS_H68_OS2_W32
  679. #endif
  680.  
  681. #if (defined(DOS_OS2) || defined(FLEXOS))
  682. #  define DOS_FLX_OS2
  683. #endif
  684.  
  685. #if (defined(DOS_OS2_W32) || defined(FLEXOS))
  686. #  define DOS_FLX_OS2_W32
  687. #endif
  688.  
  689. #if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
  690. #  define DOS_FLX_H68_OS2_W32
  691. #endif
  692.  
  693. #if (defined(TOPS20) || defined(VMS))
  694. #  define T20_VMS
  695. #endif
  696.  
  697. #if (defined(MSDOS) || defined(T20_VMS))
  698. #  define DOS_T20_VMS
  699. #endif
  700.  
  701. /* clean up with a few defaults */
  702. #ifndef DIR_END
  703. #  define DIR_END       '/'     /* last char before program name or filename */
  704. #endif
  705. #ifndef DATE_FORMAT
  706. #  define DATE_FORMAT   DF_MDY  /* defaults to US convention */
  707. #endif
  708. #ifndef CLOSE_INFILE
  709. #  define CLOSE_INFILE()  close(G.zipfd)
  710. #endif
  711. #ifndef RETURN
  712. #  define RETURN        return  /* only used in main() */
  713. #endif
  714. #ifndef EXIT
  715. #  define EXIT          exit
  716. #endif
  717. #ifndef USAGE
  718. #  define USAGE(ret)    usage(__G__ (ret));   /* used in unzip.c, zipinfo.c */
  719. #endif
  720. #ifndef TIMET_TO_NATIVE         /* everybody but MSC 7.0 and Macintosh */
  721. #  define TIMET_TO_NATIVE(x)
  722. #  define NATIVE_TO_TIMET(x)
  723. #endif
  724.  
  725. #if (defined(DOS_FLX_OS2_W32) || defined(UNIX) || defined(RISCOS))
  726. #  ifndef HAVE_UNLINK
  727. #    define HAVE_UNLINK
  728. #  endif
  729. #endif
  730. #if (defined(AOS_VS) || defined(ATARI) || defined(__BEOS__)) /* GRR: others? */
  731. #  ifndef HAVE_UNLINK
  732. #    define HAVE_UNLINK
  733. #  endif
  734. #endif
  735.  
  736. /* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
  737.  
  738. #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
  739. #  if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
  740. #    define INT_SPRINTF      /* sprintf() returns int:  SysVish/Posix */
  741. #  endif
  742. #  if (defined(DOS_FLX_OS2_W32) || defined(VMS) || defined(AMIGA))
  743. #    define INT_SPRINTF      /* sprintf() returns int:  ANSI */
  744. #  endif
  745. #  if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
  746. #    if (defined(POSIX) || defined(__POSIX))
  747. #      define INT_SPRINTF    /* sprintf() returns int:  ANSI/Posix */
  748. #    endif
  749. #    ifdef __GNUC__
  750. #      define PCHAR_SPRINTF  /* undetermined actual return value */
  751. #    endif
  752. #  endif
  753. #  if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS))
  754. #    define INT_SPRINTF      /* sprintf() returns int:  ANSI/Posix */
  755. #  endif
  756. #  if defined(sun)
  757. #    define PCHAR_SPRINTF    /* sprintf() returns char *:  SunOS cc *and* gcc */
  758. #  endif
  759. #endif
  760.  
  761. /* defaults that we hope will take care of most machines in the future */
  762.  
  763. #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
  764. #  ifdef __STDC__
  765. #    define INT_SPRINTF      /* sprintf() returns int:  ANSI */
  766. #  endif
  767. #  ifndef INT_SPRINTF
  768. #    define PCHAR_SPRINTF    /* sprintf() returns char *:  BSDish */
  769. #  endif
  770. #endif
  771.  
  772. #define MSG_STDERR(f)  (f & 1)        /* bit 0:  0 = stdout, 1 = stderr */
  773. #define MSG_INFO(f)    ((f & 6) == 0) /* bits 1 and 2:  0 = info */
  774. #define MSG_WARN(f)    ((f & 6) == 2) /* bits 1 and 2:  1 = warning */
  775. #define MSG_ERROR(f)   ((f & 6) == 4) /* bits 1 and 2:  2 = error */
  776. #define MSG_FATAL(f)   ((f & 6) == 6) /* bits 1 and 2:  (3 = fatal error) */
  777. #define MSG_ZFN(f)     (f & 0x0008)   /* bit 3:  1 = print zipfile name */
  778. #define MSG_FN(f)      (f & 0x0010)   /* bit 4:  1 = print filename */
  779. #define MSG_LNEWLN(f)  (f & 0x0020)   /* bit 5:  1 = leading newline if !SOL */
  780. #define MSG_TNEWLN(f)  (f & 0x0040)   /* bit 6:  1 = trailing newline if !SOL */
  781. #define MSG_MNEWLN(f)  (f & 0x0080)   /* bit 7:  1 = trailing newline if MPW */
  782. /* the following are subject to change */
  783. #define MSG_NO_WGUI(f) (f & 0x0100)   /* bit 8:  1 = skip if Windows GUI */
  784. #define MSG_NO_AGUI(f) (f & 0x0200)   /* bit 9:  1 = skip if Acorn GUI */
  785. #define MSG_NO_DLL2(f) (f & 0x0400)   /* bit 10:  1 = skip if OS/2 DLL */
  786. #define MSG_NO_NDLL(f) (f & 0x0800)   /* bit 11:  1 = skip if WIN32 DLL */
  787. #define MSG_NO_WDLL(f) (f & 0x1000)   /* bit 12:  1 = skip if Windows DLL */
  788.  
  789. #if (defined(MORE) && !defined(SCREENLINES))
  790. #  ifdef DOS_FLX_OS2_W32
  791. #    define SCREENLINES 25  /* can be (should be) a function instead */
  792. #  else
  793. #    define SCREENLINES 24  /* VT-100s are assumed to be minimal hardware */
  794. #  endif
  795. #endif
  796.  
  797. #define DIR_BLKSIZ  64      /* number of directory entries per block
  798.                              *  (should fit in 4096 bytes, usually) */
  799. #ifndef WSIZE
  800. #  define WSIZE     0x8000  /* window size--must be a power of two, and */
  801. #endif                      /*  at least 32K for zip's deflate method */
  802.  
  803. #ifndef INBUFSIZ
  804. #  if (defined(MED_MEM) || defined(SMALL_MEM))
  805. #    define INBUFSIZ  2048  /* works for MS-DOS small model */
  806. #  else
  807. #    define INBUFSIZ  8192  /* larger buffers for real OSes */
  808. #  endif
  809. #endif
  810.  
  811. #ifndef __16BIT__
  812. #  define nearmalloc  malloc
  813. #  define nearfree    free
  814. #  ifndef __IBMC__
  815. #    define near
  816. #    define far
  817. #  endif
  818. #endif
  819.  
  820. #if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
  821. #  undef DYNALLOC_CRCTAB
  822. #endif
  823.  
  824. #if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
  825. #  undef DYNALLOC_CRCTAB   /* not safe with reentrant code */
  826. #endif
  827.  
  828. #if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
  829. #  ifdef DYNALLOC_CRCTAB
  830. #    undef DYNALLOC_CRCTAB
  831. #  endif
  832. #endif
  833.  
  834. #if (defined(USE_ZLIB) && defined(ASM_CRC))
  835. #  undef ASM_CRC
  836. #endif
  837.  
  838. /* Logic for case of small memory, length of EOL > 1:  if OUTBUFSIZ == 2048,
  839.  * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
  840.  * and transbuf 1040 bytes.  Have room for 32 extra EOL chars; 1008/32 == 31.5
  841.  * chars/line, smaller than estimated 35-70 characters per line for C source
  842.  * and normal text.  Hence difference is sufficient for most "average" files.
  843.  * (Argument scales for larger OUTBUFSIZ.)
  844.  */
  845. #ifdef SMALL_MEM          /* i.e., 16-bit OSes:  MS-DOS, OS/2 1.x, etc. */
  846. #  define LoadFarString(x)       fLoadFarString(__G__ (x))
  847. #  define LoadFarStringSmall(x)  fLoadFarStringSmall(__G__ (x))
  848. #  define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
  849. #  if (defined(_MSC_VER) && (_MSC_VER >= 600))
  850. #    define zfstrcpy(dest, src)  _fstrcpy((dest), (src))
  851. #  endif
  852. #  ifndef Far
  853. #    define Far far  /* __far only works for MSC 6.00, not 6.0a or Borland */
  854. #  endif
  855. #  define OUTBUFSIZ INBUFSIZ
  856. #  if (lenEOL == 1)
  857. #    define RAWBUFSIZ (OUTBUFSIZ>>1)
  858. #  else
  859. #    define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
  860. #  endif
  861. #  define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
  862.    typedef short  shrint;            /* short/int or "shrink int" (unshrink) */
  863. #else
  864. #  define zfstrcpy(dest, src)       strcpy((dest), (src))
  865. #  ifdef QDOS
  866. #    define LoadFarString(x)        Qstrfix(x)   /* fix up _ for '.' */
  867. #    define LoadFarStringSmall(x)   Qstrfix(x)
  868. #    define LoadFarStringSmall2(x)  Qstrfix(x)
  869. #  else
  870. #    define LoadFarString(x)        x
  871. #    define LoadFarStringSmall(x)   x
  872. #    define LoadFarStringSmall2(x)  x
  873. #  endif
  874. #  ifdef MED_MEM
  875. #    define OUTBUFSIZ 0xFF80         /* can't malloc arrays of 0xFFE8 or more */
  876. #    define TRANSBUFSIZ 0xFF80
  877.      typedef short  shrint;
  878. #  else
  879. #    define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
  880. #    define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
  881. #    ifdef AMIGA
  882.        typedef short shrint;
  883. #    else
  884.        typedef int  shrint;          /* for efficiency/speed, we hope... */
  885. #    endif
  886. #  endif /* ?MED_MEM */
  887. #  define RAWBUFSIZ OUTBUFSIZ
  888. #endif /* ?SMALL_MEM */
  889.  
  890. #ifndef Far
  891. #  define Far
  892. #endif
  893.  
  894. #ifndef MAIN
  895. #  define MAIN  main
  896. #endif
  897.  
  898. #ifdef SFX      /* disable some unused features for SFX executables */
  899. #  ifndef NO_ZIPINFO
  900. #    define NO_ZIPINFO
  901. #  endif
  902. #  ifdef TIMESTAMP
  903. #    undef TIMESTAMP
  904. #  endif
  905. #endif
  906.  
  907. /* user may have defined both by accident...  NOTIMESTAMP takes precedence */
  908. #if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
  909. #  undef TIMESTAMP
  910. #endif
  911.  
  912. #if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
  913. #  define COPYRIGHT_CLEAN
  914. #endif
  915.  
  916. #if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
  917. #  define LZW_CLEAN
  918. #endif
  919.  
  920. #ifndef O_BINARY
  921. #  define O_BINARY  0
  922. #endif
  923.  
  924. #ifndef PIPE_ERROR
  925. #  define PIPE_ERROR (errno == EPIPE)
  926. #endif
  927.  
  928. /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
  929. #ifdef VMS
  930. #  define FOPR  "r","ctx=stm"
  931. #  define FOPM  "r+","ctx=stm","rfm=fix","mrs=512"
  932. #  define FOPW  "w","ctx=stm","rfm=fix","mrs=512"
  933. #endif /* VMS */
  934.  
  935. #ifdef CMS_MVS
  936. /* Binary files must be RECFM=F,LRECL=1 for ftell() to get correct pos */
  937. #  define FOPW "wb,recfm=f,lrecl=1"
  938. #  ifdef MVS
  939. #    define FOPWT "w,lrecl=133"
  940. #  else
  941. #    define FOPWT "w"
  942. #  endif
  943. #endif /* CMS_MVS */
  944.  
  945. #ifdef TOPS20          /* TOPS-20 MODERN?  You kidding? */
  946. #  define FOPW "w8"
  947. #endif /* TOPS20 */
  948.  
  949. /* Defaults when nothing special has been defined previously. */
  950. #ifdef MODERN
  951. #  ifndef FOPR
  952. #    define FOPR "rb"
  953. #  endif
  954. #  ifndef FOPM
  955. #    define FOPM "r+b"
  956. #  endif
  957. #  ifndef FOPW
  958. #    define FOPW "wb"
  959. #  endif
  960. #  ifndef FOPWT
  961. #    define FOPWT "wt"
  962. #  endif
  963. #else /* !MODERN */
  964. #  ifndef FOPR
  965. #    define FOPR "r"
  966. #  endif
  967. #  ifndef FOPM
  968. #    define FOPM "r+"
  969. #  endif
  970. #  ifndef FOPW
  971. #    define FOPW "w"
  972. #  endif
  973. #  ifndef FOPWT
  974. #    define FOPWT "w"
  975. #  endif
  976. #endif /* ?MODERN */
  977.  
  978. /*
  979.  * If <limits.h> exists on most systems, should include that, since it may
  980.  * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  981.  * _POSIX_PATH_MAX.
  982.  */
  983. #ifdef DOS_FLX_OS2
  984. #  include <limits.h>
  985. #endif
  986.  
  987. #ifndef PATH_MAX
  988. #  ifdef MAXPATHLEN
  989. #    define PATH_MAX      MAXPATHLEN    /* in <sys/param.h> on some systems */
  990. #  else
  991. #    ifdef _MAX_PATH
  992. #      define PATH_MAX    _MAX_PATH
  993. #    else
  994. #      if FILENAME_MAX > 255
  995. #        define PATH_MAX  FILENAME_MAX  /* used like PATH_MAX on some systems */
  996. #      else
  997. #        define PATH_MAX  1024
  998. #      endif
  999. #    endif /* ?_MAX_PATH */
  1000. #  endif /* ?MAXPATHLEN */
  1001. #endif /* !PATH_MAX */
  1002.  
  1003. #define FILNAMSIZ  PATH_MAX
  1004.  
  1005. #ifdef SHORT_SYMS                   /* Mark Williams C, ...? */
  1006. #  define extract_or_test_files     xtr_or_tst_files
  1007. #  define extract_or_test_member    xtr_or_tst_member
  1008. #endif
  1009.  
  1010. #ifdef REALLY_SHORT_SYMS            /* TOPS-20 linker:  first 6 chars */
  1011. #  define process_cdir_file_hdr     XXpcdfh
  1012. #  define process_local_file_hdr    XXplfh
  1013. #  define extract_or_test_files     XXxotf  /* necessary? */
  1014. #  define extract_or_test_member    XXxotm  /* necessary? */
  1015. #  define check_for_newer           XXcfn
  1016. #  define overwrite_all             XXoa
  1017. #  define process_all_files         XXpaf
  1018. #  define extra_field               XXef
  1019. #  define explode_lit8              XXel8
  1020. #  define explode_lit4              XXel4
  1021. #  define explode_nolit8            XXnl8
  1022. #  define explode_nolit4            XXnl4
  1023. #  define cpdist8                   XXcpdist8
  1024. #  define inflate_codes             XXic
  1025. #  define inflate_stored            XXis
  1026. #  define inflate_fixed             XXif
  1027. #  define inflate_dynamic           XXid
  1028. #  define inflate_block             XXib
  1029. #  define maxcodemax                XXmax
  1030. #endif
  1031.  
  1032. #ifndef S_TIME_T_MAX            /* max value of signed (>= 32-bit) time_t */
  1033. #  define S_TIME_T_MAX  ((time_t)(ulg)0x7fffffffL)
  1034. #endif
  1035. #ifndef U_TIME_T_MAX            /* max value of unsigned (>= 32-bit) time_t */
  1036. #  define U_TIME_T_MAX  ((time_t)(ulg)0xffffffffL)
  1037. #endif
  1038. #ifdef DOSDATE_MINIMUM          /* min DOSDATE value (1980-01-01) */
  1039. #  undef DOSDATE_MINIMUM
  1040. #endif
  1041. #define DOSDATE_MINIMUM ((ush)0x0021)
  1042. #ifdef DOSDATE_2038_01_18       /* approximate DOSDATE equivalent of */
  1043. #  undef DOSDATE_2038_01_18     /*  the signed-32-bit time_t limit */
  1044. #endif
  1045. #define DOSDATE_2038_01_18 ((ush)0x7432)
  1046.  
  1047. #ifdef QDOS
  1048. #  define ZSUFX         "_zip"
  1049. #  define ALT_ZSUFX     ".zip"
  1050. #else
  1051. #  ifdef RISCOS
  1052. #    define ZSUFX       "/zip"
  1053. #  else
  1054. #    define ZSUFX       ".zip"
  1055. #  endif
  1056. #  define ALT_ZSUFX     ".ZIP"   /* Unix-only so far (only case-sensitive fs) */
  1057. #endif
  1058.  
  1059. #define CENTRAL_HDR_SIG   "\001\002"   /* the infamous "PK" signature bytes, */
  1060. #define LOCAL_HDR_SIG     "\003\004"   /*  sans "PK" (so unzip executable not */
  1061. #define END_CENTRAL_SIG   "\005\006"   /*  mistaken for zipfile itself) */
  1062. #define EXTD_LOCAL_SIG    "\007\010"   /* [ASCII "\113" == EBCDIC "\080" ??] */
  1063.  
  1064. /* choice of activities for do_string() */
  1065. #define SKIP              0             /* skip header block */
  1066. #define DISPLAY           1             /* display archive comment (ASCII) */
  1067. #define DISPL_8           5             /* display file comment (ext. ASCII) */
  1068. #define DS_FN             2             /* read filename (ext. ASCII) */
  1069. #define EXTRA_FIELD       3             /* copy extra field into buffer */
  1070. #define DS_EF             3
  1071. #ifdef AMIGA
  1072. #  define FILENOTE        4
  1073. #endif
  1074.  
  1075. #define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  1076. #define EXISTS_AND_OLDER  0
  1077. #define EXISTS_AND_NEWER  1
  1078.  
  1079. #define ROOT              0    /* checkdir() extract-to path:  called once */
  1080. #define INIT              1    /* allocate buildpath:  called once per member */
  1081. #define APPEND_DIR        2    /* append a dir comp.:  many times per member */
  1082. #define APPEND_NAME       3    /* append actual filename:  once per member */
  1083. #define GETPATH           4    /* retrieve the complete path and free it */
  1084. #define END               5    /* free root path prior to exiting program */
  1085.  
  1086. /* version_made_by codes (central dir):  make sure these */
  1087. /*  are not defined on their respective systems!! */
  1088. #define FS_FAT_           0    /* filesystem used by MS-DOS, OS/2, Win32 */
  1089. #define AMIGA_            1
  1090. #define VMS_              2
  1091. #define UNIX_             3
  1092. #define VM_CMS_           4
  1093. #define ATARI_            5    /* what if it's a minix filesystem? [cjh] */
  1094. #define FS_HPFS_          6    /* filesystem used by OS/2 (and NT 3.x) */
  1095. #define MAC_              7
  1096. #define Z_SYSTEM_         8
  1097. #define CPM_              9
  1098. #define TOPS20_           10
  1099. #define FS_NTFS_          11   /* filesystem used by Windows NT */
  1100. #define QDOS_             12
  1101. #define ACORN_            13   /* Archimedes Acorn RISC OS */
  1102. #define FS_VFAT_          14   /* filesystem used by Windows 95, NT */
  1103. #define MVS_              15
  1104. #define BEOS_             16   /* hybrid POSIX/database filesystem */
  1105. #define TANDEM_           17   /* Tandem/NSK */
  1106. #define NUM_HOSTS         18   /* index of last system + 1 */
  1107.  
  1108. #define STORED            0    /* compression methods */
  1109. #define SHRUNK            1
  1110. #define REDUCED1          2
  1111. #define REDUCED2          3
  1112. #define REDUCED3          4
  1113. #define REDUCED4          5
  1114. #define IMPLODED          6
  1115. #define TOKENIZED         7
  1116. #define DEFLATED          8
  1117. #define ENHDEFLATED       9
  1118. #define DCLIMPLODED      10
  1119. #define NUM_METHODS      11    /* index of last method + 1 */
  1120. /* don't forget to update list_files(), extract.c and zipinfo.c appropriately
  1121.  * if NUM_METHODS changes */
  1122.  
  1123. /* (the PK-class error codes are public and have been moved into unzip.h) */
  1124.  
  1125. #define DF_MDY            0    /* date format 10/26/91 (USA only) */
  1126. #define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  1127. #define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  1128.  
  1129. /*---------------------------------------------------------------------------
  1130.     Extra-field block ID values and offset info.
  1131.   ---------------------------------------------------------------------------*/
  1132. /* extra-field ID values, all little-endian: */
  1133. #define EF_AV        0x0007    /* PKWARE's authenticity verification */
  1134. #define EF_OS2       0x0009    /* OS/2 extended attributes */
  1135. #define EF_PKVMS     0x000c    /* PKWARE's VMS */
  1136. #define EF_PKUNIX    0x000d    /* PKWARE's Unix */
  1137. #define EF_IZVMS     0x4d49    /* Info-ZIP's VMS ("IM") */
  1138. #define EF_IZUNIX    0x5855    /* Info-ZIP's old Unix[1] ("UX") */
  1139. #define EF_IZUNIX2   0x7855    /* Info-ZIP's new Unix[2] ("Ux") */
  1140. #define EF_TIME      0x5455    /* universal timestamp ("UT") */
  1141. #define EF_JLMAC     0x07c8    /* Johnny Lee's old Macintosh (= 1992) */
  1142. #define EF_ZIPIT     0x2605    /* Thomas Brown's Macintosh (ZipIt) */
  1143. #define EF_VMCMS     0x4704    /* Info-ZIP's VM/CMS ("\004G") */
  1144. #define EF_MVS       0x470f    /* Info-ZIP's MVS ("\017G") */
  1145. #define EF_ACL       0x4c41    /* (OS/2) access control list ("AL") */
  1146. #define EF_NTSD      0x4453    /* NT security descriptor ("SD") */
  1147. #define EF_BEOS      0x6542    /* BeOS ("Be") */
  1148. #define EF_QDOS      0xfb4a    /* SMS/QDOS ("J\373") */
  1149. #define EF_AOSVS     0x5356    /* AOS/VS ("VS") */
  1150. #define EF_SPARK     0x4341    /* David Pilling's Acorn/SparkFS ("AC") */
  1151. #define EF_MD5       0x4b46    /* Fred Kantor's MD5 ("FK") */
  1152. #define EF_ASIUNIX   0x756e    /* ASi's Unix ("nu") */
  1153.  
  1154. #define EB_HEADSIZE       4    /* length of extra field block header */
  1155. #define EB_ID             0    /* offset of block ID in header */
  1156. #define EB_LEN            2    /* offset of data length field in header */
  1157. #define EB_UCSIZE_P       0    /* offset of ucsize field in compr. data */
  1158. #define EB_CMPRHEADLEN    6    /* lenght of compression header */
  1159.  
  1160. #define EB_UX_MINLEN      8    /* minimal "UX" field contains atime, mtime */
  1161. #define EB_UX_FULLSIZE    12   /* full "UX" field (atime, mtime, uid, gid) */
  1162. #define EB_UX_ATIME       0    /* offset of atime in "UX" extra field data */
  1163. #define EB_UX_MTIME       4    /* offset of mtime in "UX" extra field data */
  1164. #define EB_UX_UID         8    /* byte offset of UID in "UX" field data */
  1165. #define EB_UX_GID         10   /* byte offset of GID in "UX" field data */
  1166.  
  1167. #define EB_UX2_MINLEN     4    /* minimal "Ux" field contains UID/GID */
  1168. #define EB_UX2_UID        0    /* byte offset of UID in "Ux" field data */
  1169. #define EB_UX2_GID        2    /* byte offset of GID in "Ux" field data */
  1170. #define EB_UX2_VALID      (1 << 8)      /* UID/GID present */
  1171.  
  1172. #define EB_UT_MINLEN      1    /* minimal UT field contains Flags byte */
  1173. #define EB_UT_FLAGS       0    /* byte offset of Flags field */
  1174. #define EB_UT_TIME1       1    /* byte offset of 1st time value */
  1175. #define EB_UT_FL_MTIME    (1 << 0)      /* mtime present */
  1176. #define EB_UT_FL_ATIME    (1 << 1)      /* atime present */
  1177. #define EB_UT_FL_CTIME    (1 << 2)      /* ctime present */
  1178.  
  1179. #define EB_OS2_CHEAD      4    /* offset of OS2/ACL compressed data header */
  1180.  
  1181. #define EB_NTSD_C_LEN     4    /* length of central NT security data */
  1182. #define EB_NTSD_L_LEN     5    /* length of minimal local NT security data */
  1183. #define EB_NTSD_VERSION   4    /* offset of NTSD version byte */
  1184. #define EB_NTSD_MAX_VER   (0)  /* maximum version # we know how to handle */
  1185.  
  1186. /*---------------------------------------------------------------------------
  1187.     True sizes of the various headers, as defined by PKWARE--so it is not
  1188.     likely that these will ever change.  But if they do, make sure both these
  1189.     defines AND the typedefs below get updated accordingly.
  1190.   ---------------------------------------------------------------------------*/
  1191. #define LREC_SIZE   26   /* lengths of local file headers, central */
  1192. #define CREC_SIZE   42   /*  directory headers, and the end-of-    */
  1193. #define ECREC_SIZE  18   /*  central-dir record, respectively      */
  1194.  
  1195. #define MAX_BITS    13                 /* used in unshrink() */
  1196. #define HSIZE       (1 << MAX_BITS)    /* size of global work area */
  1197.  
  1198. #define LF     10        /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  1199. #define CR     13        /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  1200. #define CTRLZ  26        /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
  1201.  
  1202. #ifdef EBCDIC
  1203. #  define foreign(c)    ascii[(uch)(c)]
  1204. #  define native(c)     ebcdic[(uch)(c)]
  1205. #  define NATIVE        "EBCDIC"
  1206. #endif
  1207.  
  1208. #if (defined(CRAY) && defined(ZMEM))
  1209. #  undef ZMEM
  1210. #endif
  1211.  
  1212. #ifdef ZMEM
  1213. #  undef ZMEM
  1214. #  define memcpy(dest,src,len)   bcopy(src,dest,len)
  1215. #  define memzero                bzero
  1216. #else
  1217. #  define memzero(dest,len)      memset(dest,0,len)
  1218. #endif
  1219.  
  1220. #ifdef VMS
  1221. #  define ENV_UNZIP       "UNZIP_OPTS"     /* names of environment variables */
  1222. #  define ENV_ZIPINFO     "ZIPINFO_OPTS"
  1223. #endif /* VMS */
  1224. #ifdef RISCOS
  1225. #  define ENV_UNZIP       "Unzip$Options"
  1226. #  define ENV_ZIPINFO     "Zipinfo$Options"
  1227. #  define ENV_UNZIPEXTS   "Unzip$Exts"
  1228. #endif /* RISCOS */
  1229. #ifndef ENV_UNZIP
  1230. #  define ENV_UNZIP       "UNZIP"          /* the standard names */
  1231. #  define ENV_ZIPINFO     "ZIPINFO"
  1232. #endif
  1233. #define ENV_UNZIP2        "UNZIPOPT"     /* alternate names, for zip compat. */
  1234. #define ENV_ZIPINFO2      "ZIPINFOOPT"
  1235.  
  1236. #if (!defined(QQ) && !defined(NOQQ))
  1237. #  define QQ
  1238. #endif
  1239.  
  1240. #ifdef QQ                         /* Newtware version:  no file */
  1241. #  define QCOND     (!G.qflag)   /*  comments with -vq or -vqq */
  1242. #else                             /* Bill Davidsen version:  no way to */
  1243. #  define QCOND     (which_hdr)   /*  kill file comments when listing */
  1244. #endif
  1245.  
  1246. #ifdef OLD_QQ
  1247. #  define QCOND2    (G.qflag < 2)
  1248. #else
  1249. #  define QCOND2    (!G.qflag)
  1250. #endif
  1251.  
  1252. #ifndef TRUE
  1253. #  define TRUE      1   /* sort of obvious */
  1254. #endif
  1255. #ifndef FALSE
  1256. #  define FALSE     0
  1257. #endif
  1258.  
  1259. #ifndef SEEK_SET
  1260. #  define SEEK_SET  0
  1261. #  define SEEK_CUR  1
  1262. #  define SEEK_END  2
  1263. #endif
  1264.  
  1265. #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
  1266. #  define SYMLINKS
  1267. #  ifndef S_ISLNK
  1268. #    define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK)
  1269. #  endif
  1270. #endif /* UNIX && S_IFLNK && !MTS */
  1271.  
  1272. #ifndef S_ISDIR
  1273. #  ifdef CMS_MVS
  1274. #    define S_ISDIR(m)  (FALSE)
  1275. #  else
  1276. #    define S_ISDIR(m)  (((m) & S_IFMT) == S_IFDIR)
  1277. # endif
  1278. #endif
  1279.  
  1280. #ifndef IS_VOLID
  1281. #  define IS_VOLID(m)  ((m) & 0x08)
  1282. #endif
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288. /**************/
  1289. /*  Typedefs  */
  1290. /**************/
  1291.  
  1292. #ifdef NO_UID_GID
  1293. #  ifdef UID_USHORT
  1294.      typedef unsigned short  uid_t;    /* TI SysV.3 */
  1295.      typedef unsigned short  gid_t;
  1296. #  else
  1297.      typedef unsigned int    uid_t;    /* SCO Xenix */
  1298.      typedef unsigned int    gid_t;
  1299. #  endif
  1300. #endif
  1301.  
  1302. #if (defined(WIN32) || defined(sgi) || defined(GOT_UTIMBUF) || defined(ATARI))
  1303.    typedef struct utimbuf ztimbuf;
  1304. #else
  1305.    typedef struct ztimbuf {
  1306.        time_t actime;        /* new access time */
  1307.        time_t modtime;       /* new modification time */
  1308.    } ztimbuf;
  1309. #endif
  1310.  
  1311. typedef struct iztimes {
  1312.    time_t atime;             /* new access time */
  1313.    time_t mtime;             /* new modification time */
  1314.    time_t ctime;             /* used for creation time; NOT same as st_ctime */
  1315. } iztimes;
  1316.  
  1317. #ifdef UNIX
  1318.    typedef struct dirtime {  /* temporary struct for holding directory info */
  1319.        char *fn;             /*  until can be sorted and set at end */
  1320.        union {
  1321.            iztimes t3;       /* mtime, atime, ctime */
  1322.            ztimbuf t2;       /* modtime, actime */
  1323.        } u;
  1324.        unsigned perms;       /* same as min_info.file_attr */
  1325.        int have_uidgid;      /* flag */
  1326.        ush uidgid[2];
  1327.    } dirtime;
  1328. #endif /* UNIX */
  1329.  
  1330. typedef struct min_info {
  1331.     long offset;
  1332.     ulg compr_size;          /* compressed size (needed if extended header) */
  1333.     ulg crc;                 /* crc (needed if extended header) */
  1334.     int hostnum;
  1335.     unsigned file_attr;      /* local flavor, as used by creat(), chmod()... */
  1336.     unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  1337.     unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  1338.     unsigned textfile : 1;   /* file is text (according to zip) */
  1339.     unsigned textmode : 1;   /* file is to be extracted as text */
  1340.     unsigned lcflag : 1;     /* convert filename to lowercase */
  1341.     unsigned vollabel : 1;   /* "file" is an MS-DOS volume (disk) label */
  1342. } min_info;
  1343.  
  1344. typedef struct VMStimbuf {
  1345.     char *revdate;    /* (both roughly correspond to Unix modtime/st_mtime) */
  1346.     char *credate;
  1347. } VMStimbuf;
  1348.  
  1349. /*---------------------------------------------------------------------------
  1350.     Zipfile work area declarations.
  1351.   ---------------------------------------------------------------------------*/
  1352.  
  1353. #ifdef MALLOC_WORK
  1354.    union work {
  1355.      struct {                 /* unshrink(): */
  1356.        shrint *Parent;          /* (8193 * sizeof(shrint)) */
  1357.        uch *value;
  1358.        uch *Stack;
  1359.      } shrink;
  1360.      uch *Slide;              /* explode(), inflate(), unreduce() */
  1361.    };
  1362. #else /* !MALLOC_WORK */
  1363.    union work {
  1364.      struct {                 /* unshrink(): */
  1365.        shrint Parent[HSIZE];    /* (8192 * sizeof(shrint)) == 16KB minimum */
  1366.        uch value[HSIZE];        /* 8KB */
  1367.        uch Stack[HSIZE];        /* 8KB */
  1368.      } shrink;                  /* total = 32KB minimum; 80KB on Cray/Alpha */
  1369.      uch Slide[WSIZE];        /* explode(), inflate(), unreduce() */
  1370.    };
  1371. #endif /* ?MALLOC_WORK */
  1372.  
  1373. #define slide  G.area.Slide
  1374.  
  1375. #ifdef DLL
  1376. #  define redirSlide G.redirect_pointer
  1377. #else
  1378. #  define redirSlide G.area.Slide
  1379. #endif
  1380.  
  1381. /*---------------------------------------------------------------------------
  1382.     Zipfile layout declarations.  If these headers ever change, make sure the
  1383.     xxREC_SIZE defines (above) change with them!
  1384.   ---------------------------------------------------------------------------*/
  1385.  
  1386.    typedef uch   local_byte_hdr[ LREC_SIZE ];
  1387. #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  1388. #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  1389. #      define L_GENERAL_PURPOSE_BIT_FLAG        2
  1390. #      define L_COMPRESSION_METHOD              4
  1391. #      define L_LAST_MOD_FILE_TIME              6
  1392. #      define L_LAST_MOD_FILE_DATE              8
  1393. #      define L_CRC32                           10
  1394. #      define L_COMPRESSED_SIZE                 14
  1395. #      define L_UNCOMPRESSED_SIZE               18
  1396. #      define L_FILENAME_LENGTH                 22
  1397. #      define L_EXTRA_FIELD_LENGTH              24
  1398.  
  1399.    typedef uch   cdir_byte_hdr[ CREC_SIZE ];
  1400. #      define C_VERSION_MADE_BY_0               0
  1401. #      define C_VERSION_MADE_BY_1               1
  1402. #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  1403. #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  1404. #      define C_GENERAL_PURPOSE_BIT_FLAG        4
  1405. #      define C_COMPRESSION_METHOD              6
  1406. #      define C_LAST_MOD_FILE_TIME              8
  1407. #      define C_LAST_MOD_FILE_DATE              10
  1408. #      define C_CRC32                           12
  1409. #      define C_COMPRESSED_SIZE                 16
  1410. #      define C_UNCOMPRESSED_SIZE               20
  1411. #      define C_FILENAME_LENGTH                 24
  1412. #      define C_EXTRA_FIELD_LENGTH              26
  1413. #      define C_FILE_COMMENT_LENGTH             28
  1414. #      define C_DISK_NUMBER_START               30
  1415. #      define C_INTERNAL_FILE_ATTRIBUTES        32
  1416. #      define C_EXTERNAL_FILE_ATTRIBUTES        34
  1417. #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  1418.  
  1419.    typedef uch   ec_byte_rec[ ECREC_SIZE+4 ];
  1420. /*     define SIGNATURE                         0   space-holder only */
  1421. #      define NUMBER_THIS_DISK                  4
  1422. #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  1423. #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  1424. #      define TOTAL_ENTRIES_CENTRAL_DIR         10
  1425. #      define SIZE_CENTRAL_DIRECTORY            12
  1426. #      define OFFSET_START_CENTRAL_DIRECTORY    16
  1427. #      define ZIPFILE_COMMENT_LENGTH            20
  1428.  
  1429.  
  1430.    typedef struct local_file_header {                 /* LOCAL */
  1431.        uch version_needed_to_extract[2];
  1432.        ush general_purpose_bit_flag;
  1433.        ush compression_method;
  1434.        ush last_mod_file_time;
  1435.        ush last_mod_file_date;
  1436.        ulg crc32;
  1437.        ulg csize;
  1438.        ulg ucsize;
  1439.        ush filename_length;
  1440.        ush extra_field_length;
  1441.    } local_file_hdr;
  1442.  
  1443. #if 0
  1444.    typedef struct central_directory_file_header {     /* CENTRAL */
  1445.        uch version_made_by[2];
  1446.        uch version_needed_to_extract[2];
  1447.        ush general_purpose_bit_flag;
  1448.        ush compression_method;
  1449.        ush last_mod_file_time;
  1450.        ush last_mod_file_date;
  1451.        ulg crc32;
  1452.        ulg csize;
  1453.        ulg ucsize;
  1454.        ush filename_length;
  1455.        ush extra_field_length;
  1456.        ush file_comment_length;
  1457.        ush disk_number_start;
  1458.        ush internal_file_attributes;
  1459.        ulg external_file_attributes;
  1460.        ulg relative_offset_local_header;
  1461.    } cdir_file_hdr;
  1462. #endif /* 0 */
  1463.  
  1464.    typedef struct end_central_dir_record {            /* END CENTRAL */
  1465.        ush number_this_disk;
  1466.        ush num_disk_start_cdir;
  1467.        ush num_entries_centrl_dir_ths_disk;
  1468.        ush total_entries_central_dir;
  1469.        ulg size_central_directory;
  1470.        ulg offset_start_central_directory;
  1471.        ush zipfile_comment_length;
  1472.    } ecdir_rec;
  1473.  
  1474.  
  1475. /* Huffman code lookup table entry--this entry is four bytes for machines
  1476.    that have 16-bit pointers (e.g. PC's in the small or medium model).
  1477.    Valid extra bits are 0..13.  e == 15 is EOB (end of block), e == 16
  1478.    means that v is a literal, 16 < e < 32 means that v is a pointer to
  1479.    the next table, which codes e - 16 bits, and lastly e == 99 indicates
  1480.    an unused code.  If a code with e == 99 is looked up, this implies an
  1481.    error in the data. */
  1482.  
  1483. struct huft {
  1484.     uch e;                /* number of extra bits or operation */
  1485.     uch b;                /* number of bits in this code or subcode */
  1486.     union {
  1487.         ush n;            /* literal, length base, or distance base */
  1488.         struct huft *t;   /* pointer to next level of table */
  1489.     } v;
  1490. };
  1491.  
  1492.  
  1493. typedef struct _APIDocStruct {
  1494.     char *compare;
  1495.     char *function;
  1496.     char *syntax;
  1497.     char *purpose;
  1498. } APIDocStruct;
  1499.  
  1500.  
  1501.  
  1502.  
  1503. /*************/
  1504. /*  Globals  */
  1505. /*************/
  1506.  
  1507. #if (defined(OS2) && !defined(FUNZIP))
  1508. #  include "os2/os2data.h"
  1509. #endif
  1510.  
  1511. #include "globals.h"
  1512.  
  1513.  
  1514.  
  1515. /*************************/
  1516. /*  Function Prototypes  */
  1517. /*************************/
  1518.  
  1519. /*---------------------------------------------------------------------------
  1520.     Functions in unzip.c (initialization routines):
  1521.   ---------------------------------------------------------------------------*/
  1522.  
  1523. #ifndef WINDLL
  1524.    int    MAIN                   OF((int argc, char **argv));
  1525.    int    unzip                  OF((__GPRO__ int argc, char **argv));
  1526.    int    uz_opts                OF((__GPRO__ int *pargc, char ***pargv));
  1527.    int    usage                  OF((__GPRO__ int error));
  1528. #endif /* !WINDLL */
  1529.  
  1530. /*---------------------------------------------------------------------------
  1531.     Functions in process.c (main driver routines):
  1532.   ---------------------------------------------------------------------------*/
  1533.  
  1534. int      process_zipfiles        OF((__GPRO));
  1535. void     free_G_buffers          OF((__GPRO));
  1536. /* static int    do_seekable     OF((__GPRO__ int lastchance)); */
  1537. /* static int    find_ecrec      OF((__GPRO__ long searchlen)); */
  1538. int      uz_end_central          OF((__GPRO));
  1539. int      process_cdir_file_hdr   OF((__GPRO));
  1540. int      get_cdir_ent            OF((__GPRO));
  1541. int      process_local_file_hdr  OF((__GPRO));
  1542. unsigned ef_scan_for_izux        OF((uch *ef_buf, unsigned ef_len, int ef_is_c,
  1543.                                      unsigned dos_mdate,
  1544.                                      iztimes *z_utim, ush *z_uidgid));
  1545.  
  1546. #ifndef SFX
  1547.  
  1548. /*---------------------------------------------------------------------------
  1549.     Functions in zipinfo.c (`zipinfo-style' listing routines):
  1550.   ---------------------------------------------------------------------------*/
  1551.  
  1552. #ifndef NO_ZIPINFO
  1553. #ifndef WINDLL
  1554.    int   zi_opts                 OF((__GPRO__ int *pargc, char ***pargv));
  1555. #endif
  1556. int      zi_end_central          OF((__GPRO));
  1557. int      zipinfo                 OF((__GPRO));
  1558. /* static int      zi_long       OF((__GPRO__ ulg *pEndprev)); */
  1559. /* static int      zi_short      OF((__GPRO)); */
  1560. /* static char    *zi_time       OF((__GPRO__
  1561.                                      ZCONST ush *datez, ZCONST ush *timez,
  1562.                                      ZCONST time_t *modtimez, char *d_t_str));*/
  1563. #endif /* !NO_ZIPINFO */
  1564.  
  1565. /*---------------------------------------------------------------------------
  1566.     Functions in list.c (generic zipfile-listing routines):
  1567.   ---------------------------------------------------------------------------*/
  1568.  
  1569. int      list_files              OF((__GPRO));
  1570. #ifdef TIMESTAMP
  1571.    int   get_time_stamp          OF((__GPRO__  time_t *last_modtime,
  1572.                                      unsigned *nmember));
  1573. #endif
  1574. int      ratio                   OF((ulg uc, ulg c));
  1575. void     fnprint                 OF((__GPRO));
  1576.  
  1577. #endif /* !SFX */
  1578.  
  1579. /*---------------------------------------------------------------------------
  1580.     Functions in fileio.c:
  1581.   ---------------------------------------------------------------------------*/
  1582.  
  1583. int      open_input_file      OF((__GPRO));
  1584. int      open_outfile         OF((__GPRO));                    /* also vms.c */
  1585. void     undefer_input        OF((__GPRO));
  1586. void     defer_leftover_input OF((__GPRO));
  1587. unsigned readbuf              OF((__GPRO__ char *buf, register unsigned len));
  1588. int      readbyte             OF((__GPRO));
  1589. int      fillinbuf            OF((__GPRO));
  1590. #ifdef FUNZIP
  1591.    int   flush                OF((__GPRO__ ulg size));  /* actually funzip.c */
  1592. #else
  1593.    int   flush                OF((__GPRO__ uch *buf, ulg size, int unshrink));
  1594. #endif
  1595. /* static int  disk_error     OF((__GPRO)); */
  1596. void     handler              OF((int signal));
  1597. time_t   dos_to_unix_time     OF((unsigned ddate, unsigned dtime));
  1598. int      check_for_newer      OF((__GPRO__ char *filename)); /* os2,vmcms,vms */
  1599. int      do_string            OF((__GPRO__ unsigned int len, int option));
  1600. ush      makeword             OF((uch *b));
  1601. ulg      makelong             OF((uch *sig));
  1602. #if (!defined(STR_TO_ISO) || defined(NEED_STR2ISO))
  1603.    char *str2iso              OF((char *dst, ZCONST char *src));
  1604. #endif
  1605. #if (!defined(STR_TO_OEM) || defined(NEED_STR2OEM))
  1606.    char *str2oem              OF((char *dst, ZCONST char *src));
  1607. #endif
  1608. int      zstrnicmp            OF((register ZCONST char *s1,
  1609.                                   register ZCONST char *s2,
  1610.                                   register unsigned n));
  1611. #ifdef REGULUS
  1612.    int zstat                  OF((char *p, struct stat *s));
  1613. #endif
  1614. #ifdef ZMEM   /* MUST be ifdef'd because of conflicts with the standard def. */
  1615.    zvoid *memset OF((register zvoid *, register int, register unsigned int));
  1616.    zvoid *memcpy OF((register zvoid *, register ZCONST zvoid *,
  1617.                      register unsigned int));
  1618. #endif
  1619. #ifdef SMALL_MEM
  1620.    char *fLoadFarString       OF((__GPRO__ const char Far *sz));
  1621.    char *fLoadFarStringSmall  OF((__GPRO__ const char Far *sz));
  1622.    char *fLoadFarStringSmall2 OF((__GPRO__ const char Far *sz));
  1623.    #ifndef zfstrcpy
  1624.      char Far * Far zfstrcpy  OF((char Far *s1, const char Far *s2));
  1625.    #endif
  1626. #endif
  1627.  
  1628.  
  1629. /*---------------------------------------------------------------------------
  1630.     Functions in extract.c:
  1631.   ---------------------------------------------------------------------------*/
  1632.  
  1633. int    extract_or_test_files     OF((__GPRO));
  1634. /* static int   store_info          OF((void)); */
  1635. /* static int   extract_or_test_member   OF((__GPRO)); */
  1636. /* static int   TestExtraField   OF((__GPRO__ uch *ef, unsigned ef_len)); */
  1637. /* static int   test_OS2         OF((__GPRO__ uch *eb, unsigned eb_size)); */
  1638. /* static int   test_NT          OF((__GPRO__ uch *eb, unsigned eb_size)); */
  1639. int    memextract                OF((__GPRO__ uch *tgt, ulg tgtsize,
  1640.                                      uch *src, ulg srcsize));
  1641. int    memflush                  OF((__GPRO__ uch *rawbuf, ulg size));
  1642. char  *fnfilter                  OF((char *raw, uch *space));
  1643.  
  1644. /*---------------------------------------------------------------------------
  1645.     Decompression functions:
  1646.   ---------------------------------------------------------------------------*/
  1647.  
  1648. #if (!defined(SFX) && !defined(FUNZIP))
  1649. int    explode                   OF((__GPRO));                  /* explode.c */
  1650. #endif
  1651. int    huft_free                 OF((struct huft *t));          /* inflate.c */
  1652. int    huft_build                OF((__GPRO__ unsigned *b, unsigned n,
  1653.                                      unsigned s, ush *d, ush *e,
  1654.                                      struct huft **t, int *m));
  1655. #ifdef USE_ZLIB
  1656.    int    UZinflate              OF((__GPRO));                  /* inflate.c */
  1657. #  define inflate_free(x)        inflateEnd(&((struct Globals *)(&G))->dstrm)
  1658. #else
  1659.    int    inflate                OF((__GPRO));                  /* inflate.c */
  1660.    int    inflate_free           OF((__GPRO));                  /* inflate.c */
  1661. #endif /* ?USE_ZLIB */
  1662. #if (!defined(SFX) && !defined(FUNZIP))
  1663. void   unreduce                  OF((__GPRO));                 /* unreduce.c */
  1664. /* static void  LoadFollowers    OF((__GPRO__ f_array *follower, uch *Slen));
  1665.                                                                 * unreduce.c */
  1666. int    unshrink                  OF((__GPRO));                 /* unshrink.c */
  1667. /* static void  partial_clear    OF((__GPRO));                  * unshrink.c */
  1668. #endif /* !SFX && !FUNZIP */
  1669.  
  1670. /*---------------------------------------------------------------------------
  1671.     Internal API functions (only included in DLL versions):
  1672.   ---------------------------------------------------------------------------*/
  1673.  
  1674. #ifdef DLL
  1675.    void     setFileNotFound       OF((__GPRO));                     /* api.c */
  1676.    int      unzipToMemory         OF((__GPRO__ char *zip, char *file,
  1677.                                       UzpBuffer *retstr));          /* api.c */
  1678.    int      redirect_outfile      OF((__GPRO));                     /* api.c */
  1679.    int      writeToMemory         OF((__GPRO__ uch *rawbuf, ulg size));
  1680.    /* this obsolescent entry point kept for compatibility: */
  1681.    int      UzpUnzip              OF((int argc, char **argv));/* use UzpMain */
  1682. #ifdef OS2DLL
  1683.    int      varmessage            OF((__GPRO__ uch *buf, ulg size));
  1684.    int      varputchar            OF((__GPRO__ int c));         /* rexxapi.c */
  1685.    int      finish_REXX_redirect  OF((__GPRO));                 /* rexxapi.c */
  1686. #endif
  1687. #ifdef API_DOC
  1688.    void     APIhelp               OF((__GPRO__ int argc, char **argv));
  1689. #endif                                                          /* apihelp.c */
  1690. #endif /* DLL */
  1691.  
  1692. /*---------------------------------------------------------------------------
  1693.     Acorn RISC OS-only functions:
  1694.   ---------------------------------------------------------------------------*/
  1695.  
  1696. #ifdef RISCOS
  1697.    int   isRISCOSexfield     OF((void *extra_field));             /* acorn.c */
  1698.    void  setRISCOSexfield    OF((char *path, void *extra_field)); /* acorn.c */
  1699.    void  printRISCOSexfield  OF((int isdir, void *extra_field));  /* acorn.c */
  1700. #endif
  1701.  
  1702. /*---------------------------------------------------------------------------
  1703.     BeOS-only functions:
  1704.   ---------------------------------------------------------------------------*/
  1705.  
  1706. #ifdef __BEOS__
  1707.    uch  *scanBeOSexfield     OF((uch *extra_field, unsigned ef_len));
  1708.    int   isBeOSexfield       OF((uch *extra_field));               /* beos.c */
  1709.    void  setBeOSexfield      OF((char *path, uch *extra_field));   /* beos.c */
  1710.    void  printBeOSexfield    OF((int isdir, uch *extra_field));    /* beos.c */
  1711. #endif
  1712.  
  1713. /*---------------------------------------------------------------------------
  1714.     Human68K-only functions:
  1715.   ---------------------------------------------------------------------------*/
  1716.  
  1717. #ifdef __human68k__
  1718.    void  InitTwentyOne       OF((void));
  1719. #endif
  1720.  
  1721. /*---------------------------------------------------------------------------
  1722.     Macintosh-only functions:
  1723.   ---------------------------------------------------------------------------*/
  1724.  
  1725. #ifdef MACOS
  1726.    void    screenOpen        OF((char *));                    /* macscreen.c */
  1727.    void    screenControl     OF((char *, int));               /* macscreen.c */
  1728.    void    screenDump        OF((char *, long));              /* macscreen.c */
  1729.    void    screenUpdate      OF((WindowPtr));                 /* macscreen.c */
  1730.    void    screenClose       OF((void));                      /* macscreen.c */
  1731.  
  1732.    void    MacFSTest  OF((int));                                    /* mac.c */
  1733.    int     macmkdir   OF((char *, short, long));                    /* mac.c */
  1734.    void    ResolveMacVol OF((short, short *, long *, StringPtr));   /* mac.c */
  1735.    short   macopen    OF((char *, short, short, long));             /* mac.c */
  1736.    FILE   *macfopen   OF((char *, char *, short, long));            /* mac.c */
  1737.    short   maccreat   OF((char *, short, long, OSType, OSType));    /* mac.c */
  1738.    short   macread    OF((short, char *, unsigned));                /* mac.c */
  1739.    long    macwrite   OF((short, char *, unsigned));                /* mac.c */
  1740.    short   macclose   OF((short));                                  /* mac.c */
  1741.    long    maclseek   OF((short, long, short));                     /* mac.c */
  1742.    int     macgetch   OF((void));                                   /* mac.c */
  1743.    char   *macgetenv  OF((char *));                                 /* mac.c */
  1744.    char   *wfgets     OF((char *, int, FILE *));                    /* mac.c */
  1745.    void    wfprintf   OF((FILE *, char *, ...));                    /* mac.c */
  1746.    void    wprintf    OF((char *, ...));                            /* mac.c */
  1747. #endif
  1748.  
  1749. /*---------------------------------------------------------------------------
  1750.     MSDOS-only functions:
  1751.   ---------------------------------------------------------------------------*/
  1752.  
  1753. #if (defined(__GO32__) || (defined(MSDOS) && defined(__EMX__)))
  1754.    unsigned _dos_getcountryinfo(void *);                          /* msdos.c */
  1755. #if (!defined(__DJGPP__) || (__DJGPP__ < 2))
  1756.    unsigned _dos_setftime(int, unsigned short, unsigned short);   /* msdos.c */
  1757.    void _dos_setfileattr(char *, int);                            /* msdos.c */
  1758.    unsigned _dos_creat(char *, unsigned, int *);                  /* msdos.c */
  1759.    void _dos_getdrive(unsigned *);                                /* msdos.c */
  1760.    unsigned _dos_close(int);                                      /* msdos.c */
  1761. #endif /* !__DJGPP__ || (__DJGPP__ < 2) */
  1762. #endif
  1763.  
  1764. /*---------------------------------------------------------------------------
  1765.     OS/2-only functions:
  1766.   ---------------------------------------------------------------------------*/
  1767.  
  1768. #ifdef OS2   /* GetFileTime conflicts with something in Win32 header files */
  1769. #if (defined(REENTRANT) && defined(USETHREADID))
  1770.    ulg   GetThreadId          OF((void));
  1771. #endif
  1772.    int   GetCountryInfo       OF((void));                           /* os2.c */
  1773.    long  GetFileTime          OF((ZCONST char *name));              /* os2.c */
  1774. /* static void  SetPathAttrTimes OF((__GPRO__ int flags, int dir));    os2.c */
  1775. /* static int   SetEAs        OF((__GPRO__ const char *path,
  1776.                                   void *eablock));                     os2.c */
  1777. /* static int   SetACL        OF((__GPRO__ const char *path,
  1778.                                   void *eablock));                     os2.c */
  1779. /* static int   IsFileNameValid OF((const char *name));                os2.c */
  1780. /* static void  map2fat       OF((char *pathcomp, char **pEndFAT));    os2.c */
  1781. /* static int   SetLongNameEA OF((char *name, char *longname));        os2.c */
  1782. /* static void  InitNLS       OF((void));                              os2.c */
  1783.    int   IsUpperNLS           OF((int nChr));                       /* os2.c */
  1784.    int   ToLowerNLS           OF((int nChr));                       /* os2.c */
  1785.    void  DebugMalloc          OF((void));                           /* os2.c */
  1786. #endif
  1787.  
  1788. /*---------------------------------------------------------------------------
  1789.     QDOS-only functions:
  1790.   ---------------------------------------------------------------------------*/
  1791.  
  1792. #ifdef QDOS
  1793.    int    QMatch              (uch, uch);
  1794.    void   QFilename           (__GPRO__ char *);
  1795.    char  *Qstrfix             (char *);
  1796.    int    QReturn             (int zip_error);
  1797. #endif
  1798.  
  1799. /*---------------------------------------------------------------------------
  1800.     TOPS20-only functions:
  1801.   ---------------------------------------------------------------------------*/
  1802.  
  1803. #ifdef TOPS20
  1804.    int    upper               OF((char *s));                     /* tops20.c */
  1805.    int    enquote             OF((char *s));                     /* tops20.c */
  1806.    int    dequote             OF((char *s));                     /* tops20.c */
  1807.    int    fnlegal             OF(()); /* error if prototyped? */ /* tops20.c */
  1808. #endif
  1809.  
  1810. /*---------------------------------------------------------------------------
  1811.     VM/CMS- and MVS-only functions:
  1812.   ---------------------------------------------------------------------------*/
  1813.  
  1814. #ifdef CMS_MVS
  1815.    extent getVMMVSexfield     OF((char *type, uch *ef_block, unsigned datalen));
  1816.    FILE  *vmmvs_open_infile   OF((__GPRO));                       /* vmmvs.c */
  1817.    void   close_infile        OF((__GPRO__));                     /* vmmvs.c */
  1818. #endif
  1819.  
  1820. /*---------------------------------------------------------------------------
  1821.     VMS-only functions:
  1822.   ---------------------------------------------------------------------------*/
  1823.  
  1824. #ifdef VMS
  1825.    int    check_format        OF((__GPRO));                         /* vms.c */
  1826. /* int    open_outfile        OF((__GPRO));           * (see fileio.c) vms.c */
  1827. /* int    flush               OF((__GPRO__ uch *rawbuf, unsigned size,
  1828.                                   int final_flag));   * (see fileio.c) vms.c */
  1829. #ifdef RETURN_CODES
  1830.    void   return_VMS          OF((__GPRO__ int zip_error));         /* vms.c */
  1831. #else
  1832.    void   return_VMS          OF((int zip_error));                  /* vms.c */
  1833. #endif
  1834. #ifdef VMSCLI
  1835.    ulg    vms_unzip_cmdline   OF((int *, char ***));            /* cmdline.c */
  1836.    int    VMSCLI_usage        OF((__GPRO__ int error));         /* cmdline.c */
  1837. #endif
  1838. #endif
  1839.  
  1840. /*---------------------------------------------------------------------------
  1841.     WIN32-only functions:
  1842.   ---------------------------------------------------------------------------*/
  1843.  
  1844. #ifdef WIN32
  1845.    int   IsWinNT        OF((void));                               /* win32.c */
  1846. #ifdef NTSD_EAS
  1847.    void  process_defer_NT     OF((__GPRO));                       /* win32.c */
  1848.    int   test_NTSD      OF((__GPRO__ uch *eb, unsigned eb_size,
  1849.                             uch *eb_ucptr, ulg eb_ucsize));       /* win32.c */
  1850. #  define TEST_NTSD     test_NTSD
  1851. #endif
  1852. #endif
  1853.  
  1854. /*---------------------------------------------------------------------------
  1855.     Miscellaneous/shared functions:
  1856.   ---------------------------------------------------------------------------*/
  1857.  
  1858. struct Globals *globalsCtor   OF((void));                       /* globals.c */
  1859.  
  1860. void     envargs         OF((__GPRO__ int *Pargc, char ***Pargv,
  1861.                              char *envstr, char *envstr2));     /* envargs.c */
  1862. void     mksargs         OF((int *argcp, char ***argvp));       /* envargs.c */
  1863.  
  1864. int      match           OF((char *s, char *p, int ic));          /* match.c */
  1865. int      iswild          OF((char *p));                           /* match.c */
  1866.  
  1867. #ifdef DYNALLOC_CRCTAB
  1868.    void     free_crc_table  OF((void));                          /* crctab.c */
  1869. #endif
  1870. #ifndef USE_ZLIB
  1871.    ulg near *get_crc_table  OF((void));                /* funzip.c, crctab.c */
  1872.    ulg      crc32           OF((ulg crc, ZCONST uch *buf, extent len));
  1873. #endif /* !USE_ZLIB */                        /* assembler source or crc32.c */
  1874.  
  1875. int      dateformat      OF((void));              /* currently, only msdos.c */
  1876. #ifndef WINDLL
  1877.    void  version         OF((__GPRO));                              /* local */
  1878. #endif
  1879. int      mapattr         OF((__GPRO));                              /* local */
  1880. int      mapname         OF((__GPRO__ int renamed));                /* local */
  1881. int      checkdir        OF((__GPRO__ char *pathcomp, int flag));   /* local */
  1882. char    *do_wild         OF((__GPRO__ char *wildzipfn));            /* local */
  1883. char    *GetLoadPath     OF((__GPRO));                              /* local */
  1884. #if (defined(MORE) && (defined(UNIX) || defined(VMS) || defined(__BEOS__)))
  1885.    int screenlines       OF((void));                                /* local */
  1886. #endif
  1887. #ifndef MTS /* macro in MTS */
  1888.    void  close_outfile   OF((__GPRO));                              /* local */
  1889. #endif
  1890. #ifdef TIMESTAMP
  1891.    int   stamp_file      OF((ZCONST char *fname, time_t modtime));  /* local */
  1892. #endif
  1893. #ifdef SYSTEM_SPECIFIC_CTOR
  1894.    void  SYSTEM_SPECIFIC_CTOR   OF((__GPRO));                       /* local */
  1895. #endif
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901. /************/
  1902. /*  Macros  */
  1903. /************/
  1904.  
  1905. #ifndef MAX
  1906. #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  1907. #endif
  1908. #ifndef MIN
  1909. #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  1910. #endif
  1911.  
  1912. #ifdef DEBUG
  1913. #  define Trace(x)   fprintf x
  1914. #else
  1915. #  define Trace(x)
  1916. #endif
  1917.  
  1918. #ifdef DEBUG_TIME
  1919. #  define TTrace(x)  fprintf x
  1920. #else
  1921. #  define TTrace(x)
  1922. #endif
  1923.  
  1924. #ifdef NO_DEBUG_IN_MACROS
  1925. #  define MTrace(x)
  1926. #else
  1927. #  define MTrace(x)  Trace(x)
  1928. #endif
  1929.  
  1930. #if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
  1931. #  define ToLower(x)   ((char)(isupper((int)x)? tolower((int)x) : x))
  1932. #else
  1933. #  define ToLower      tolower          /* assumed "smart"; used in match() */
  1934. #endif
  1935.  
  1936. #ifdef USE_STRM_INPUT
  1937.    /* ``Replace'' the unbuffered UNIX style I/O function with similar
  1938.     * standard C functions from <stdio.h>.
  1939.     */
  1940. #  define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
  1941. #  define lseek(fd,o,w) fseek((FILE *)(fd),(o),(w))
  1942. #  define close(fd) fclose((FILE *)(fd))
  1943. #endif /* USE_STRM_INPUT */
  1944.  
  1945. /* The return value of the Info() "macro function" is never checked in
  1946.  * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
  1947.  * Info() definition for "FUNZIP" would have to be corrected:
  1948.  * #define Info(buf,flag,sprf_arg) \
  1949.  *      (fprintf((flag)&1? stderr : stdout, \
  1950.  *               (char *)(sprintf sprf_arg, (buf))) == EOF)
  1951.  */
  1952. #ifndef Info   /* may already have been defined for redirection */
  1953. #  ifdef FUNZIP
  1954. #    define Info(buf,flag,sprf_arg) \
  1955.      fprintf((flag)&1? stderr : stdout, (char *)(sprintf sprf_arg, (buf)))
  1956. #  else
  1957. #    ifdef INT_SPRINTF  /* optimized version for "int sprintf()" flavour */
  1958. #      define Info(buf,flag,sprf_arg) \
  1959.        (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
  1960. #    else          /* generic version, does not use sprintf() return value */
  1961. #      define Info(buf,flag,sprf_arg) \
  1962.        (*G.message)((zvoid *)&G, (uch *)(buf), \
  1963.                      (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
  1964. #    endif
  1965. #  endif
  1966. #endif /* !Info */
  1967.  
  1968. /*  The following macros wrappers around the fnfilter function are used many
  1969.  *  times to prepare archive entry names or name components for displaying
  1970.  *  listings and (warning/error) messages. They use sections in the upper half
  1971.  *  of 'slide' as buffer, since their output is normally fed through the
  1972.  *  Info() macro with 'slide' (the start of this area) as message buffer.
  1973.  */
  1974. #define FnFilter1(fname)  fnfilter((fname), slide + (WSIZE>>1))
  1975. #define FnFilter2(fname)  fnfilter((fname), slide + ((WSIZE>>1) + (WSIZE>>2)))
  1976.  
  1977. #ifndef FUNZIP   /* used only in inflate.c */
  1978. #  define MESSAGE(str,len,flag)  (*G.message)((zvoid *)&G,(str),(len),(flag))
  1979. #endif
  1980.  
  1981. #if 0            /* Optimization: use the (const) result of crc32(0L,NULL,0) */
  1982. #  define CRCVAL_INITIAL  crc32(0L, NULL, 0)
  1983. #else
  1984. #  define CRCVAL_INITIAL  0L
  1985. #endif
  1986.  
  1987. #ifndef TEST_NTSD               /* "NTSD valid?" checking function */
  1988. #  define TEST_NTSD     NULL    /*   ... is not available */
  1989. #endif
  1990.  
  1991. /*
  1992.  *  Seek to the block boundary of the block which includes abs_offset,
  1993.  *  then read block into input buffer and set pointers appropriately.
  1994.  *  If block is already in the buffer, just set the pointers.  This macro
  1995.  *  is used by uz_end_central (process.c), zi_end_central (zipinfo.c) and
  1996.  *  do_string (fileio.c).  A slightly modified version is embedded within
  1997.  *  extract_or_test_files (extract.c).  readbyte() and readbuf() (fileio.c)
  1998.  *  are compatible.  NOTE THAT abs_offset is intended to be the "proper off-
  1999.  *  set" (i.e., if there were no extra bytes prepended); cur_zipfile_bufstart
  2000.  *  contains the corrected offset.
  2001.  *
  2002.  *  Since ZLSEEK is never used during decompression, it is safe to use the
  2003.  *  slide[] buffer for the error message.
  2004.  *
  2005.  *  The awkward "%cbs_offset" construct is provided for the obnoxious Solaris
  2006.  *  compiler, which wants to do macro substitution inside strings.
  2007.  */
  2008.  
  2009. #ifndef ZLSEEK
  2010. #  ifdef USE_STRM_INPUT
  2011. #    define _ZLS_RELOAD(abs_offset) {\
  2012.          MTrace((stderr, "ZLSEEK: %cbs_offset = %ld, G.extra_bytes = %ld\n",\
  2013.            'a', (abs_offset), G.extra_bytes));\
  2014.          fseek(G.zipfd,(LONGINT)bufstart,SEEK_SET);\
  2015.          G.cur_zipfile_bufstart = ftell(G.zipfd);\
  2016.          MTrace((stderr,\
  2017.            "       request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",\
  2018.            request, ((abs_offset)+G.extra_bytes), inbuf_offset));\
  2019.          MTrace((stderr, "       bufstart = %ld, cur_zipfile_bufstart = %ld\n",\
  2020.            bufstart, G.cur_zipfile_bufstart));\
  2021.          if ((G.incnt = fread((char *)G.inbuf,1,INBUFSIZ,G.zipfd)) <= 0)\
  2022.              return(PK_EOF);\
  2023.          G.inptr = G.inbuf + (int)inbuf_offset;\
  2024.          G.incnt -= (int)inbuf_offset;\
  2025.      }
  2026. #  else /* !USE_STRM_INPUT */
  2027. #    define _ZLS_RELOAD(abs_offset) {\
  2028.          MTrace((stderr, "ZLSEEK: %cbs_offset = %ld, G.extra_bytes = %ld\n",\
  2029.            'a', (abs_offset), G.extra_bytes));\
  2030.          G.cur_zipfile_bufstart = lseek(G.zipfd,(LONGINT)bufstart,SEEK_SET);\
  2031.          MTrace((stderr,\
  2032.            "       request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",\
  2033.            request, ((abs_offset)+G.extra_bytes), inbuf_offset));\
  2034.          MTrace((stderr, "       bufstart = %ld, cur_zipfile_bufstart = %ld\n",\
  2035.            bufstart, G.cur_zipfile_bufstart));\
  2036.          if ((G.incnt = read(G.zipfd,(char *)G.inbuf,INBUFSIZ)) <= 0)\
  2037.              return(PK_EOF);\
  2038.          G.inptr = G.inbuf + (int)inbuf_offset;\
  2039.          G.incnt -= (int)inbuf_offset;\
  2040.      }
  2041. #  endif /* ?USE_STRM_INPUT */
  2042.  
  2043. #  define ZLSEEK(abs_offset) {\
  2044.        LONGINT request = (abs_offset) + G.extra_bytes;\
  2045.        LONGINT inbuf_offset = request % INBUFSIZ;\
  2046.        LONGINT bufstart = request - inbuf_offset;\
  2047. \
  2048.        if (request < 0) {\
  2049.            Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),\
  2050.              G.zipfn, LoadFarString(ReportMsg)));\
  2051.            return(PK_BADERR);\
  2052.        } else if (bufstart != G.cur_zipfile_bufstart)\
  2053.            _ZLS_RELOAD(abs_offset)\
  2054.        else {\
  2055.            G.incnt += (G.inptr-G.inbuf) - (int)inbuf_offset;\
  2056.            G.inptr = G.inbuf + (int)inbuf_offset;\
  2057.        }\
  2058.    }
  2059. #endif /* !ZLSEEK */
  2060.  
  2061. #define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
  2062.   {error_in_archive=error; if(error>1) return error;}
  2063.  
  2064. /*
  2065.  *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  2066.  *  and unzip.c in several functions.
  2067.  *
  2068.  *  macro SKIP_(length)
  2069.  *      ush length;
  2070.  *  {
  2071.  *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  2072.  *          error_in_archive = error;   /-* might be warning *-/
  2073.  *          if (error > 1)              /-* fatal *-/
  2074.  *              return (error);
  2075.  *      }
  2076.  *  }
  2077.  *
  2078.  */
  2079.  
  2080.  
  2081. #ifdef FUNZIP
  2082. #  define FLUSH(w)  flush(__G__ (ulg)(w))
  2083. #  define NEXTBYTE  getc(G.in)   /* redefined in crypt.h if full version */
  2084. #else
  2085. #  define FLUSH(w)  if (G.mem_mode) memflush(__G__ redirSlide,(ulg)(w)); \
  2086.      else flush(__G__ redirSlide,(ulg)(w),0)
  2087. #  define NEXTBYTE  (--G.incnt >= 0 ? (int)(*G.inptr++) : readbyte(__G))
  2088. #endif
  2089.  
  2090.  
  2091. #define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
  2092.   while (G.bits_left<=8*(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
  2093.   G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
  2094.   zdest=(shrint)((ush)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
  2095.   G.bits_left-=nbits;}
  2096.  
  2097. /*
  2098.  * macro READBITS(nbits,zdest)    * only used by unreduce and unshrink *
  2099.  *  {
  2100.  *      if (nbits > G.bits_left) {  * fill G.bitbuf, 8*sizeof(ulg) bits *
  2101.  *          int temp;
  2102.  *
  2103.  *          G.zipeof = 1;
  2104.  *          while (G.bits_left <= 8*(sizeof(G.bitbuf)-1) &&
  2105.  *                 (temp = NEXTBYTE) != EOF) {
  2106.  *              G.bitbuf |= (ulg)temp << G.bits_left;
  2107.  *              G.bits_left += 8;
  2108.  *              G.zipeof = 0;
  2109.  *          }
  2110.  *      }
  2111.  *      zdest = (shrint)((ush)G.bitbuf & mask_bits[nbits]);
  2112.  *      G.bitbuf >>= nbits;
  2113.  *      G.bits_left -= nbits;
  2114.  *  }
  2115.  *
  2116.  */
  2117.  
  2118.  
  2119. /* GRR:  should change name to STRLOWER and use StringLower if possible */
  2120.  
  2121. /*
  2122.  *  Copy the zero-terminated string in str1 into str2, converting any
  2123.  *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  2124.  *  as well, of course.  str1 and str2 may be the same character array.
  2125.  */
  2126. #ifdef __human68k__
  2127. #  define TOLOWER(str1, str2) \
  2128.    { \
  2129.        char *p=(str1), *q=(str2); \
  2130.        uch c; \
  2131.        while ((c = *p++) != '\0') { \
  2132.            if (iskanji(c)) { \
  2133.                if (*p == '\0') \
  2134.                    break; \
  2135.                *q++ = c; \
  2136.                *q++ = *p++; \
  2137.            } else \
  2138.                *q++ = isupper(c) ? tolower(c) : c; \
  2139.        } \
  2140.        *q = '\0'; \
  2141.    }
  2142. #else
  2143. #  define TOLOWER(str1, str2) \
  2144.    { \
  2145.        char  *p, *q; \
  2146.        p = (str1) - 1; \
  2147.        q = (str2); \
  2148.        while (*++p) \
  2149.            *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
  2150.        *q = '\0'; \
  2151.    }
  2152. #endif
  2153. /*
  2154.  *  NOTES:  This macro makes no assumptions about the characteristics of
  2155.  *    the tolower() function or macro (beyond its existence), nor does it
  2156.  *    make assumptions about the structure of the character set (i.e., it
  2157.  *    should work on EBCDIC machines, too).  The fact that either or both
  2158.  *    of isupper() and tolower() may be macros has been taken into account;
  2159.  *    watch out for "side effects" (in the C sense) when modifying this
  2160.  *    macro.
  2161.  */
  2162.  
  2163. #ifndef foreign
  2164. #  define foreign(c)  (c)
  2165. #endif
  2166.  
  2167. #ifndef native
  2168. #  define native(c)   (c)
  2169. #  define A_TO_N(str1)
  2170. #else
  2171. #  ifndef NATIVE
  2172. #    define NATIVE     "native chars"
  2173. #  endif
  2174. #  define A_TO_N(str1) {register uch *p;\
  2175.      for (p=(uch *)(str1); *p; p++) *p=native(*p);}
  2176. #endif
  2177. /*
  2178.  *  Translate the zero-terminated string in str1 from ASCII to the native
  2179.  *  character set. The translation is performed in-place and uses the
  2180.  *  "native" macro to translate each character.
  2181.  *
  2182.  *  NOTE:  Using the "native" macro means that is it the only part of unzip
  2183.  *    which knows which translation table (if any) is actually in use to
  2184.  *    produce the native character set.  This makes adding new character set
  2185.  *    translation tables easy, insofar as all that is needed is an appropriate
  2186.  *    "native" macro definition and the translation table itself.  Currently,
  2187.  *    the only non-ASCII native character set implemented is EBCDIC, but this
  2188.  *    may not always be so.
  2189.  */
  2190.  
  2191.  
  2192. /* default setup for internal codepage: assume ISO 8859-1 compatibility!! */
  2193. #if (!defined(NATIVE) && !defined(CRTL_CP_IS_ISO) && !defined(CRTL_CP_IS_OEM))
  2194. #  define CRTL_CP_IS_ISO
  2195. #endif
  2196.  
  2197.  
  2198. /*  Translate "extended ASCII" chars (OEM coding for DOS and OS/2; else
  2199.  *  ISO-8859-1 [ISO Latin 1, Win Ansi,...]) into the internal "native"
  2200.  *  code page.  As with A_TO_N(), conversion is done in place.
  2201.  */
  2202. #ifndef _ISO_INTERN
  2203. #  ifdef CRTL_CP_IS_OEM
  2204. #    ifndef IZ_ISO2OEM_ARRAY
  2205. #      define IZ_ISO2OEM_ARRAY
  2206. #    endif
  2207. #    define _ISO_INTERN(str1) {register uch *p;\
  2208.        for (p=(uch *)(str1); *p; p++)\
  2209.          *p = native((*p & 0x80) ? iso2oem[*p & 0x7f] : *p);}
  2210. #  else
  2211. #    define _ISO_INTERN(str1)   A_TO_N(str1)
  2212. #  endif
  2213. #endif
  2214.  
  2215. #ifndef _OEM_INTERN
  2216. #  ifdef CRTL_CP_IS_OEM
  2217. #    define _OEM_INTERN(str1)   A_TO_N(str1)
  2218. #  else
  2219. #    ifndef IZ_OEM2ISO_ARRAY
  2220. #      define IZ_OEM2ISO_ARRAY
  2221. #    endif
  2222. #    define _OEM_INTERN(str1) {register uch *p;\
  2223.        for (p=(uch *)(str1); *p; p++)\
  2224.          *p = native((*p & 0x80) ? oem2iso[*p & 0x7f] : *p);}
  2225. #  endif
  2226. #endif
  2227.  
  2228. #ifndef STR_TO_ISO
  2229. #  ifdef CRTL_CP_IS_ISO
  2230. #    define STR_TO_ISO          strcpy
  2231. #  else
  2232. #    define STR_TO_ISO          str2iso
  2233. #    define NEED_STR2ISO
  2234. #  endif
  2235. #endif
  2236.  
  2237. #ifndef STR_TO_OEM
  2238. #  ifdef CRTL_CP_IS_OEM
  2239. #    define STR_TO_OEM          strcpy
  2240. #  else
  2241. #    define STR_TO_OEM          str2oem
  2242. #    define NEED_STR2OEM
  2243. #  endif
  2244. #endif
  2245.  
  2246. #if (!defined(INTERN_TO_ISO) && !defined(ASCII2ISO))
  2247. #  ifdef CRTL_CP_IS_OEM
  2248.      /* know: "ASCII" is "OEM" */
  2249. #    define ASCII2ISO(c) (((c) & 0x80) ? oem2iso[(c) & 0x7f] : (c))
  2250. #    if (defined(NEED_STR2ISO) && !defined(CRYP_USES_OEM2ISO))
  2251. #      define CRYP_USES_OEM2ISO
  2252. #    endif
  2253. #  else
  2254.      /* assume: "ASCII" is "ISO-ANSI" */
  2255. #    define ASCII2ISO(c) (c)
  2256. #  endif
  2257. #endif
  2258.  
  2259. #if (!defined(INTERN_TO_OEM) && !defined(ASCII2OEM))
  2260. #  ifdef CRTL_CP_IS_OEM
  2261.      /* know: "ASCII" is "OEM" */
  2262. #    define ASCII2OEM(c) (c)
  2263. #  else
  2264.      /* assume: "ASCII" is "ISO-ANSI" */
  2265. #    define ASCII2OEM(c) (((c) & 0x80) ? iso2oem[(c) & 0x7f] : (c))
  2266. #    if (defined(NEED_STR2OEM) && !defined(CRYP_USES_ISO2OEM))
  2267. #      define CRYP_USES_ISO2OEM
  2268. #    endif
  2269. #  endif
  2270. #endif
  2271.  
  2272. /* codepage conversion setup for testp() in crypt.c */
  2273. #ifdef CRTL_CP_IS_ISO
  2274. #  ifndef STR_TO_CP2
  2275. #    define STR_TO_CP2  STR_TO_OEM
  2276. #  endif
  2277. #else
  2278. #  ifdef CRTL_CP_IS_OEM
  2279. #    ifndef STR_TO_CP2
  2280. #      define STR_TO_CP2  STR_TO_ISO
  2281. #    endif
  2282. #  else /* native internal CP is neither ISO nor OEM */
  2283. #    ifndef STR_TO_CP1
  2284. #      define STR_TO_CP1  STR_TO_ISO
  2285. #    endif
  2286. #    ifndef STR_TO_CP2
  2287. #      define STR_TO_CP2  STR_TO_OEM
  2288. #    endif
  2289. #  endif
  2290. #endif
  2291.  
  2292.  
  2293. /* Convert filename (and file comment string) into "internal" charset.
  2294.  * This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
  2295.  * codepage when made on
  2296.  *  -> DOS (this includes 16-bit Windows 3.1)  (FS_FAT_)
  2297.  *  -> OS/2                                    (FS_HPFS_)
  2298.  *  -> Win95/WinNT with Nico Mak's WinZip      (FS_NTFS_ && hostver == "5.0")
  2299.  *
  2300.  * All other ports are assumed to code zip entry filenames in ISO 8859-1.
  2301.  */
  2302. #ifndef Ext_ASCII_TO_Native
  2303. #  define Ext_ASCII_TO_Native(string, hostnum, hostver) \
  2304.     if ((hostnum) == FS_FAT_ || (hostnum) == FS_HPFS_ || \
  2305.         ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
  2306.         _OEM_INTERN((string)); \
  2307.     } else { \
  2308.         _ISO_INTERN((string)); \
  2309.     }
  2310. #endif
  2311.  
  2312.  
  2313.  
  2314. /**********************/
  2315. /*  Global constants  */
  2316. /**********************/
  2317.  
  2318.    extern ZCONST ush near  mask_bits[];
  2319.    extern char     *fnames[2];
  2320.  
  2321. #ifdef EBCDIC
  2322.    extern ZCONST uch ebcdic[];
  2323. #endif
  2324. #ifdef IZ_ISO2OEM_ARRAY
  2325.    extern ZCONST uch Far iso2oem[];
  2326. #endif
  2327. #ifdef IZ_OEM2ISO_ARRAY
  2328.    extern ZCONST uch Far oem2iso[];
  2329. #endif
  2330.  
  2331.    extern char Far  CentSigMsg[];
  2332.    extern char Far  EndSigMsg[];
  2333.    extern char Far  SeekMsg[];
  2334.    extern char Far  FilenameNotMatched[];
  2335.    extern char Far  ExclFilenameNotMatched[];
  2336.    extern char Far  ReportMsg[];
  2337.  
  2338. #ifndef SFX
  2339.    extern char Far  CompiledWith[];
  2340. #endif /* !SFX */
  2341.  
  2342.  
  2343.  
  2344. /***********************************/
  2345. /*  Global (shared?) RTL variables */
  2346. /***********************************/
  2347.  
  2348. #ifdef DECLARE_ERRNO
  2349.    extern int       errno;
  2350. #endif
  2351.  
  2352.  
  2353. #endif /* !__unzpriv_h */
  2354.