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