Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3124 lines
107KB

  1. /*
  2. Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2009-Jan-02 or later
  4. (the contents of which are also included in unzip.h) for terms of use.
  5. If, for some reason, all these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  7. */
  8. /*---------------------------------------------------------------------------
  9. unzpriv.h
  10. This header file contains private (internal) macros, typedefs, prototypes
  11. and global-variable declarations used by all of the UnZip source files.
  12. In a prior life it was part of the main unzip.h header, but now it is only
  13. included by that header if UNZIP_INTERNAL is defined.
  14. ---------------------------------------------------------------------------*/
  15. #ifndef __unzpriv_h /* prevent multiple inclusions */
  16. #define __unzpriv_h
  17. /* First thing: Signal all following code that we compile UnZip utilities! */
  18. #ifndef UNZIP
  19. # define UNZIP
  20. #endif
  21. /* GRR 960204: MORE defined here in preparation for removal altogether */
  22. #ifndef MORE
  23. # ifndef RISCOS
  24. # define MORE
  25. # endif
  26. #endif
  27. /* fUnZip should never need to be reentrant */
  28. #ifdef FUNZIP
  29. # ifdef REENTRANT
  30. # undef REENTRANT
  31. # endif
  32. # ifdef DLL
  33. # undef DLL
  34. # endif
  35. # ifdef SFX /* fUnZip is NOT the sfx stub! */
  36. # undef SFX
  37. # endif
  38. # ifdef USE_BZIP2 /* fUnZip does not support bzip2 decompression */
  39. # undef USE_BZIP2
  40. # endif
  41. #endif
  42. #if (defined(USE_ZLIB) && !defined(HAVE_ZL_INFLAT64) && !defined(NO_DEFLATE64))
  43. /* zlib does not (yet?) provide Deflate64(tm) support */
  44. # define NO_DEFLATE64
  45. #endif
  46. #ifdef NO_DEFLATE64
  47. /* disable support for Deflate64(tm) */
  48. # ifdef USE_DEFLATE64
  49. # undef USE_DEFLATE64
  50. # endif
  51. #else
  52. /* enable Deflate64(tm) support unless compiling for SFX stub */
  53. # if (!defined(USE_DEFLATE64) && !defined(SFX))
  54. # define USE_DEFLATE64
  55. # endif
  56. #endif
  57. /* disable bzip2 support for SFX stub, unless explicitly requested */
  58. #if (defined(SFX) && !defined(BZIP2_SFX) && defined(USE_BZIP2))
  59. # undef USE_BZIP2
  60. #endif
  61. #if (defined(NO_VMS_TEXT_CONV) || defined(VMS))
  62. # ifdef VMS_TEXT_CONV
  63. # undef VMS_TEXT_CONV
  64. # endif
  65. #else
  66. # if (!defined(VMS_TEXT_CONV) && !defined(SFX))
  67. # define VMS_TEXT_CONV
  68. # endif
  69. #endif
  70. /* Enable -B option per default on specific systems, to allow backing up
  71. * files that would be overwritten.
  72. * (This list of systems must be kept in sync with the list of systems
  73. * that add the B_flag to the UzpOpts structure, see unzip.h.)
  74. */
  75. #if (!defined(NO_UNIXBACKUP) && !defined(UNIXBACKUP))
  76. # if defined(UNIX) || defined(OS2) || defined(WIN32)
  77. # define UNIXBACKUP
  78. # endif
  79. #endif
  80. #if (defined(DLL) && !defined(REENTRANT))
  81. # define REENTRANT
  82. #endif
  83. #if (!defined(DYNAMIC_CRC_TABLE) && !defined(FUNZIP))
  84. # define DYNAMIC_CRC_TABLE
  85. #endif
  86. #if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
  87. # ifndef DYNALLOC_CRCTAB
  88. # define DYNALLOC_CRCTAB
  89. # endif
  90. #endif
  91. /*---------------------------------------------------------------------------
  92. OS-dependent configuration for UnZip internals
  93. ---------------------------------------------------------------------------*/
  94. /* Some compiler distributions for Win32/i386 systems try to emulate
  95. * a Unix (POSIX-compatible) environment.
  96. */
  97. #if (defined(WIN32) && defined(UNIX))
  98. /* UnZip does not support merging both ports in a single executable. */
  99. # if (defined(FORCE_WIN32_OVER_UNIX) && defined(FORCE_UNIX_OVER_WIN32))
  100. /* conflicting choice requests -> we prefer the Win32 environment */
  101. # undef FORCE_UNIX_OVER_WIN32
  102. # endif
  103. # ifdef FORCE_WIN32_OVER_UNIX
  104. /* native Win32 support was explicitly requested... */
  105. # undef UNIX
  106. # else
  107. /* use the POSIX (Unix) emulation features by default... */
  108. # undef WIN32
  109. # endif
  110. #endif
  111. /* bad or (occasionally?) missing stddef.h: */
  112. #if (defined(M_XENIX) || defined(DNIX))
  113. # define NO_STDDEF_H
  114. #endif
  115. #if (defined(M_XENIX) && !defined(M_UNIX)) /* SCO Xenix only, not SCO Unix */
  116. # define SCO_XENIX
  117. # define NO_LIMITS_H /* no limits.h, but MODERN defined */
  118. # define NO_UID_GID /* no uid_t/gid_t */
  119. # define size_t int
  120. #endif
  121. #ifdef realix /* Modcomp Real/IX, real-time SysV.3 variant */
  122. # define SYSV
  123. # define NO_UID_GID /* no uid_t/gid_t */
  124. #endif
  125. #if (defined(_AIX) && !defined(_ALL_SOURCE))
  126. # define _ALL_SOURCE
  127. #endif
  128. #if defined(apollo) /* defines __STDC__ */
  129. # define NO_STDLIB_H
  130. #endif
  131. #ifdef DNIX
  132. # define SYSV
  133. # define SHORT_NAMES /* 14-char limitation on path components */
  134. /* # define FILENAME_MAX 14 */
  135. # define FILENAME_MAX NAME_MAX /* GRR: experiment */
  136. #endif
  137. #if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
  138. # ifndef SYSV
  139. # define SYSV
  140. # endif
  141. #endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
  142. #if (defined(M_SYSV) || defined(M_SYS5))
  143. # ifndef SYSV
  144. # define SYSV
  145. # endif
  146. #endif /* M_SYSV || M_SYS5 */
  147. /* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
  148. #if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
  149. # ifndef SYSV
  150. # define SYSV
  151. # endif
  152. #endif /* __SVR4 || __svr4__ || sgi || __hpux */
  153. #if (defined(LINUX) || defined(__QNX__))
  154. # ifndef SYSV
  155. # define SYSV
  156. # endif
  157. #endif /* LINUX || __QNX__ */
  158. #if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
  159. # if (!defined(BSD) && !defined(SYSV))
  160. # define BSD
  161. # endif
  162. #endif /* ultrix || __ultrix || bsd4_2 */
  163. #if (defined(sun) || defined(pyr) || defined(CONVEX))
  164. # if (!defined(BSD) && !defined(SYSV))
  165. # define BSD
  166. # endif
  167. #endif /* sun || pyr || CONVEX */
  168. #ifdef pyr /* Pyramid: has BSD and AT&T "universes" */
  169. # ifdef BSD
  170. # define pyr_bsd
  171. # define USE_STRINGS_H /* instead of more common string.h */
  172. # define ZMEM /* ZMEM now uses bcopy/bzero: not in AT&T universe */
  173. # endif /* (AT&T memcpy claimed to be very slow, though) */
  174. # define DECLARE_ERRNO
  175. #endif /* pyr */
  176. /* stat() bug for Borland, VAX C RTL, and Atari ST MiNT on TOS
  177. * filesystems: returns 0 for wildcards! (returns 0xffffffff on Minix
  178. * filesystem or `U:' drive under Atari MiNT.) Watcom C was previously
  179. * included on this list; it would be good to know what version the problem
  180. * was fixed at, if it did exist. */
  181. #if (defined(__TURBOC__) && !defined(WIN32))
  182. /*# define WILD_STAT_BUG*/
  183. #endif
  184. #if (defined(VMS) || defined(__MINT__))
  185. # define WILD_STAT_BUG
  186. #endif
  187. /*---------------------------------------------------------------------------
  188. OS-dependent includes
  189. ---------------------------------------------------------------------------*/
  190. /*---------------------------------------------------------------------------
  191. API (DLL) section:
  192. ---------------------------------------------------------------------------*/
  193. #ifdef DLL
  194. # define MAIN UZ_EXP UzpMain /* was UzpUnzip */
  195. # ifdef OS2DLL
  196. # undef Info
  197. # define REDIRECTC(c) varputchar(__G__ c)
  198. # define REDIRECTPRINT(buf,size) varmessage(__G__ buf, size)
  199. # define FINISH_REDIRECT() finish_REXX_redirect(__G)
  200. # else
  201. # define REDIRECTC(c)
  202. # define REDIRECTPRINT(buf,size) 0
  203. # define FINISH_REDIRECT() close_redirect(__G)
  204. # endif
  205. #endif
  206. /*---------------------------------------------------------------------------
  207. Acorn RISCOS section:
  208. ---------------------------------------------------------------------------*/
  209. #ifdef RISCOS
  210. # include "acorn/riscos.h"
  211. #endif
  212. /*---------------------------------------------------------------------------
  213. Amiga section:
  214. ---------------------------------------------------------------------------*/
  215. #ifdef AMIGA
  216. # include "amiga/amiga.h"
  217. #endif
  218. /*---------------------------------------------------------------------------
  219. AOS/VS section (somewhat similar to Unix, apparently):
  220. ---------------------------------------------------------------------------*/
  221. #ifdef AOS_VS
  222. # ifdef __FILEIO_C
  223. # include "aosvs/aosvs.h"
  224. # endif
  225. #endif
  226. /*---------------------------------------------------------------------------
  227. Atari ST section:
  228. ---------------------------------------------------------------------------*/
  229. #ifdef ATARI
  230. # include <time.h>
  231. # include <stat.h>
  232. # include <fcntl.h>
  233. # include <limits.h>
  234. # define SYMLINKS
  235. # define EXE_EXTENSION ".tos"
  236. # ifndef DATE_FORMAT
  237. # define DATE_FORMAT DF_DMY
  238. # endif
  239. # define DIR_END '/'
  240. # define INT_SPRINTF
  241. # define timezone _timezone
  242. # define lenEOL 2
  243. # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
  244. # undef SHORT_NAMES
  245. # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
  246. # define TIMESTAMP
  247. # endif
  248. #endif
  249. /*---------------------------------------------------------------------------
  250. AtheOS section:
  251. ---------------------------------------------------------------------------*/
  252. #ifdef __ATHEOS__
  253. # include "atheos/athcfg.h"
  254. #endif
  255. /*---------------------------------------------------------------------------
  256. BeOS section:
  257. ---------------------------------------------------------------------------*/
  258. #ifdef __BEOS__
  259. # include "beos/beocfg.h"
  260. #endif
  261. /*---------------------------------------------------------------------------
  262. Human68k/X680x0 section:
  263. ---------------------------------------------------------------------------*/
  264. #ifdef __human68k__
  265. /* DO NOT DEFINE DOS_OS2 HERE! If Human68k is so much */
  266. /* like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
  267. # if (!defined(_MBCS) && !defined(NO_MBCS))
  268. /* enable MBCS support by default for this system */
  269. # define _MBCS
  270. # endif
  271. # if (defined(_MBCS) && defined(NO_MBCS))
  272. /* disable MBCS support when explicitely requested */
  273. # undef _MBCS
  274. # endif
  275. # include <time.h>
  276. # include <fcntl.h>
  277. # include <io.h>
  278. # include <conio.h>
  279. # include <sys/stat.h>
  280. # ifdef HAVE_MBSTRING_H
  281. # include <mbstring.h>
  282. # endif
  283. # ifdef HAVE_MBCTYPE_H
  284. # include <mbctype.h>
  285. # else
  286. # ifndef _ismbblead
  287. # define _ismbblead(c) (0x80 <= (c) && ((c) < 0xa0 || 0xe0 <= (c)))
  288. # endif
  289. # endif
  290. # ifndef DATE_FORMAT
  291. # define DATE_FORMAT DF_YMD /* Japanese standard */
  292. # endif
  293. # define lenEOL 1
  294. # define PutNativeEOL *q++ = native(LF);
  295. # define INT_SPRINTF
  296. # define SYMLINKS
  297. # ifdef SFX
  298. # define MAIN main_sfx
  299. # endif
  300. #endif
  301. /*---------------------------------------------------------------------------
  302. Mac section:
  303. ---------------------------------------------------------------------------*/
  304. #ifdef MACOS
  305. # include "maccfg.h"
  306. #endif /* MACOS */
  307. /*---------------------------------------------------------------------------
  308. MS-DOS, OS/2, FLEXOS section:
  309. ---------------------------------------------------------------------------*/
  310. #ifdef WINDLL
  311. # ifdef MORE
  312. # undef MORE
  313. # endif
  314. # ifdef OS2_EAS
  315. # undef OS2_EAS
  316. # endif
  317. #endif
  318. #if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
  319. # ifndef MSC
  320. # define MSC /* This should work for older MSC, too! */
  321. # endif
  322. #endif
  323. #if (defined(MSDOS) || defined(OS2) || defined(FLEXOS))
  324. # include <sys/types.h> /* off_t, time_t, dev_t, ... */
  325. # include <sys/stat.h>
  326. # include <io.h> /* lseek(), open(), setftime(), dup(), creat() */
  327. # include <time.h> /* localtime() */
  328. # include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
  329. # ifdef OS2 /* defined for all OS/2 compilers */
  330. # include "os2/os2cfg.h"
  331. # else
  332. # ifdef FLEXOS
  333. # include "flexos/flxcfg.h"
  334. # else
  335. # include "msdos/doscfg.h"
  336. # endif
  337. # endif
  338. # if (defined(_MSC_VER) && (_MSC_VER == 700) && !defined(GRR))
  339. /*
  340. * ARGH. MSC 7.0 libraries think times are based on 1899 Dec 31 00:00, not
  341. * 1970 Jan 1 00:00. So we have to diddle time_t's appropriately: add or
  342. * subtract 70 years' worth of seconds; i.e., number of days times 86400;
  343. * i.e., (70*365 regular days + 17 leap days + 1 1899 day) * 86400 ==
  344. * (25550 + 17 + 1) * 86400 == 2209075200 seconds. We know time_t is an
  345. * unsigned long (ulg) on the only system with this bug.
  346. */
  347. # define TIMET_TO_NATIVE(x) (x) += (ulg)2209075200L;
  348. # define NATIVE_TO_TIMET(x) (x) -= (ulg)2209075200L;
  349. # endif
  350. # if (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0450))
  351. # define timezone _timezone
  352. # endif
  353. # if (defined(__GO32__) || defined(FLEXOS))
  354. # define DIR_END '/'
  355. # else
  356. # define DIR_END '\\' /* OS uses '\\' as directory separator */
  357. # define DIR_END2 '/' /* also check for '/' (RTL may convert) */
  358. # endif
  359. # ifdef DATE_FORMAT
  360. # undef DATE_FORMAT
  361. # endif
  362. # define DATE_FORMAT dateformat()
  363. # define lenEOL 2
  364. # define PutNativeEOL {*q++ = native(CR); *q++ = native(LF);}
  365. # if (!defined(NO_EF_UT_TIME) && !defined(USE_EF_UT_TIME))
  366. # define USE_EF_UT_TIME
  367. # endif
  368. #endif /* MSDOS || OS2 || FLEXOS */
  369. /*---------------------------------------------------------------------------
  370. MTS section (piggybacks UNIX, I think):
  371. ---------------------------------------------------------------------------*/
  372. #ifdef MTS
  373. # include <sys/types.h> /* off_t, time_t, dev_t, ... */
  374. # include <sys/stat.h>
  375. # include <sys/file.h> /* MTS uses this instead of fcntl.h */
  376. # include <timeb.h>
  377. # include <time.h>
  378. # include <unix.h> /* some important non-ANSI routines */
  379. # define mkdir(s,n) (-1) /* no "make directory" capability */
  380. # define EBCDIC /* set EBCDIC conversion on */
  381. # define NO_STRNICMP /* unzip's is as good the one in MTS */
  382. # define USE_FWRITE
  383. # define close_outfile() fclose(G.outfile) /* can't set time on files */
  384. # define umask(n) /* don't have umask() on MTS */
  385. # define FOPWT "w" /* open file for writing in TEXT mode */
  386. # ifndef DATE_FORMAT
  387. # define DATE_FORMAT DF_MDY
  388. # endif
  389. # define lenEOL 1
  390. # define PutNativeEOL *q++ = native(LF);
  391. #endif /* MTS */
  392. /*---------------------------------------------------------------------------
  393. Novell Netware NLM section
  394. ---------------------------------------------------------------------------*/
  395. #ifdef NLM
  396. # include "netware/nlmcfg.h"
  397. #endif
  398. /*---------------------------------------------------------------------------
  399. QDOS section
  400. ---------------------------------------------------------------------------*/
  401. #ifdef QDOS
  402. # define DIRENT
  403. # include <fcntl.h>
  404. # include <unistd.h>
  405. # include <sys/stat.h>
  406. # include <time.h>
  407. # include "qdos/izqdos.h"
  408. # ifndef DATE_FORMAT
  409. # define DATE_FORMAT DF_MDY
  410. # endif
  411. # define lenEOL 1
  412. # define PutNativeEOL *q++ = native(LF);
  413. # define DIR_END '_'
  414. # define RETURN QReturn
  415. # undef PATH_MAX
  416. # define PATH_MAX 36
  417. # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP))
  418. # define TIMESTAMP
  419. # endif
  420. # define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
  421. # define SCREENWIDTH 80
  422. #endif
  423. /*---------------------------------------------------------------------------
  424. Tandem NSK section:
  425. ---------------------------------------------------------------------------*/
  426. #ifdef TANDEM
  427. # include "tandem.h"
  428. # include <fcntl.h>
  429. # ifndef __INT32
  430. /* We are compiling with non-WIDE memory model, int = 16 bits */
  431. # ifndef INT_16BIT
  432. # define INT_16BIT /* report "int" size is 16-bit to inflate setup */
  433. # endif
  434. # ifdef USE_DEFLATE64
  435. /* Following required for 64k WSIZE of Deflate64 support */
  436. # define MED_MEM /* else OUTBUFSIZ is 64K and fails in do_string */
  437. # define INBUFSIZ 8192 /* but larger buffer for real OSes */
  438. # endif
  439. # endif
  440. /* use a single LF delimiter so that writes to 101 text files work */
  441. # define PutNativeEOL *q++ = native(LF);
  442. # define lenEOL 1
  443. # ifndef DATE_FORMAT
  444. # define DATE_FORMAT DF_DMY
  445. # endif
  446. # define SCREENLINES 25
  447. /* USE_EF_UT_TIME is set in tandem.h */
  448. # define RESTORE_UIDGID
  449. # define NO_STRNICMP
  450. #endif
  451. /*---------------------------------------------------------------------------
  452. THEOS section:
  453. ---------------------------------------------------------------------------*/
  454. #ifdef THEOS
  455. # include "theos/thscfg.h"
  456. #endif
  457. /*---------------------------------------------------------------------------
  458. TOPS-20 section:
  459. ---------------------------------------------------------------------------*/
  460. #ifdef TOPS20
  461. # include <sys/types.h> /* off_t, time_t, dev_t, ... */
  462. # include <sys/stat.h>
  463. # include <sys/param.h>
  464. # include <sys/time.h>
  465. # include <sys/timeb.h>
  466. # include <sys/file.h>
  467. # include <timex.h>
  468. # include <monsym.h> /* get amazing monsym() macro */
  469. extern int open(), close(), read();
  470. extern int stat(), unlink(), jsys(), fcntl();
  471. extern long lseek(), dup(), creat();
  472. # define strchr index /* GRR: necessary? */
  473. # define strrchr rindex
  474. # define REALLY_SHORT_SYMS
  475. # define NO_MKDIR
  476. # ifndef HAVE_STRNICMP
  477. # define NO_STRNICMP /* probably not provided by TOPS20 C RTL */
  478. # endif
  479. # define DIR_BEG '<'
  480. # define DIR_END '>'
  481. # define DIR_EXT ".directory"
  482. # ifndef DATE_FORMAT
  483. # define DATE_FORMAT DF_MDY
  484. # endif
  485. # define EXE_EXTENSION ".exe" /* just a guess... */
  486. #endif /* TOPS20 */
  487. /*---------------------------------------------------------------------------
  488. Unix section:
  489. ---------------------------------------------------------------------------*/
  490. #ifdef UNIX
  491. # include "unix/unxcfg.h"
  492. #endif /* UNIX */
  493. /*---------------------------------------------------------------------------
  494. VM/CMS and MVS section:
  495. ---------------------------------------------------------------------------*/
  496. #ifdef CMS_MVS
  497. # include "vmmvs.h"
  498. # define CLOSE_INFILE() close_infile(__G)
  499. #endif
  500. /*---------------------------------------------------------------------------
  501. VMS section:
  502. ---------------------------------------------------------------------------*/
  503. #ifdef VMS
  504. # include "vms/vmscfg.h"
  505. #endif /* VMS */
  506. /*---------------------------------------------------------------------------
  507. Win32 (Windows 95/NT) section:
  508. ---------------------------------------------------------------------------*/
  509. #if (defined(WIN32) && !defined(POCKET_UNZIP) && !defined(_WIN32_WCE))
  510. # include "win32/w32cfg.h"
  511. #endif
  512. /*---------------------------------------------------------------------------
  513. Win32 Windows CE section (also POCKET_UNZIP)
  514. ---------------------------------------------------------------------------*/
  515. #if (defined(_WIN32_WCE) || defined(POCKET_UNZIP))
  516. # include "wince/wcecfg.h"
  517. #endif
  518. /* ----------------------------------------------------------------------------
  519. MUST BE AFTER LARGE FILE INCLUDES
  520. ---------------------------------------------------------------------------- */
  521. /* This stuff calls in types and messes up large file includes. It needs to
  522. go after large file defines in local includes.
  523. I am guessing that moving them here probably broke some ports, but hey.
  524. 10/31/2004 EG */
  525. /* ----------------------------------------------------------------------------
  526. Common includes
  527. ---------------------------------------------------------------------------- */
  528. /* Some ports apply specific adjustments which must be in effect before
  529. reading the "standard" include headers.
  530. */
  531. #ifdef EFT
  532. # define Z_OFF_T off_t /* Amdahl UTS nonsense ("extended file types") */
  533. #else
  534. #if (defined(UNIX) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
  535. # define Z_OFF_T off_t /* 64bit offsets to support 2GB < zipfile size < 4GB */
  536. #else
  537. # define Z_OFF_T long long
  538. #endif
  539. #endif
  540. #ifndef ZOFF_T_DEFINED
  541. typedef Z_OFF_T zoff_t;
  542. # define ZOFF_T_DEFINED
  543. #endif
  544. #ifndef Z_STAT_DEFINED
  545. typedef struct stat z_stat;
  546. # define Z_STAT_DEFINED
  547. #endif
  548. #ifndef MINIX /* Minix needs it after all the other includes (?) */
  549. # include <stdio.h>
  550. #endif
  551. #include <ctype.h> /* skip for VMS, to use tolower() function? */
  552. #include <errno.h> /* used in mapname() */
  553. #ifdef USE_STRINGS_H
  554. # include <strings.h> /* strcpy, strcmp, memcpy, index/rindex, etc. */
  555. #else
  556. # include <string.h> /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
  557. #endif
  558. #if (defined(MODERN) && !defined(NO_LIMITS_H))
  559. # include <limits.h> /* MAX/MIN constant symbols for system types... */
  560. #endif
  561. /* this include must be down here for SysV.4, for some reason... */
  562. #include <signal.h> /* used in unzip.c, fileio.c */
  563. #ifdef MODERN
  564. # ifndef NO_STDDEF_H
  565. # include <stddef.h>
  566. # endif
  567. # ifndef NO_STDLIB_H
  568. # include <stdlib.h> /* standard library prototypes, malloc(), etc. */
  569. # endif
  570. typedef size_t extent;
  571. #else /* !MODERN */
  572. # ifndef AOS_VS /* mostly modern? */
  573. Z_OFF_T lseek();
  574. # ifdef VAXC /* not fully modern, but has stdlib.h and void */
  575. # include <stdlib.h>
  576. # else
  577. char *malloc();
  578. # endif /* ?VAXC */
  579. # endif /* !AOS_VS */
  580. typedef unsigned int extent;
  581. #endif /* ?MODERN */
  582. /*************/
  583. /* Defines */
  584. /*************/
  585. #define UNZIP_BZ2VERS 46
  586. #ifdef ZIP64_SUPPORT
  587. # ifdef USE_BZIP2
  588. # define UNZIP_VERSION UNZIP_BZ2VERS
  589. # else
  590. # define UNZIP_VERSION 45
  591. # endif
  592. #else
  593. #ifdef USE_DEFLATE64
  594. # define UNZIP_VERSION 21 /* compatible with PKUNZIP 4.0 */
  595. #else
  596. # define UNZIP_VERSION 20 /* compatible with PKUNZIP 2.0 */
  597. #endif
  598. #endif
  599. #define VMS_UNZIP_VERSION 42 /* if OS-needed-to-extract is VMS: can do */
  600. #if (defined(MSDOS) || defined(OS2))
  601. # define DOS_OS2
  602. #endif
  603. #if (defined(OS2) || defined(WIN32))
  604. # define OS2_W32
  605. #endif
  606. #if (defined(DOS_OS2) || defined(WIN32))
  607. # define DOS_OS2_W32
  608. # define DOS_W32_OS2 /* historical: don't use */
  609. #endif
  610. #if (defined(DOS_OS2_W32) || defined(__human68k__))
  611. # define DOS_H68_OS2_W32
  612. #endif
  613. #if (defined(DOS_OS2) || defined(FLEXOS))
  614. # define DOS_FLX_OS2
  615. #endif
  616. #if (defined(DOS_OS2_W32) || defined(FLEXOS))
  617. # define DOS_FLX_OS2_W32
  618. #endif
  619. #if (defined(DOS_H68_OS2_W32) || defined(FLEXOS))
  620. # define DOS_FLX_H68_OS2_W32
  621. #endif
  622. #if (defined(DOS_FLX_OS2) || defined(NLM))
  623. # define DOS_FLX_NLM_OS2
  624. #endif
  625. #if (defined(DOS_FLX_OS2_W32) || defined(NLM))
  626. # define DOS_FLX_NLM_OS2_W32
  627. #endif
  628. #if (defined(DOS_FLX_H68_OS2_W32) || defined(NLM))
  629. # define DOS_FLX_H68_NLM_OS2_W32
  630. #endif
  631. #if (defined(TOPS20) || defined(VMS))
  632. # define T20_VMS
  633. #endif
  634. #if (defined(MSDOS) || defined(T20_VMS))
  635. # define DOS_T20_VMS
  636. #endif
  637. #if (defined(__ATHEOS__) || defined(__BEOS__))
  638. # define ATH_BEO
  639. #endif
  640. #if (defined(ATH_BEO) || defined(UNIX))
  641. # define ATH_BEO_UNX
  642. #endif
  643. #if (defined(ATH_BEO_UNX) || defined(THEOS))
  644. # define ATH_BEO_THS_UNX
  645. #endif
  646. /* clean up with a few defaults */
  647. #ifndef DIR_END
  648. # define DIR_END '/' /* last char before program name or filename */
  649. #endif
  650. #ifndef DATE_FORMAT
  651. # ifdef DATEFMT_ISO_DEFAULT
  652. # define DATE_FORMAT DF_YMD /* defaults to invariant ISO-style */
  653. # else
  654. # define DATE_FORMAT DF_MDY /* defaults to US convention */
  655. # endif
  656. #endif
  657. #ifndef DATE_SEPCHAR
  658. # define DATE_SEPCHAR '-'
  659. #endif
  660. #ifndef CLOSE_INFILE
  661. # define CLOSE_INFILE() close(G.zipfd)
  662. #endif
  663. #ifndef RETURN
  664. # define RETURN return /* only used in main() */
  665. #endif
  666. #ifndef EXIT
  667. # define EXIT exit
  668. #endif
  669. #ifndef USAGE
  670. # define USAGE(ret) usage(__G__ (ret)) /* used in unzip.c, zipinfo.c */
  671. #endif
  672. #ifndef TIMET_TO_NATIVE /* everybody but MSC 7.0 and Macintosh */
  673. # define TIMET_TO_NATIVE(x)
  674. # define NATIVE_TO_TIMET(x)
  675. #endif
  676. #ifndef STRNICMP
  677. # ifdef NO_STRNICMP
  678. # define STRNICMP zstrnicmp
  679. # else
  680. # define STRNICMP strnicmp
  681. # endif
  682. #endif
  683. #if (defined(DOS_FLX_NLM_OS2_W32) || defined(ATH_BEO_UNX) || defined(RISCOS))
  684. # ifndef HAVE_UNLINK
  685. # define HAVE_UNLINK
  686. # endif
  687. #endif
  688. #if (defined(AOS_VS) || defined(ATARI)) /* GRR: others? */
  689. # ifndef HAVE_UNLINK
  690. # define HAVE_UNLINK
  691. # endif
  692. #endif
  693. /* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
  694. #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
  695. # if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
  696. # define INT_SPRINTF /* sprintf() returns int: SysVish/Posix */
  697. # endif
  698. # if (defined(DOS_FLX_NLM_OS2_W32) || defined(VMS) || defined(AMIGA))
  699. # define INT_SPRINTF /* sprintf() returns int: ANSI */
  700. # endif
  701. # if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
  702. # if (defined(POSIX) || defined(__POSIX))
  703. # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
  704. # endif
  705. # ifdef __GNUC__
  706. # define PCHAR_SPRINTF /* undetermined actual return value */
  707. # endif
  708. # endif
  709. # if (defined(__osf__) || defined(_AIX) || defined(CMS_MVS) || defined(THEOS))
  710. # define INT_SPRINTF /* sprintf() returns int: ANSI/Posix */
  711. # endif
  712. # if defined(sun)
  713. # define PCHAR_SPRINTF /* sprintf() returns char *: SunOS cc *and* gcc */
  714. # endif
  715. #endif
  716. /* defaults that we hope will take care of most machines in the future */
  717. #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
  718. # ifdef __STDC__
  719. # define INT_SPRINTF /* sprintf() returns int: ANSI */
  720. # endif
  721. # ifndef INT_SPRINTF
  722. # define PCHAR_SPRINTF /* sprintf() returns char *: BSDish */
  723. # endif
  724. #endif
  725. #define MSG_STDERR(f) (f & 1) /* bit 0: 0 = stdout, 1 = stderr */
  726. #define MSG_INFO(f) ((f & 6) == 0) /* bits 1 and 2: 0 = info */
  727. #define MSG_WARN(f) ((f & 6) == 2) /* bits 1 and 2: 1 = warning */
  728. #define MSG_ERROR(f) ((f & 6) == 4) /* bits 1 and 2: 2 = error */
  729. #define MSG_FATAL(f) ((f & 6) == 6) /* bits 1 and 2: (3 = fatal error) */
  730. #define MSG_ZFN(f) (f & 0x0008) /* bit 3: 1 = print zipfile name */
  731. #define MSG_FN(f) (f & 0x0010) /* bit 4: 1 = print filename */
  732. #define MSG_LNEWLN(f) (f & 0x0020) /* bit 5: 1 = leading newline if !SOL */
  733. #define MSG_TNEWLN(f) (f & 0x0040) /* bit 6: 1 = trailing newline if !SOL */
  734. #define MSG_MNEWLN(f) (f & 0x0080) /* bit 7: 1 = trailing NL for prompts */
  735. /* the following are subject to change */
  736. #define MSG_NO_WGUI(f) (f & 0x0100) /* bit 8: 1 = skip if Windows GUI */
  737. #define MSG_NO_AGUI(f) (f & 0x0200) /* bit 9: 1 = skip if Acorn GUI */
  738. #define MSG_NO_DLL2(f) (f & 0x0400) /* bit 10: 1 = skip if OS/2 DLL */
  739. #define MSG_NO_NDLL(f) (f & 0x0800) /* bit 11: 1 = skip if WIN32 DLL */
  740. #define MSG_NO_WDLL(f) (f & 0x1000) /* bit 12: 1 = skip if Windows DLL */
  741. #if (defined(MORE) && !defined(SCREENLINES))
  742. # ifdef DOS_FLX_NLM_OS2_W32
  743. # define SCREENLINES 25 /* can be (should be) a function instead */
  744. # else
  745. # define SCREENLINES 24 /* VT-100s are assumed to be minimal hardware */
  746. # endif
  747. #endif
  748. #if (defined(MORE) && !defined(SCREENSIZE))
  749. # ifndef SCREENWIDTH
  750. # define SCREENSIZE(scrrows, scrcols) { \
  751. if ((scrrows) != NULL) *(scrrows) = SCREENLINES; }
  752. # else
  753. # define SCREENSIZE(scrrows, scrcols) { \
  754. if ((scrrows) != NULL) *(scrrows) = SCREENLINES; \
  755. if ((scrcols) != NULL) *(scrcols) = SCREENWIDTH; }
  756. # endif
  757. #endif
  758. #if (defined(__16BIT__) || defined(MED_MEM) || defined(SMALL_MEM))
  759. # define DIR_BLKSIZ 64 /* number of directory entries per block
  760. * (should fit in 4096 bytes, usually) */
  761. #else
  762. # define DIR_BLKSIZ 16384 /* use more memory, to reduce long-range seeks */
  763. #endif
  764. #ifndef WSIZE
  765. # ifdef USE_DEFLATE64
  766. # define WSIZE 65536L /* window size--must be a power of two, and */
  767. # else /* at least 64K for PKZip's deflate64 method */
  768. # define WSIZE 0x8000 /* window size--must be a power of two, and */
  769. # endif /* at least 32K for zip's deflate method */
  770. #endif
  771. #ifdef __16BIT__
  772. # ifndef INT_16BIT
  773. # define INT_16BIT /* on 16-bit systems int size is 16 bits */
  774. # endif
  775. #else
  776. # define nearmalloc malloc
  777. # define nearfree free
  778. # if (!defined(__IBMC__) || !defined(OS2))
  779. # ifndef near
  780. # define near
  781. # endif
  782. # ifndef far
  783. # define far
  784. # endif
  785. # endif
  786. #endif
  787. #if (defined(DYNALLOC_CRCTAB) && !defined(DYNAMIC_CRC_TABLE))
  788. # undef DYNALLOC_CRCTAB
  789. #endif
  790. #if (defined(DYNALLOC_CRCTAB) && defined(REENTRANT))
  791. # undef DYNALLOC_CRCTAB /* not safe with reentrant code */
  792. #endif
  793. #if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
  794. # ifdef DYNALLOC_CRCTAB
  795. # undef DYNALLOC_CRCTAB
  796. # endif
  797. #endif
  798. #if (defined(USE_ZLIB) && defined(ASM_CRC))
  799. # undef ASM_CRC
  800. #endif
  801. #ifdef USE_ZLIB
  802. # ifdef IZ_CRC_BE_OPTIMIZ
  803. # undef IZ_CRC_BE_OPTIMIZ
  804. # endif
  805. # ifdef IZ_CRC_LE_OPTIMIZ
  806. # undef IZ_CRC_LE_OPTIMIZ
  807. # endif
  808. #endif
  809. #if (!defined(IZ_CRC_BE_OPTIMIZ) && !defined(IZ_CRC_LE_OPTIMIZ))
  810. # ifdef IZ_CRCOPTIM_UNFOLDTBL
  811. # undef IZ_CRCOPTIM_UNFOLDTBL
  812. # endif
  813. #endif
  814. #ifndef INBUFSIZ
  815. # if (defined(MED_MEM) || defined(SMALL_MEM))
  816. # define INBUFSIZ 2048 /* works for MS-DOS small model */
  817. # else
  818. # define INBUFSIZ 8192 /* larger buffers for real OSes */
  819. # endif
  820. #endif
  821. #if (defined(INT_16BIT) && (defined(USE_DEFLATE64) || lenEOL > 1))
  822. /* For environments using 16-bit integers OUTBUFSIZ must be limited to
  823. * less than 64k (do_string() uses "unsigned" in calculations involving
  824. * OUTBUFSIZ). This is achieved by defining MED_MEM when WSIZE = 64k (aka
  825. * Deflate64 support enabled) or EOL markers contain multiple characters.
  826. * (The rule gets applied AFTER the default rule for INBUFSIZ because it
  827. * is not neccessary to reduce INBUFSIZE in this case.)
  828. */
  829. # if (!defined(SMALL_MEM) && !defined(MED_MEM))
  830. # define MED_MEM
  831. # endif
  832. #endif
  833. /* Logic for case of small memory, length of EOL > 1: if OUTBUFSIZ == 2048,
  834. * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
  835. * and transbuf 1040 bytes. Have room for 32 extra EOL chars; 1008/32 == 31.5
  836. * chars/line, smaller than estimated 35-70 characters per line for C source
  837. * and normal text. Hence difference is sufficient for most "average" files.
  838. * (Argument scales for larger OUTBUFSIZ.)
  839. */
  840. #ifdef SMALL_MEM /* i.e., 16-bit OSes: MS-DOS, OS/2 1.x, etc. */
  841. # define LoadFarString(x) fLoadFarString(__G__ (x))
  842. # define LoadFarStringSmall(x) fLoadFarStringSmall(__G__ (x))
  843. # define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
  844. # if (defined(_MSC_VER) && (_MSC_VER >= 600))
  845. # define zfstrcpy(dest, src) _fstrcpy((dest), (src))
  846. # define zfstrcmp(s1, s2) _fstrcmp((s1), (s2))
  847. # endif
  848. # if !(defined(SFX) || defined(FUNZIP))
  849. # if (defined(_MSC_VER))
  850. # define zfmalloc(sz) _fmalloc((sz))
  851. # define zffree(x) _ffree(x)
  852. # endif
  853. # if (defined(__TURBOC__))
  854. # include <alloc.h>
  855. # define zfmalloc(sz) farmalloc((unsigned long)(sz))
  856. # define zffree(x) farfree(x)
  857. # endif
  858. # endif /* !(SFX || FUNZIP) */
  859. # ifndef Far
  860. # define Far far /* __far only works for MSC 6.00, not 6.0a or Borland */
  861. # endif
  862. # define OUTBUFSIZ INBUFSIZ
  863. # if (lenEOL == 1)
  864. # define RAWBUFSIZ (OUTBUFSIZ>>1)
  865. # else
  866. # define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
  867. # endif
  868. # define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
  869. typedef short shrint; /* short/int or "shrink int" (unshrink) */
  870. #else
  871. # define zfstrcpy(dest, src) strcpy((dest), (src))
  872. # define zfstrcmp(s1, s2) strcmp((s1), (s2))
  873. # define zfmalloc malloc
  874. # define zffree(x) free(x)
  875. # ifdef QDOS
  876. # define LoadFarString(x) Qstrfix(x) /* fix up _ for '.' */
  877. # define LoadFarStringSmall(x) Qstrfix(x)
  878. # define LoadFarStringSmall2(x) Qstrfix(x)
  879. # else
  880. # define LoadFarString(x) (char *)(x)
  881. # define LoadFarStringSmall(x) (char *)(x)
  882. # define LoadFarStringSmall2(x) (char *)(x)
  883. # endif
  884. # ifdef MED_MEM
  885. # define OUTBUFSIZ 0xFF80 /* can't malloc arrays of 0xFFE8 or more */
  886. # define TRANSBUFSIZ 0xFF80
  887. typedef short shrint;
  888. # else
  889. # define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
  890. # define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
  891. # ifdef AMIGA
  892. typedef short shrint;
  893. # else
  894. typedef int shrint; /* for efficiency/speed, we hope... */
  895. # endif
  896. # endif /* ?MED_MEM */
  897. # define RAWBUFSIZ OUTBUFSIZ
  898. #endif /* ?SMALL_MEM */
  899. #ifndef Far
  900. # define Far
  901. #endif
  902. #ifndef Cdecl
  903. # define Cdecl
  904. #endif
  905. #ifndef MAIN
  906. # define MAIN main
  907. #endif
  908. #ifdef SFX /* disable some unused features for SFX executables */
  909. # ifndef NO_ZIPINFO
  910. # define NO_ZIPINFO
  911. # endif
  912. # ifdef TIMESTAMP
  913. # undef TIMESTAMP
  914. # endif
  915. #endif
  916. #ifdef SFX
  917. # ifdef CHEAP_SFX_AUTORUN
  918. # ifndef NO_SFX_EXDIR
  919. # define NO_SFX_EXDIR
  920. # endif
  921. # endif
  922. # ifndef NO_SFX_EXDIR
  923. # ifndef SFX_EXDIR
  924. # define SFX_EXDIR
  925. # endif
  926. # else
  927. # ifdef SFX_EXDIR
  928. # undef SFX_EXDIR
  929. # endif
  930. # endif
  931. #endif
  932. /* user may have defined both by accident... NOTIMESTAMP takes precedence */
  933. #if (defined(TIMESTAMP) && defined(NOTIMESTAMP))
  934. # undef TIMESTAMP
  935. #endif
  936. #if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
  937. # define COPYRIGHT_CLEAN
  938. #endif
  939. /* The LZW patent is expired worldwide since 2004-Jul-07, so USE_UNSHRINK
  940. * is now enabled by default. See unshrink.c.
  941. */
  942. #if (!defined(LZW_CLEAN) && !defined(USE_UNSHRINK))
  943. # define USE_UNSHRINK
  944. #endif
  945. #ifndef O_BINARY
  946. # define O_BINARY 0
  947. #endif
  948. #ifndef PIPE_ERROR
  949. # ifndef EPIPE
  950. # define EPIPE -1
  951. # endif
  952. # define PIPE_ERROR (errno == EPIPE)
  953. #endif
  954. /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
  955. #ifdef VMS
  956. # define FOPR "r","ctx=stm"
  957. # define FOPM "r+","ctx=stm","rfm=fix","mrs=512"
  958. # define FOPW "w","ctx=stm","rfm=fix","mrs=512"
  959. # define FOPWR "w+","ctx=stm","rfm=fix","mrs=512"
  960. #endif /* VMS */
  961. #ifdef CMS_MVS
  962. /* Binary files must be RECFM=F,LRECL=1 for ftell() to get correct pos */
  963. /* ...unless byteseek is used. Let's try that for a while. */
  964. # define FOPR "rb,byteseek"
  965. # define FOPM "r+b,byteseek"
  966. # ifdef MVS
  967. # define FOPW "wb,recfm=u,lrecl=32760,byteseek" /* New binary files */
  968. # define FOPWE "wb" /* Existing binary files */
  969. # define FOPWT "w,lrecl=133" /* New text files */
  970. # define FOPWTE "w" /* Existing text files */
  971. # else
  972. # define FOPW "wb,recfm=v,lrecl=32760"
  973. # define FOPWT "w"
  974. # endif
  975. #endif /* CMS_MVS */
  976. #ifdef TOPS20 /* TOPS-20 MODERN? You kidding? */
  977. # define FOPW "w8"
  978. #endif /* TOPS20 */
  979. /* Defaults when nothing special has been defined previously. */
  980. #ifdef MODERN
  981. # ifndef FOPR
  982. # define FOPR "rb"
  983. # endif
  984. # ifndef FOPM
  985. # define FOPM "r+b"
  986. # endif
  987. # ifndef FOPW
  988. # define FOPW "wb"
  989. # endif
  990. # ifndef FOPWT
  991. # define FOPWT "wt"
  992. # endif
  993. # ifndef FOPWR
  994. # define FOPWR "w+b"
  995. # endif
  996. #else /* !MODERN */
  997. # ifndef FOPR
  998. # define FOPR "r"
  999. # endif
  1000. # ifndef FOPM
  1001. # define FOPM "r+"
  1002. # endif
  1003. # ifndef FOPW
  1004. # define FOPW "w"
  1005. # endif
  1006. # ifndef FOPWT
  1007. # define FOPWT "w"
  1008. # endif
  1009. # ifndef FOPWR
  1010. # define FOPWR "w+"
  1011. # endif
  1012. #endif /* ?MODERN */
  1013. /*
  1014. * If <limits.h> exists on most systems, should include that, since it may
  1015. * define some or all of the following: NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  1016. * _POSIX_PATH_MAX.
  1017. */
  1018. #ifdef DOS_FLX_NLM_OS2_W32
  1019. # include <limits.h>
  1020. #endif
  1021. /* 2008-07-22 SMS.
  1022. * Unfortunately, on VMS, <limits.h> exists, and is included by <stdlib.h>
  1023. * (so it's pretty much unavoidable), and it defines PATH_MAX to a fixed
  1024. * short value (256, correct only for older systems without ODS-5 support),
  1025. * rather than one based on the real RMS NAM[L] situation. So, we
  1026. * artificially undefine it here, to allow our better-defined _MAX_PATH
  1027. * (see vms/vmscfg.h) to be used.
  1028. */
  1029. #ifdef VMS
  1030. # undef PATH_MAX
  1031. #endif
  1032. #ifndef PATH_MAX
  1033. # ifdef MAXPATHLEN
  1034. # define PATH_MAX MAXPATHLEN /* in <sys/param.h> on some systems */
  1035. # else
  1036. # ifdef _MAX_PATH
  1037. # define PATH_MAX _MAX_PATH
  1038. # else
  1039. # if FILENAME_MAX > 255
  1040. # define PATH_MAX FILENAME_MAX /* used like PATH_MAX on some systems */
  1041. # else
  1042. # define PATH_MAX 1024
  1043. # endif
  1044. # endif /* ?_MAX_PATH */
  1045. # endif /* ?MAXPATHLEN */
  1046. #endif /* !PATH_MAX */
  1047. /*
  1048. * buffer size required to hold the longest legal local filepath
  1049. * (including the trailing '\0')
  1050. */
  1051. #define FILNAMSIZ PATH_MAX
  1052. #ifdef UNICODE_SUPPORT
  1053. # if !(defined(UTF8_MAYBE_NATIVE) || defined(UNICODE_WCHAR))
  1054. # undef UNICODE_SUPPORT
  1055. # endif
  1056. #endif
  1057. /* 2007-09-18 SMS.
  1058. * Include <locale.h> here if it will be needed later for Unicode.
  1059. * Otherwise, SETLOCALE may be defined here, and then defined again
  1060. * (differently) when <locale.h> is read later.
  1061. */
  1062. #ifdef UNICODE_SUPPORT
  1063. # ifdef UNICODE_WCHAR
  1064. # if !(defined(_WIN32_WCE) || defined(POCKET_UNZIP))
  1065. # include <wchar.h>
  1066. # endif
  1067. # endif
  1068. # ifndef _MBCS /* no need to include <locale.h> twice, see below */
  1069. # include <locale.h>
  1070. # ifndef SETLOCALE
  1071. # define SETLOCALE(category, locale) setlocale(category, locale)
  1072. # endif
  1073. # endif
  1074. #endif /* UNICODE_SUPPORT */
  1075. /* DBCS support for Info-ZIP (mainly for japanese (-: )
  1076. * by Yoshioka Tsuneo (QWF00133@nifty.ne.jp,tsuneo-y@is.aist-nara.ac.jp)
  1077. */
  1078. #ifdef _MBCS
  1079. # include <locale.h>
  1080. /* Multi Byte Character Set */
  1081. # define ___MBS_TMP_DEF char *___tmp_ptr;
  1082. # define ___TMP_PTR ___tmp_ptr
  1083. # ifndef CLEN
  1084. # define NEED_UZMBCLEN
  1085. # define CLEN(ptr) (int)uzmbclen((ZCONST unsigned char *)(ptr))
  1086. # endif
  1087. # ifndef PREINCSTR
  1088. # define PREINCSTR(ptr) (ptr += CLEN(ptr))
  1089. # endif
  1090. # define POSTINCSTR(ptr) (___TMP_PTR=(char *)(ptr), PREINCSTR(ptr),___TMP_PTR)
  1091. char *plastchar OF((ZCONST char *ptr, extent len));
  1092. # define lastchar(ptr, len) ((int)(unsigned)*plastchar(ptr, len))
  1093. # ifndef MBSCHR
  1094. # define NEED_UZMBSCHR
  1095. # define MBSCHR(str,c) (char *)uzmbschr((ZCONST unsigned char *)(str), c)
  1096. # endif
  1097. # ifndef MBSRCHR
  1098. # define NEED_UZMBSRCHR
  1099. # define MBSRCHR(str,c) (char *)uzmbsrchr((ZCONST unsigned char *)(str), c)
  1100. # endif
  1101. # ifndef SETLOCALE
  1102. # define SETLOCALE(category, locale) setlocale(category, locale)
  1103. # endif
  1104. #else /* !_MBCS */
  1105. # define ___MBS_TMP_DEF
  1106. # define ___TMP_PTR
  1107. # define CLEN(ptr) 1
  1108. # define PREINCSTR(ptr) (++(ptr))
  1109. # define POSTINCSTR(ptr) ((ptr)++)
  1110. # define plastchar(ptr, len) (&ptr[(len)-1])
  1111. # define lastchar(ptr, len) (ptr[(len)-1])
  1112. # define MBSCHR(str, c) strchr(str, c)
  1113. # define MBSRCHR(str, c) strrchr(str, c)
  1114. # ifndef SETLOCALE
  1115. # define SETLOCALE(category, locale)
  1116. # endif
  1117. #endif /* ?_MBCS */
  1118. #define INCSTR(ptr) PREINCSTR(ptr)
  1119. #if (defined(MALLOC_WORK) && !defined(MY_ZCALLOC))
  1120. /* Any system without a special calloc function */
  1121. # ifndef zcalloc
  1122. # define zcalloc(items, size) \
  1123. (zvoid far *)calloc((unsigned)(items), (unsigned)(size))
  1124. # endif
  1125. # ifndef zcfree
  1126. # define zcfree free
  1127. # endif
  1128. #endif /* MALLOC_WORK && !MY_ZCALLOC */
  1129. #if (defined(CRAY) && defined(ZMEM))
  1130. # undef ZMEM
  1131. #endif
  1132. #ifdef ZMEM
  1133. # undef ZMEM
  1134. # define memcmp(b1,b2,len) bcmp(b2,b1,len)
  1135. # define memcpy(dest,src,len) bcopy(src,dest,len)
  1136. # define memzero bzero
  1137. #else
  1138. # define memzero(dest,len) memset(dest,0,len)
  1139. #endif
  1140. #ifndef TRUE
  1141. # define TRUE 1 /* sort of obvious */
  1142. #endif
  1143. #ifndef FALSE
  1144. # define FALSE 0
  1145. #endif
  1146. #ifndef SEEK_SET
  1147. # define SEEK_SET 0
  1148. # define SEEK_CUR 1
  1149. # define SEEK_END 2
  1150. #endif
  1151. #if (!defined(S_IEXEC) && defined(S_IXUSR))
  1152. # define S_IEXEC S_IXUSR
  1153. #endif
  1154. #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
  1155. # define SYMLINKS
  1156. # ifndef S_ISLNK
  1157. # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  1158. # endif
  1159. #endif /* UNIX && S_IFLNK && !MTS */
  1160. #ifndef S_ISDIR
  1161. # ifdef CMS_MVS
  1162. # define S_ISDIR(m) (FALSE)
  1163. # else
  1164. # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  1165. # endif
  1166. #endif
  1167. #ifndef IS_VOLID
  1168. # define IS_VOLID(m) ((m) & 0x08)
  1169. #endif
  1170. /***********************************/
  1171. /* LARGE_FILE_SUPPORT */
  1172. /***********************************/
  1173. /* This whole section lifted from Zip 3b tailor.h
  1174. * Types are in OS dependent headers (eg, w32cfg.h)
  1175. *
  1176. * LARGE_FILE_SUPPORT and ZIP64_SUPPORT are automatically
  1177. * set in OS dependent headers (for some ports) based on the port and compiler.
  1178. *
  1179. * Function prototypes are below as OF is defined earlier in this file
  1180. * but after OS dependent header is included.
  1181. *
  1182. * E. Gordon 9/21/2003
  1183. * Updated 1/28/2004
  1184. * Lifted and placed here 6/7/2004 - Myles Bennett
  1185. */
  1186. #ifdef LARGE_FILE_SUPPORT
  1187. /* 64-bit Large File Support */
  1188. /* ---------------------------- */
  1189. # if defined(UNIX) || defined(VMS)
  1190. /* 64-bit stat functions */
  1191. # define zstat stat
  1192. # define zfstat fstat
  1193. /* 64-bit fseeko */
  1194. # define zlseek lseek
  1195. # define zfseeko fseeko
  1196. /* 64-bit ftello */
  1197. # define zftello ftello
  1198. /* 64-bit fopen */
  1199. # define zfopen fopen
  1200. # define zfdopen fdopen
  1201. # endif /* UNIX || VMS */
  1202. /* ---------------------------- */
  1203. # ifdef WIN32
  1204. # if defined(_MSC_VER) || defined(__MINGW32__) || defined(__LCC__)
  1205. /* MS C (VC), MinGW GCC port and LCC-32 use the MS C Runtime lib */
  1206. /* 64-bit stat functions */
  1207. # define zstat _stati64
  1208. # define zfstat _fstati64
  1209. /* 64-bit lseek */
  1210. # define zlseek _lseeki64
  1211. # if defined(_MSC_VER) && (_MSC_VER >= 1400)
  1212. /* Beginning with VS 8.0 (Visual Studio 2005, MSC 14), the Microsoft
  1213. C rtl publishes its (previously internal) implmentations of
  1214. "fseeko" and "ftello" for 64-bit file offsets. */
  1215. /* 64-bit fseeko */
  1216. # define zfseeko _fseeki64
  1217. /* 64-bit ftello */
  1218. # define zftello _ftelli64
  1219. # else /* not (defined(_MSC_VER) && (_MSC_VER >= 1400)) */
  1220. # if defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__ >= 0x800)
  1221. /* Up-to-date versions of MinGW define the macro __MSVCRT_VERSION__
  1222. to denote the version of the MS C rtl dll used for linking. When
  1223. configured to link against the runtime of MS Visual Studio 8 (or
  1224. newer), the built-in 64-bit fseek/ftell functions are available. */
  1225. /* 64-bit fseeko */
  1226. # define zfseeko _fseeki64
  1227. /* 64-bit ftello */
  1228. # define zftello _ftelli64
  1229. # else /* !(defined(__MSVCRT_VERSION__) && (__MSVCRT_VERSION__>=0x800)) */
  1230. /* The version of the C runtime is lower than MSC 14 or unknown. */
  1231. /* The newest MinGW port contains built-in extensions to the MSC rtl
  1232. that provide fseeko and ftello, but our implementations will do
  1233. for now. */
  1234. /* 64-bit fseeko */
  1235. int zfseeko OF((FILE *, zoff_t, int));
  1236. /* 64-bit ftello */
  1237. zoff_t zftello OF((FILE *));
  1238. # endif /* ? (__MSVCRT_VERSION__ >= 0x800) */
  1239. # endif /* ? (_MSC_VER >= 1400) */
  1240. /* 64-bit fopen */
  1241. # define zfopen fopen
  1242. # define zfdopen fdopen
  1243. # endif /* _MSC_VER || __MINGW__ || __LCC__ */
  1244. # ifdef __CYGWIN__
  1245. /* CYGWIN GCC Posix emulator on Windows
  1246. (configuration not yet finished/tested) */
  1247. /* 64-bit stat functions */
  1248. # define zstat _stati64
  1249. # define zfstat _fstati64
  1250. /* 64-bit lseek */
  1251. # define zlseek _lseeki64
  1252. /* 64-bit fseeko */
  1253. # define zfseeko fseeko
  1254. /* 64-bit ftello */
  1255. # define zftello ftello
  1256. /* 64-bit fopen */
  1257. # define zfopen fopen
  1258. # define zfdopen fdopen
  1259. # endif
  1260. # if defined(__WATCOMC__) || defined(__BORLANDC__)
  1261. /* WATCOM C and Borland C provide their own C runtime libraries,
  1262. but they are sufficiently compatible with MS CRTL. */
  1263. /* 64-bit stat functions */
  1264. # define zstat _stati64
  1265. # define zfstat _fstati64
  1266. # ifdef __WATCOMC__
  1267. /* 64-bit lseek */
  1268. # define zlseek _lseeki64
  1269. # endif
  1270. /* 64-bit fseeko */
  1271. int zfseeko OF((FILE *, zoff_t, int));
  1272. /* 64-bit ftello */
  1273. zoff_t zftello OF((FILE *));
  1274. /* 64-bit fopen */
  1275. # define zfopen fopen
  1276. # define zfdopen fdopen
  1277. # endif
  1278. # ifdef __IBMC__
  1279. /* IBM C */
  1280. /* 64-bit stat functions */
  1281. /* 64-bit fseeko */
  1282. /* 64-bit ftello */
  1283. /* 64-bit fopen */
  1284. # endif
  1285. # endif /* WIN32 */
  1286. #else
  1287. /* No Large File Support */
  1288. # ifndef REGULUS /* returns the inode number on success(!)...argh argh argh */
  1289. # define zstat stat
  1290. # endif
  1291. # define zfstat fstat
  1292. # define zlseek lseek
  1293. # define zfseeko fseek
  1294. # define zftello ftell
  1295. # define zfopen fopen
  1296. # define zfdopen fdopen
  1297. # if defined(UNIX) || defined(VMS) || defined(WIN32)
  1298. /* For these systems, implement "64bit file vs. 32bit prog" check */
  1299. # ifndef DO_SAFECHECK_2GB
  1300. # define DO_SAFECHECK_2GB
  1301. # endif
  1302. # endif
  1303. #endif
  1304. /* No "64bit file vs. 32bit prog" check for SFX stub, to save space */
  1305. #if (defined(DO_SAFECHECK_2GB) && defined(SFX))
  1306. # undef DO_SAFECHECK_2GB
  1307. #endif
  1308. #ifndef SSTAT
  1309. # ifdef WILD_STAT_BUG
  1310. # define SSTAT(path,pbuf) (iswild(path) || zstat(path,pbuf))
  1311. # else
  1312. # define SSTAT zstat
  1313. # endif
  1314. #endif
  1315. /* Default fzofft() format selection. */
  1316. #ifndef FZOFFT_FMT
  1317. # ifdef LARGE_FILE_SUPPORT
  1318. # define FZOFFT_FMT "ll"
  1319. # define FZOFFT_HEX_WID_VALUE "16"
  1320. # else /* def LARGE_FILE_SUPPORT */
  1321. # define FZOFFT_FMT "l"
  1322. # define FZOFFT_HEX_WID_VALUE "8"
  1323. # endif /* def LARGE_FILE_SUPPORT */
  1324. #endif /* ndef FZOFFT_FMT */
  1325. #define FZOFFT_HEX_WID ((char *) -1)
  1326. #define FZOFFT_HEX_DOT_WID ((char *) -2)
  1327. #define FZOFFT_NUM 4 /* Number of chambers. */
  1328. #define FZOFFT_LEN 24 /* Number of characters/chamber. */
  1329. #ifdef SHORT_SYMS /* Mark Williams C, ...? */
  1330. # define extract_or_test_files xtr_or_tst_files
  1331. # define extract_or_test_member xtr_or_tst_member
  1332. #endif
  1333. #ifdef REALLY_SHORT_SYMS /* TOPS-20 linker: first 6 chars */
  1334. # define process_cdir_file_hdr XXpcdfh
  1335. # define process_local_file_hdr XXplfh
  1336. # define extract_or_test_files XXxotf /* necessary? */
  1337. # define extract_or_test_member XXxotm /* necessary? */
  1338. # define check_for_newer XXcfn
  1339. # define overwrite_all XXoa
  1340. # define process_all_files XXpaf
  1341. # define extra_field XXef
  1342. # define explode_lit8 XXel8
  1343. # define explode_lit4 XXel4
  1344. # define explode_nolit8 XXnl8
  1345. # define explode_nolit4 XXnl4
  1346. # define cpdist8 XXcpdist8
  1347. # define inflate_codes XXic
  1348. # define inflate_stored XXis
  1349. # define inflate_fixed XXif
  1350. # define inflate_dynamic XXid
  1351. # define inflate_block XXib
  1352. # define maxcodemax XXmax
  1353. #endif
  1354. #ifndef S_TIME_T_MAX /* max value of signed (>= 32-bit) time_t */
  1355. # define S_TIME_T_MAX ((time_t)(ulg)0x7fffffffL)
  1356. #endif
  1357. #ifndef U_TIME_T_MAX /* max value of unsigned (>= 32-bit) time_t */
  1358. # define U_TIME_T_MAX ((time_t)(ulg)0xffffffffL)
  1359. #endif
  1360. #ifdef DOSTIME_MINIMUM /* min DOSTIME value (1980-01-01) */
  1361. # undef DOSTIME_MINIMUM
  1362. #endif
  1363. #define DOSTIME_MINIMUM ((ulg)0x00210000L)
  1364. #ifdef DOSTIME_2038_01_18 /* approximate DOSTIME equivalent of */
  1365. # undef DOSTIME_2038_01_18 /* the signed-32-bit time_t limit */
  1366. #endif
  1367. #define DOSTIME_2038_01_18 ((ulg)0x74320000L)
  1368. #ifdef QDOS
  1369. # define ZSUFX "_zip"
  1370. # define ALT_ZSUFX ".zip"
  1371. #else
  1372. # ifdef RISCOS
  1373. # define ZSUFX "/zip"
  1374. # else
  1375. # define ZSUFX ".zip"
  1376. # endif
  1377. # define ALT_ZSUFX ".ZIP" /* Unix-only so far (only case-sensitive fs) */
  1378. #endif
  1379. #define CENTRAL_HDR_SIG "\001\002" /* the infamous "PK" signature bytes, */
  1380. #define LOCAL_HDR_SIG "\003\004" /* w/o "PK" (so unzip executable not */
  1381. #define END_CENTRAL_SIG "\005\006" /* mistaken for zipfile itself) */
  1382. #define EXTD_LOCAL_SIG "\007\010" /* [ASCII "\113" == EBCDIC "\080" ??] */
  1383. /** internal-only return codes **/
  1384. #define IZ_DIR 76 /* potential zipfile is a directory */
  1385. /* special return codes for mapname() */
  1386. #define MPN_OK 0 /* mapname successful */
  1387. #define MPN_INF_TRUNC (1<<8) /* caution - filename truncated */
  1388. #define MPN_INF_SKIP (2<<8) /* info - skipped because nothing to do */
  1389. #define MPN_ERR_SKIP (3<<8) /* error - entry skipped */
  1390. #define MPN_ERR_TOOLONG (4<<8) /* error - path too long */
  1391. #define MPN_NOMEM (10<<8) /* error - out of memory, file skipped */
  1392. #define MPN_CREATED_DIR (16<<8) /* directory created: set time & permission */
  1393. #define MPN_VOL_LABEL (17<<8) /* volume label, but can't set on hard disk */
  1394. #define MPN_INVALID (99<<8) /* internal logic error, should never reach */
  1395. /* mask for internal mapname&checkdir return codes */
  1396. #define MPN_MASK 0x7F00
  1397. /* error code for extracting/testing extra field blocks */
  1398. #define IZ_EF_TRUNC 79 /* local extra field truncated (PKZIP'd) */
  1399. /* choice of activities for do_string() */
  1400. #define SKIP 0 /* skip header block */
  1401. #define DISPLAY 1 /* display archive comment (ASCII) */
  1402. #define DISPL_8 5 /* display file comment (ext. ASCII) */
  1403. #define DS_FN 2 /* read filename (ext. ASCII, chead) */
  1404. #define DS_FN_C 2 /* read filename from central header */
  1405. #define DS_FN_L 6 /* read filename from local header */
  1406. #define EXTRA_FIELD 3 /* copy extra field into buffer */
  1407. #define DS_EF 3
  1408. #ifdef AMIGA
  1409. # define FILENOTE 4 /* convert file comment to filenote */
  1410. #endif
  1411. #if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
  1412. # define CHECK_AUTORUN 7 /* copy command, display remainder */
  1413. # define CHECK_AUTORUN_Q 8 /* copy command, skip remainder */
  1414. #endif
  1415. #define DOES_NOT_EXIST -1 /* return values for check_for_newer() */
  1416. #define EXISTS_AND_OLDER 0
  1417. #define EXISTS_AND_NEWER 1
  1418. #define OVERWRT_QUERY 0 /* status values for G.overwrite_mode */
  1419. #define OVERWRT_ALWAYS 1
  1420. #define OVERWRT_NEVER 2
  1421. #define IS_OVERWRT_ALL (G.overwrite_mode == OVERWRT_ALWAYS)
  1422. #define IS_OVERWRT_NONE (G.overwrite_mode == OVERWRT_NEVER)
  1423. #ifdef VMS
  1424. /* return codes for VMS-specific open_outfile() function */
  1425. # define OPENOUT_OK 0 /* file openend normally */
  1426. # define OPENOUT_FAILED 1 /* file open failed */
  1427. # define OPENOUT_SKIPOK 2 /* file not opened, skip at error level OK */
  1428. # define OPENOUT_SKIPWARN 3 /* file not opened, skip at error level WARN */
  1429. #endif /* VMS */
  1430. #define ROOT 0 /* checkdir() extract-to path: called once */
  1431. #define INIT 1 /* allocate buildpath: called once per member */
  1432. #define APPEND_DIR 2 /* append a dir comp.: many times per member */
  1433. #define APPEND_NAME 3 /* append actual filename: once per member */
  1434. #define GETPATH 4 /* retrieve the complete path and free it */
  1435. #define END 5 /* free root path prior to exiting program */
  1436. /* version_made_by codes (central dir): make sure these */
  1437. /* are not defined on their respective systems!! */
  1438. #define FS_FAT_ 0 /* filesystem used by MS-DOS, OS/2, Win32 */
  1439. #define AMIGA_ 1
  1440. #define VMS_ 2
  1441. #define UNIX_ 3
  1442. #define VM_CMS_ 4
  1443. #define ATARI_ 5 /* what if it's a minix filesystem? [cjh] */
  1444. #define FS_HPFS_ 6 /* filesystem used by OS/2 (and NT 3.x) */
  1445. #define MAC_ 7 /* HFS filesystem used by MacOS */
  1446. #define Z_SYSTEM_ 8
  1447. #define CPM_ 9
  1448. #define TOPS20_ 10
  1449. #define FS_NTFS_ 11 /* filesystem used by Windows NT */
  1450. #define QDOS_ 12
  1451. #define ACORN_ 13 /* Archimedes Acorn RISC OS */
  1452. #define FS_VFAT_ 14 /* filesystem used by Windows 95, NT */
  1453. #define MVS_ 15
  1454. #define BEOS_ 16 /* hybrid POSIX/database filesystem */
  1455. #define TANDEM_ 17 /* Tandem NSK */
  1456. #define THEOS_ 18 /* THEOS */
  1457. #define MAC_OSX_ 19 /* Mac OS/X (Darwin) */
  1458. #define ATHEOS_ 30 /* AtheOS */
  1459. #define NUM_HOSTS 31 /* index of last system + 1 */
  1460. /* don't forget to update zipinfo.c appropiately if NUM_HOSTS changes! */
  1461. #define STORED 0 /* compression methods */
  1462. #define SHRUNK 1
  1463. #define REDUCED1 2
  1464. #define REDUCED2 3
  1465. #define REDUCED3 4
  1466. #define REDUCED4 5
  1467. #define IMPLODED 6
  1468. #define TOKENIZED 7
  1469. #define DEFLATED 8
  1470. #define ENHDEFLATED 9
  1471. #define DCLIMPLODED 10
  1472. #define BZIPPED 12
  1473. #define LZMAED 14
  1474. #define IBMTERSED 18
  1475. #define IBMLZ77ED 19
  1476. #define WAVPACKED 97
  1477. #define PPMDED 98
  1478. #define NUM_METHODS 17 /* number of known method IDs */
  1479. /* don't forget to update list.c (list_files()), extract.c and zipinfo.c
  1480. * appropriately if NUM_METHODS changes */
  1481. /* (the PK-class error codes are public and have been moved into unzip.h) */
  1482. #define DF_MDY 0 /* date format 10/26/91 (USA only) */
  1483. #define DF_DMY 1 /* date format 26/10/91 (most of the world) */
  1484. #define DF_YMD 2 /* date format 91/10/26 (a few countries) */
  1485. /*---------------------------------------------------------------------------
  1486. Extra-field block ID values and offset info.
  1487. ---------------------------------------------------------------------------*/
  1488. /* extra-field ID values, all little-endian: */
  1489. #define EF_PKSZ64 0x0001 /* PKWARE's 64-bit filesize extensions */
  1490. #define EF_AV 0x0007 /* PKWARE's authenticity verification */
  1491. #define EF_EFS 0x0008 /* PKWARE's extended language encoding */
  1492. #define EF_OS2 0x0009 /* OS/2 extended attributes */
  1493. #define EF_PKW32 0x000a /* PKWARE's Win95/98/WinNT filetimes */
  1494. #define EF_PKVMS 0x000c /* PKWARE's VMS */
  1495. #define EF_PKUNIX 0x000d /* PKWARE's Unix */
  1496. #define EF_PKFORK 0x000e /* PKWARE's future stream/fork descriptors */
  1497. #define EF_PKPATCH 0x000f /* PKWARE's patch descriptor */
  1498. #define EF_PKPKCS7 0x0014 /* PKWARE's PKCS#7 store for X.509 Certs */
  1499. #define EF_PKFX509 0x0015 /* PKWARE's file X.509 Cert&Signature ID */
  1500. #define EF_PKCX509 0x0016 /* PKWARE's central dir X.509 Cert ID */
  1501. #define EF_PKENCRHD 0x0017 /* PKWARE's Strong Encryption header */
  1502. #define EF_PKRMCTL 0x0018 /* PKWARE's Record Management Controls*/
  1503. #define EF_PKLSTCS7 0x0019 /* PKWARE's PKCS#7 Encr. Recipient Cert List */
  1504. #define EF_PKIBM 0x0065 /* PKWARE's IBM S/390 & AS/400 attributes */
  1505. #define EF_PKIBM2 0x0066 /* PKWARE's IBM S/390 & AS/400 compr. attribs */
  1506. #define EF_IZVMS 0x4d49 /* Info-ZIP's VMS ("IM") */
  1507. #define EF_IZUNIX 0x5855 /* Info-ZIP's first Unix[1] ("UX") */
  1508. #define EF_IZUNIX2 0x7855 /* Info-ZIP's second Unix[2] ("Ux") */
  1509. #define EF_IZUNIX3 0x7875 /* Info-ZIP's newest Unix[3] ("ux") */
  1510. #define EF_TIME 0x5455 /* universal timestamp ("UT") */
  1511. #define EF_UNIPATH 0x7075 /* Info-ZIP Unicode Path ("up") */
  1512. #define EF_UNICOMNT 0x6375 /* Info-ZIP Unicode Comment ("uc") */
  1513. #define EF_MAC3 0x334d /* Info-ZIP's new Macintosh (= "M3") */
  1514. #define EF_JLMAC 0x07c8 /* Johnny Lee's old Macintosh (= 1992) */
  1515. #define EF_ZIPIT 0x2605 /* Thomas Brown's Macintosh (ZipIt) */
  1516. #define EF_ZIPIT2 0x2705 /* T. Brown's Mac (ZipIt) v 1.3.8 and newer ? */
  1517. #define EF_SMARTZIP 0x4d63 /* Mac SmartZip by Marco Bambini */
  1518. #define EF_VMCMS 0x4704 /* Info-ZIP's VM/CMS ("\004G") */
  1519. #define EF_MVS 0x470f /* Info-ZIP's MVS ("\017G") */
  1520. #define EF_ACL 0x4c41 /* (OS/2) access control list ("AL") */
  1521. #define EF_NTSD 0x4453 /* NT security descriptor ("SD") */
  1522. #define EF_ATHEOS 0x7441 /* AtheOS ("At") */
  1523. #define EF_BEOS 0x6542 /* BeOS ("Be") */
  1524. #define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
  1525. #define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
  1526. #define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
  1527. #define EF_TANDEM 0x4154 /* Tandem NSK ("TA") */
  1528. #define EF_THEOS 0x6854 /* Jean-Michel Dubois' Theos "Th" */
  1529. #define EF_THEOSO 0x4854 /* old Theos port */
  1530. #define EF_MD5 0x4b46 /* Fred Kantor's MD5 ("FK") */
  1531. #define EF_ASIUNIX 0x756e /* ASi's Unix ("nu") */
  1532. #define EB_HEADSIZE 4 /* length of extra field block header */
  1533. #define EB_ID 0 /* offset of block ID in header */
  1534. #define EB_LEN 2 /* offset of data length field in header */
  1535. #define EB_UCSIZE_P 0 /* offset of ucsize field in compr. data */
  1536. #define EB_CMPRHEADLEN 6 /* lenght of compression header */
  1537. #define EB_UX_MINLEN 8 /* minimal "UX" field contains atime, mtime */
  1538. #define EB_UX_FULLSIZE 12 /* full "UX" field (atime, mtime, uid, gid) */
  1539. #define EB_UX_ATIME 0 /* offset of atime in "UX" extra field data */
  1540. #define EB_UX_MTIME 4 /* offset of mtime in "UX" extra field data */
  1541. #define EB_UX_UID 8 /* byte offset of UID in "UX" field data */
  1542. #define EB_UX_GID 10 /* byte offset of GID in "UX" field data */
  1543. #define EB_UX2_MINLEN 4 /* minimal "Ux" field contains UID/GID */
  1544. #define EB_UX2_UID 0 /* byte offset of UID in "Ux" field data */
  1545. #define EB_UX2_GID 2 /* byte offset of GID in "Ux" field data */
  1546. #define EB_UX2_VALID (1 << 8) /* UID/GID present */
  1547. #define EB_UX3_MINLEN 7 /* minimal "ux" field size (2-byte UID/GID) */
  1548. #define EB_UT_MINLEN 1 /* minimal UT field contains Flags byte */
  1549. #define EB_UT_FLAGS 0 /* byte offset of Flags field */
  1550. #define EB_UT_TIME1 1 /* byte offset of 1st time value */
  1551. #define EB_UT_FL_MTIME (1 << 0) /* mtime present */
  1552. #define EB_UT_FL_ATIME (1 << 1) /* atime present */
  1553. #define EB_UT_FL_CTIME (1 << 2) /* ctime present */
  1554. #define EB_FLGS_OFFS 4 /* offset of flags area in generic compressed
  1555. extra field blocks (BEOS, MAC, and others) */
  1556. #define EB_OS2_HLEN 4 /* size of OS2/ACL compressed data header */
  1557. #define EB_BEOS_HLEN 5 /* length of BeOS&AtheOS e.f attribute header */
  1558. #define EB_BE_FL_UNCMPR 0x01 /* "BeOS&AtheOS attribs uncompr." bit flag */
  1559. #define EB_MAC3_HLEN 14 /* length of Mac3 attribute block header */
  1560. #define EB_SMARTZIP_HLEN 64 /* fixed length of the SmartZip extra field */
  1561. #define EB_M3_FL_DATFRK 0x01 /* "this entry is data fork" flag */
  1562. #define EB_M3_FL_UNCMPR 0x04 /* "Mac3 attributes uncompressed" bit flag */
  1563. #define EB_M3_FL_TIME64 0x08 /* "Mac3 time fields are 64 bit wide" flag */
  1564. #define EB_M3_FL_NOUTC 0x10 /* "Mac3 timezone offset fields missing" flag */
  1565. #define EB_NTSD_C_LEN 4 /* length of central NT security data */
  1566. #define EB_NTSD_L_LEN 5 /* length of minimal local NT security data */
  1567. #define EB_NTSD_VERSION 4 /* offset of NTSD version byte */
  1568. #define EB_NTSD_MAX_VER (0) /* maximum version # we know how to handle */
  1569. #define EB_ASI_CRC32 0 /* offset of ASI Unix field's crc32 checksum */
  1570. #define EB_ASI_MODE 4 /* offset of ASI Unix permission mode field */
  1571. #define EB_IZVMS_HLEN 12 /* length of IZVMS attribute block header */
  1572. #define EB_IZVMS_FLGS 4 /* offset of compression type flag */
  1573. #define EB_IZVMS_UCSIZ 6 /* offset of ucsize field in IZVMS header */
  1574. #define EB_IZVMS_BCMASK 07 /* 3 bits for compression type */
  1575. #define EB_IZVMS_BCSTOR 0 /* Stored */
  1576. #define EB_IZVMS_BC00 1 /* 0byte -> 0bit compression */
  1577. #define EB_IZVMS_BCDEFL 2 /* Deflated */
  1578. /*---------------------------------------------------------------------------
  1579. True sizes of the various headers (excluding their 4-byte signatures),
  1580. as defined by PKWARE--so it is not likely that these will ever change.
  1581. But if they do, make sure both these defines AND the typedefs below get
  1582. updated accordingly.
  1583. 12/27/2006
  1584. The Zip64 End Of Central Directory record is variable size and now
  1585. comes in two flavors, version 1 and the new version 2 that supports
  1586. central directory encryption. We only use the old fields at the
  1587. top of the Zip64 EOCDR, and this block is a fixed size still, but
  1588. need to be aware of the stuff following.
  1589. ---------------------------------------------------------------------------*/
  1590. #define LREC_SIZE 26 /* lengths of local file headers, central */
  1591. #define CREC_SIZE 42 /* directory headers, end-of-central-dir */
  1592. #define ECREC_SIZE 18 /* record, zip64 end-of-cent-dir locator */
  1593. #define ECLOC64_SIZE 16 /* and zip64 end-of-central-dir record, */
  1594. #define ECREC64_SIZE 52 /* respectively */
  1595. #define MAX_BITS 13 /* used in unshrink() */
  1596. #define HSIZE (1 << MAX_BITS) /* size of global work area */
  1597. #define LF 10 /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  1598. #define CR 13 /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  1599. #define CTRLZ 26 /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
  1600. #ifdef EBCDIC
  1601. # define foreign(c) ascii[(uch)(c)]
  1602. # define native(c) ebcdic[(uch)(c)]
  1603. # define NATIVE "EBCDIC"
  1604. # define NOANSIFILT
  1605. #endif
  1606. #ifdef VMS
  1607. # define ENV_UNZIP "UNZIP_OPTS" /* names of environment variables */
  1608. # define ENV_ZIPINFO "ZIPINFO_OPTS"
  1609. #endif /* VMS */
  1610. #ifdef RISCOS
  1611. # define ENV_UNZIP "Unzip$Options"
  1612. # define ENV_ZIPINFO "Zipinfo$Options"
  1613. # define ENV_UNZIPEXTS "Unzip$Exts"
  1614. #endif /* RISCOS */
  1615. #ifndef ENV_UNZIP
  1616. # define ENV_UNZIP "UNZIP" /* the standard names */
  1617. # define ENV_ZIPINFO "ZIPINFO"
  1618. #endif
  1619. #define ENV_UNZIP2 "UNZIPOPT" /* alternate names, for zip compat. */
  1620. #define ENV_ZIPINFO2 "ZIPINFOOPT"
  1621. #if (!defined(QQ) && !defined(NOQQ))
  1622. # define QQ
  1623. #endif
  1624. #ifdef QQ /* Newtware version: no file */
  1625. # define QCOND (!uO.qflag) /* comments with -vq or -vqq */
  1626. #else /* Bill Davidsen version: no way to */
  1627. # define QCOND (longhdr) /* kill file comments when listing */
  1628. #endif
  1629. #ifdef OLD_QQ
  1630. # define QCOND2 (uO.qflag < 2)
  1631. #else
  1632. # define QCOND2 (!uO.qflag)
  1633. #endif
  1634. #ifdef WILD_STOP_AT_DIR
  1635. # define __WDLPRO , int sepc
  1636. # define __WDL , sepc
  1637. # define __WDLDEF int sepc;
  1638. # define WISEP , (uO.W_flag ? '/' : '\0')
  1639. #else
  1640. # define __WDLPRO
  1641. # define __WDL
  1642. # define __WDLDEF
  1643. # define WISEP
  1644. #endif
  1645. /**************/
  1646. /* Typedefs */
  1647. /**************/
  1648. #ifdef ZIP64_SUPPORT
  1649. # ifndef Z_UINT8_DEFINED
  1650. # if (defined(__GNUC__) || defined(__hpux) || defined(__SUNPRO_C))
  1651. typedef unsigned long long z_uint8;
  1652. # else
  1653. typedef unsigned __int64 z_uint8;
  1654. # endif
  1655. # define Z_UINT8_DEFINED
  1656. # endif
  1657. #endif
  1658. #ifndef Z_UINT4_DEFINED
  1659. # if (defined(MODERN) && !defined(NO_LIMITS_H))
  1660. # if (defined(UINT_MAX) && (UINT_MAX == 0xffffffffUL))
  1661. typedef unsigned int z_uint4;
  1662. # define Z_UINT4_DEFINED
  1663. # else
  1664. # if (defined(ULONG_MAX) && (ULONG_MAX == 0xffffffffUL))
  1665. typedef unsigned long z_uint4;
  1666. # define Z_UINT4_DEFINED
  1667. # else
  1668. # if (defined(USHRT_MAX) && (USHRT_MAX == 0xffffffffUL))
  1669. typedef unsigned short z_uint4;
  1670. # define Z_UINT4_DEFINED
  1671. # endif
  1672. # endif
  1673. # endif
  1674. # endif /* MODERN && !NO_LIMITS_H */
  1675. #endif /* !Z_UINT4_DEFINED */
  1676. #ifndef Z_UINT4_DEFINED
  1677. typedef ulg z_uint4;
  1678. # define Z_UINT4_DEFINED
  1679. #endif
  1680. /* The following three user-defined unsigned integer types are used for
  1681. holding zipfile entities (required widths without / with Zip64 support):
  1682. a) sizes and offset of zipfile entries
  1683. (4 bytes / 8 bytes)
  1684. b) enumeration and counts of zipfile entries
  1685. (2 bytes / 8 bytes)
  1686. Remark: internally, we use 4 bytes for archive member counting in the
  1687. No-Zip64 case, because UnZip supports more than 64k entries for
  1688. classic Zip archives without Zip64 extensions.
  1689. c) enumeration and counts of zipfile volumes of multivolume archives
  1690. (2 bytes / 4 bytes)
  1691. */
  1692. #ifdef ZIP64_SUPPORT
  1693. typedef z_uint8 zusz_t; /* zipentry sizes & offsets */
  1694. typedef z_uint8 zucn_t; /* archive entry counts */
  1695. typedef z_uint4 zuvl_t; /* multivolume numbers */
  1696. # define MASK_ZUCN64 (~(zucn_t)0)
  1697. /* In case we ever get to support an environment where z_uint8 may be WIDER
  1698. than 64 bit wide, we will have to apply a construct similar to
  1699. #define MASK_ZUCN64 (~(zucn_t)0 & (zucn_t)0xffffffffffffffffULL)
  1700. for the 64-bit mask.
  1701. */
  1702. #else
  1703. typedef ulg zusz_t; /* zipentry sizes & offsets */
  1704. typedef unsigned int zucn_t; /* archive entry counts */
  1705. typedef unsigned short zuvl_t; /* multivolume numbers */
  1706. # define MASK_ZUCN64 (~(zucn_t)0)
  1707. #endif
  1708. #define MASK_ZUCN16 ((zucn_t)0xFFFF)
  1709. #ifdef NO_UID_GID
  1710. # ifdef UID_USHORT
  1711. typedef unsigned short uid_t; /* TI SysV.3 */
  1712. typedef unsigned short gid_t;
  1713. # else
  1714. typedef unsigned int uid_t; /* SCO Xenix */
  1715. typedef unsigned int gid_t;
  1716. # endif
  1717. #endif
  1718. #if (defined(GOT_UTIMBUF) || defined(sgi) || defined(ATARI))
  1719. typedef struct utimbuf ztimbuf;
  1720. #else
  1721. typedef struct ztimbuf {
  1722. time_t actime; /* new access time */
  1723. time_t modtime; /* new modification time */
  1724. } ztimbuf;
  1725. #endif
  1726. typedef struct iztimes {
  1727. time_t atime; /* new access time */
  1728. time_t mtime; /* new modification time */
  1729. time_t ctime; /* used for creation time; NOT same as st_ctime */
  1730. } iztimes;
  1731. #ifdef SET_DIR_ATTRIB
  1732. typedef struct direntry { /* head of system-specific struct holding */
  1733. struct direntry *next; /* defered directory attributes info */
  1734. char *fn; /* filename of directory */
  1735. char buf[1]; /* start of system-specific internal data */
  1736. } direntry;
  1737. #endif /* SET_DIR_ATTRIB */
  1738. #ifdef SYMLINKS
  1739. typedef struct slinkentry { /* info for deferred symlink creation */
  1740. struct slinkentry *next; /* pointer to next entry in chain */
  1741. extent targetlen; /* length of target filespec */
  1742. extent attriblen; /* length of system-specific attrib data */
  1743. char *target; /* pointer to target filespec */
  1744. char *fname; /* pointer to name of link */
  1745. char buf[1]; /* data/name/link buffer */
  1746. } slinkentry;
  1747. #endif /* SYMLINKS */
  1748. typedef struct min_info {
  1749. zoff_t offset;
  1750. zusz_t compr_size; /* compressed size (needed if extended header) */
  1751. zusz_t uncompr_size; /* uncompressed size (needed if extended header) */
  1752. ulg crc; /* crc (needed if extended header) */
  1753. zuvl_t diskstart; /* no of volume where this entry starts */
  1754. uch hostver;
  1755. uch hostnum;
  1756. unsigned file_attr; /* local flavor, as used by creat(), chmod()... */
  1757. unsigned encrypted : 1; /* file encrypted: decrypt before uncompressing */
  1758. unsigned ExtLocHdr : 1; /* use time instead of CRC for decrypt check */
  1759. unsigned textfile : 1; /* file is text (according to zip) */
  1760. unsigned textmode : 1; /* file is to be extracted as text */
  1761. unsigned lcflag : 1; /* convert filename to lowercase */
  1762. unsigned vollabel : 1; /* "file" is an MS-DOS volume (disk) label */
  1763. #ifdef SYMLINKS
  1764. unsigned symlink : 1; /* file is a symbolic link */
  1765. #endif
  1766. unsigned HasUxAtt : 1; /* crec ext_file_attr has Unix style mode bits */
  1767. #ifdef UNICODE_SUPPORT
  1768. unsigned GPFIsUTF8: 1; /* crec gen_purpose_flag UTF-8 bit 11 is set */
  1769. #endif
  1770. #ifndef SFX
  1771. char Far *cfilname; /* central header version of filename */
  1772. #endif
  1773. } min_info;
  1774. typedef struct VMStimbuf {
  1775. char *revdate; /* (both roughly correspond to Unix modtime/st_mtime) */
  1776. char *credate;
  1777. } VMStimbuf;
  1778. /*---------------------------------------------------------------------------
  1779. Zipfile work area declarations.
  1780. ---------------------------------------------------------------------------*/
  1781. #ifdef MALLOC_WORK
  1782. union work {
  1783. struct { /* unshrink(): */
  1784. shrint *Parent; /* pointer to (8192 * sizeof(shrint)) */
  1785. uch *value; /* pointer to 8KB char buffer */
  1786. uch *Stack; /* pointer to another 8KB char buffer */
  1787. } shrink;
  1788. uch *Slide; /* explode(), inflate(), unreduce() */
  1789. };
  1790. #else /* !MALLOC_WORK */
  1791. union work {
  1792. struct { /* unshrink(): */
  1793. shrint Parent[HSIZE]; /* (8192 * sizeof(shrint)) == 16KB minimum */
  1794. uch value[HSIZE]; /* 8KB */
  1795. uch Stack[HSIZE]; /* 8KB */
  1796. } shrink; /* total = 32KB minimum; 80KB on Cray/Alpha */
  1797. uch Slide[WSIZE]; /* explode(), inflate(), unreduce() */
  1798. };
  1799. #endif /* ?MALLOC_WORK */
  1800. #define slide G.area.Slide
  1801. #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
  1802. # define redirSlide G.redirect_sldptr
  1803. #else
  1804. # define redirSlide G.area.Slide
  1805. #endif
  1806. /*---------------------------------------------------------------------------
  1807. Zipfile layout declarations. If these headers ever change, make sure the
  1808. xxREC_SIZE defines (above) change with them!
  1809. ---------------------------------------------------------------------------*/
  1810. typedef uch local_byte_hdr[ LREC_SIZE ];
  1811. # define L_VERSION_NEEDED_TO_EXTRACT_0 0
  1812. # define L_VERSION_NEEDED_TO_EXTRACT_1 1
  1813. # define L_GENERAL_PURPOSE_BIT_FLAG 2
  1814. # define L_COMPRESSION_METHOD 4
  1815. # define L_LAST_MOD_DOS_DATETIME 6
  1816. # define L_CRC32 10
  1817. # define L_COMPRESSED_SIZE 14
  1818. # define L_UNCOMPRESSED_SIZE 18
  1819. # define L_FILENAME_LENGTH 22
  1820. # define L_EXTRA_FIELD_LENGTH 24
  1821. typedef uch cdir_byte_hdr[ CREC_SIZE ];
  1822. # define C_VERSION_MADE_BY_0 0
  1823. # define C_VERSION_MADE_BY_1 1
  1824. # define C_VERSION_NEEDED_TO_EXTRACT_0 2
  1825. # define C_VERSION_NEEDED_TO_EXTRACT_1 3
  1826. # define C_GENERAL_PURPOSE_BIT_FLAG 4
  1827. # define C_COMPRESSION_METHOD 6
  1828. # define C_LAST_MOD_DOS_DATETIME 8
  1829. # define C_CRC32 12
  1830. # define C_COMPRESSED_SIZE 16
  1831. # define C_UNCOMPRESSED_SIZE 20
  1832. # define C_FILENAME_LENGTH 24
  1833. # define C_EXTRA_FIELD_LENGTH 26
  1834. # define C_FILE_COMMENT_LENGTH 28
  1835. # define C_DISK_NUMBER_START 30
  1836. # define C_INTERNAL_FILE_ATTRIBUTES 32
  1837. # define C_EXTERNAL_FILE_ATTRIBUTES 34
  1838. # define C_RELATIVE_OFFSET_LOCAL_HEADER 38
  1839. typedef uch ec_byte_rec[ ECREC_SIZE+4 ];
  1840. /* define SIGNATURE 0 space-holder only */
  1841. # define NUMBER_THIS_DISK 4
  1842. # define NUM_DISK_WITH_START_CEN_DIR 6
  1843. # define NUM_ENTRIES_CEN_DIR_THS_DISK 8
  1844. # define TOTAL_ENTRIES_CENTRAL_DIR 10
  1845. # define SIZE_CENTRAL_DIRECTORY 12
  1846. # define OFFSET_START_CENTRAL_DIRECTORY 16
  1847. # define ZIPFILE_COMMENT_LENGTH 20
  1848. typedef uch ec_byte_loc64[ ECLOC64_SIZE+4 ];
  1849. # define NUM_DISK_START_EOCDR64 4
  1850. # define OFFSET_START_EOCDR64 8
  1851. # define NUM_THIS_DISK_LOC64 16
  1852. typedef uch ec_byte_rec64[ ECREC64_SIZE+4 ];
  1853. # define ECREC64_LENGTH 4
  1854. # define EC_VERSION_MADE_BY_0 12
  1855. # define EC_VERSION_NEEDED_0 14
  1856. # define NUMBER_THIS_DSK_REC64 16
  1857. # define NUM_DISK_START_CEN_DIR64 20
  1858. # define NUM_ENTRIES_CEN_DIR_THS_DISK64 24
  1859. # define TOTAL_ENTRIES_CENTRAL_DIR64 32
  1860. # define SIZE_CENTRAL_DIRECTORY64 40
  1861. # define OFFSET_START_CENTRAL_DIRECT64 48
  1862. /* The following structs are used to hold all header data of a zip entry.
  1863. Traditionally, the structs' layouts followed the data layout of the
  1864. corresponding zipfile header structures. However, the zipfile header
  1865. layouts were designed in the old ages of 16-bit CPUs, they are subject
  1866. to structure padding and/or alignment issues on newer systems with a
  1867. "natural word width" of more than 2 bytes.
  1868. Please note that the structure members are now reordered by size
  1869. (top-down), to prevent internal padding and optimize memory usage!
  1870. */
  1871. typedef struct local_file_header { /* LOCAL */
  1872. zusz_t csize;
  1873. zusz_t ucsize;
  1874. ulg last_mod_dos_datetime;
  1875. ulg crc32;
  1876. uch version_needed_to_extract[2];
  1877. ush general_purpose_bit_flag;
  1878. ush compression_method;
  1879. ush filename_length;
  1880. ush extra_field_length;
  1881. } local_file_hdr;
  1882. typedef struct central_directory_file_header { /* CENTRAL */
  1883. zusz_t csize;
  1884. zusz_t ucsize;
  1885. zusz_t relative_offset_local_header;
  1886. ulg last_mod_dos_datetime;
  1887. ulg crc32;
  1888. ulg external_file_attributes;
  1889. zuvl_t disk_number_start;
  1890. ush internal_file_attributes;
  1891. uch version_made_by[2];
  1892. uch version_needed_to_extract[2];
  1893. ush general_purpose_bit_flag;
  1894. ush compression_method;
  1895. ush filename_length;
  1896. ush extra_field_length;
  1897. ush file_comment_length;
  1898. } cdir_file_hdr;
  1899. typedef struct end_central_dir_record { /* END CENTRAL */
  1900. zusz_t size_central_directory;
  1901. zusz_t offset_start_central_directory;
  1902. zucn_t num_entries_centrl_dir_ths_disk;
  1903. zucn_t total_entries_central_dir;
  1904. zuvl_t number_this_disk;
  1905. zuvl_t num_disk_start_cdir;
  1906. int have_ecr64; /* valid Zip64 ecdir-record exists */
  1907. int is_zip64_archive; /* Zip64 ecdir-record is mandatory */
  1908. ush zipfile_comment_length;
  1909. } ecdir_rec;
  1910. /* Huffman code lookup table entry--this entry is four bytes for machines
  1911. that have 16-bit pointers (e.g. PC's in the small or medium model).
  1912. Valid extra bits are 0..16. e == 31 is EOB (end of block), e == 32
  1913. means that v is a literal, 32 < e < 64 means that v is a pointer to
  1914. the next table, which codes (e & 31) bits, and lastly e == 99 indicates
  1915. an unused code. If a code with e == 99 is looked up, this implies an
  1916. error in the data. */
  1917. struct huft {
  1918. uch e; /* number of extra bits or operation */
  1919. uch b; /* number of bits in this code or subcode */
  1920. union {
  1921. ush n; /* literal, length base, or distance base */
  1922. struct huft *t; /* pointer to next level of table */
  1923. } v;
  1924. };
  1925. typedef struct _APIDocStruct {
  1926. char *compare;
  1927. char *function;
  1928. char *syntax;
  1929. char *purpose;
  1930. } APIDocStruct;
  1931. /*************/
  1932. /* Globals */
  1933. /*************/
  1934. #if (defined(OS2) && !defined(FUNZIP))
  1935. # include "os2/os2data.h"
  1936. #endif
  1937. #include "globals.h"
  1938. /*************************/
  1939. /* Function Prototypes */
  1940. /*************************/
  1941. /*---------------------------------------------------------------------------
  1942. Functions in unzip.c (initialization routines):
  1943. ---------------------------------------------------------------------------*/
  1944. #ifndef WINDLL
  1945. int MAIN OF((int argc, char **argv));
  1946. int unzip OF((__GPRO__ int argc, char **argv));
  1947. int uz_opts OF((__GPRO__ int *pargc, char ***pargv));
  1948. int usage OF((__GPRO__ int error));
  1949. #endif /* !WINDLL */
  1950. /*---------------------------------------------------------------------------
  1951. Functions in process.c (main driver routines):
  1952. ---------------------------------------------------------------------------*/
  1953. int process_zipfiles OF((__GPRO));
  1954. void free_G_buffers OF((__GPRO));
  1955. /* static int do_seekable OF((__GPRO__ int lastchance)); */
  1956. /* static int find_ecrec OF((__GPRO__ long searchlen)); */
  1957. /* static int process_central_comment OF((__GPRO)); */
  1958. int process_cdir_file_hdr OF((__GPRO));
  1959. int process_local_file_hdr OF((__GPRO));
  1960. int getZip64Data OF((__GPRO__ ZCONST uch *ef_buf,
  1961. unsigned ef_len));
  1962. #ifdef UNICODE_SUPPORT
  1963. int getUnicodeData OF((__GPRO__ ZCONST uch *ef_buf,
  1964. unsigned ef_len));
  1965. #endif
  1966. unsigned ef_scan_for_izux OF((ZCONST uch *ef_buf, unsigned ef_len,
  1967. int ef_is_c, ulg dos_mdatetime,
  1968. iztimes *z_utim, ulg *z_uidgid));
  1969. #if (defined(RISCOS) || defined(ACORN_FTYPE_NFS))
  1970. zvoid *getRISCOSexfield OF((ZCONST uch *ef_buf, unsigned ef_len));
  1971. #endif
  1972. #ifndef SFX
  1973. /*---------------------------------------------------------------------------
  1974. Functions in zipinfo.c (`zipinfo-style' listing routines):
  1975. ---------------------------------------------------------------------------*/
  1976. #ifndef NO_ZIPINFO
  1977. #ifndef WINDLL
  1978. int zi_opts OF((__GPRO__ int *pargc, char ***pargv));
  1979. #endif
  1980. void zi_end_central OF((__GPRO));
  1981. int zipinfo OF((__GPRO));
  1982. /* static int zi_long OF((__GPRO__ zusz_t *pEndprev)); */
  1983. /* static int zi_short OF((__GPRO)); */
  1984. /* static char *zi_time OF((__GPRO__ ZCONST ulg *datetimez,
  1985. ZCONST time_t *modtimez, char *d_t_str));*/
  1986. #endif /* !NO_ZIPINFO */
  1987. /*---------------------------------------------------------------------------
  1988. Functions in list.c (generic zipfile-listing routines):
  1989. ---------------------------------------------------------------------------*/
  1990. int list_files OF((__GPRO));
  1991. #ifdef TIMESTAMP
  1992. int get_time_stamp OF((__GPRO__ time_t *last_modtime,
  1993. ulg *nmember));
  1994. #endif
  1995. int ratio OF((zusz_t uc, zusz_t c));
  1996. void fnprint OF((__GPRO));
  1997. #endif /* !SFX */
  1998. /*---------------------------------------------------------------------------
  1999. Functions in fileio.c:
  2000. ---------------------------------------------------------------------------*/
  2001. int open_input_file OF((__GPRO));
  2002. int open_outfile OF((__GPRO)); /* also vms.c */
  2003. void undefer_input OF((__GPRO));
  2004. void defer_leftover_input OF((__GPRO));
  2005. unsigned readbuf OF((__GPRO__ char *buf, register unsigned len));
  2006. int readbyte OF((__GPRO));
  2007. int fillinbuf OF((__GPRO));
  2008. int seek_zipf OF((__GPRO__ zoff_t abs_offset));
  2009. #ifdef FUNZIP
  2010. int flush OF((__GPRO__ ulg size)); /* actually funzip.c */
  2011. #else
  2012. int flush OF((__GPRO__ uch *buf, ulg size, int unshrink));
  2013. #endif
  2014. /* static int disk_error OF((__GPRO)); */
  2015. void handler OF((int signal));
  2016. time_t dos_to_unix_time OF((ulg dos_datetime));
  2017. int check_for_newer OF((__GPRO__ char *filename)); /* os2,vmcms,vms */
  2018. int do_string OF((__GPRO__ unsigned int length, int option));
  2019. ush makeword OF((ZCONST uch *b));
  2020. ulg makelong OF((ZCONST uch *sig));
  2021. zusz_t makeint64 OF((ZCONST uch *sig));
  2022. char *fzofft OF((__GPRO__ zoff_t val,
  2023. ZCONST char *pre, ZCONST char *post));
  2024. #if (!defined(STR_TO_ISO) || defined(NEED_STR2ISO))
  2025. char *str2iso OF((char *dst, ZCONST char *src));
  2026. #endif
  2027. #if (!defined(STR_TO_OEM) || defined(NEED_STR2OEM))
  2028. char *str2oem OF((char *dst, ZCONST char *src));
  2029. #endif
  2030. #ifdef NO_STRNICMP
  2031. int zstrnicmp OF((register ZCONST char *s1,
  2032. register ZCONST char *s2,
  2033. register unsigned n));
  2034. #endif
  2035. #ifdef REGULUS
  2036. int zstat OF((ZCONST char *p, struct stat *s));
  2037. #endif
  2038. #ifdef ZMEM /* MUST be ifdef'd because of conflicts with the standard def. */
  2039. zvoid *memset OF((register zvoid *, register int, register unsigned int));
  2040. int memcmp OF((register ZCONST zvoid*, register ZCONST zvoid *,
  2041. register unsigned int));
  2042. zvoid *memcpy OF((register zvoid *, register ZCONST zvoid *,
  2043. register unsigned int));
  2044. #endif
  2045. #ifdef NEED_UZMBCLEN
  2046. extent uzmbclen OF((ZCONST unsigned char *ptr));
  2047. #endif
  2048. #ifdef NEED_UZMBSCHR
  2049. unsigned char *uzmbschr OF((ZCONST unsigned char *str, unsigned int c));
  2050. #endif
  2051. #ifdef NEED_UZMBSRCHR
  2052. unsigned char *uzmbsrchr OF((ZCONST unsigned char *str, unsigned int c));
  2053. #endif
  2054. #ifdef SMALL_MEM
  2055. char *fLoadFarString OF((__GPRO__ const char Far *sz));
  2056. char *fLoadFarStringSmall OF((__GPRO__ const char Far *sz));
  2057. char *fLoadFarStringSmall2 OF((__GPRO__ const char Far *sz));
  2058. #ifndef zfstrcpy
  2059. char Far * Far zfstrcpy OF((char Far *s1, const char Far *s2));
  2060. #endif
  2061. #if (!defined(SFX) && !defined(zfstrcmp))
  2062. int Far zfstrcmp OF((const char Far *s1, const char Far *s2));
  2063. #endif
  2064. #endif
  2065. /*---------------------------------------------------------------------------
  2066. Functions in extract.c:
  2067. ---------------------------------------------------------------------------*/
  2068. int extract_or_test_files OF((__GPRO));
  2069. /* static int store_info OF((void)); */
  2070. /* static int extract_or_test_member OF((__GPRO)); */
  2071. /* static int TestExtraField OF((__GPRO__ uch *ef, unsigned ef_len)); */
  2072. /* static int test_OS2 OF((__GPRO__ uch *eb, unsigned eb_size)); */
  2073. /* static int test_NT OF((__GPRO__ uch *eb, unsigned eb_size)); */
  2074. #ifndef SFX
  2075. unsigned find_compr_idx OF((unsigned compr_methodnum));
  2076. #endif
  2077. int memextract OF((__GPRO__ uch *tgt, ulg tgtsize,
  2078. ZCONST uch *src, ulg srcsize));
  2079. int memflush OF((__GPRO__ ZCONST uch *rawbuf, ulg size));
  2080. #if (defined(VMS) || defined(VMS_TEXT_CONV))
  2081. uch *extract_izvms_block OF((__GPRO__ ZCONST uch *ebdata,
  2082. unsigned size, unsigned *retlen,
  2083. ZCONST uch *init, unsigned needlen));
  2084. #endif
  2085. char *fnfilter OF((ZCONST char *raw, uch *space,
  2086. extent size));
  2087. /*---------------------------------------------------------------------------
  2088. Decompression functions:
  2089. ---------------------------------------------------------------------------*/
  2090. #if (!defined(SFX) && !defined(FUNZIP))
  2091. int explode OF((__GPRO)); /* explode.c */
  2092. #endif
  2093. int huft_free OF((struct huft *t)); /* inflate.c */
  2094. int huft_build OF((__GPRO__ ZCONST unsigned *b, unsigned n,
  2095. unsigned s, ZCONST ush *d, ZCONST uch *e,
  2096. struct huft **t, unsigned *m));
  2097. #ifdef USE_ZLIB
  2098. int UZinflate OF((__GPRO__ int is_defl64)); /* inflate.c */
  2099. # define inflate_free(x) inflateEnd(&((Uz_Globs *)(&G))->dstrm)
  2100. #else
  2101. int inflate OF((__GPRO__ int is_defl64)); /* inflate.c */
  2102. int inflate_free OF((__GPRO)); /* inflate.c */
  2103. #endif /* ?USE_ZLIB */
  2104. #if (!defined(SFX) && !defined(FUNZIP))
  2105. #ifndef COPYRIGHT_CLEAN
  2106. int unreduce OF((__GPRO)); /* unreduce.c */
  2107. /* static void LoadFollowers OF((__GPRO__ f_array *follower, uch *Slen));
  2108. * unreduce.c */
  2109. #endif /* !COPYRIGHT_CLEAN */
  2110. #ifndef LZW_CLEAN
  2111. int unshrink OF((__GPRO)); /* unshrink.c */
  2112. /* static void partial_clear OF((__GPRO)); * unshrink.c */
  2113. #endif /* !LZW_CLEAN */
  2114. #endif /* !SFX && !FUNZIP */
  2115. #ifdef USE_BZIP2
  2116. int UZbunzip2 OF((__GPRO)); /* extract.c */
  2117. void bz_internal_error OF((int bzerrcode)); /* ubz2err.c */
  2118. #endif
  2119. /*---------------------------------------------------------------------------
  2120. Internal API functions (only included in DLL versions):
  2121. ---------------------------------------------------------------------------*/
  2122. #ifdef DLL
  2123. void setFileNotFound OF((__GPRO)); /* api.c */
  2124. int unzipToMemory OF((__GPRO__ char *zip, char *file,
  2125. UzpBuffer *retstr)); /* api.c */
  2126. int redirect_outfile OF((__GPRO)); /* api.c */
  2127. int writeToMemory OF((__GPRO__ ZCONST uch *rawbuf,
  2128. extent size)); /* api.c */
  2129. int close_redirect OF((__GPRO)); /* api.c */
  2130. /* this obsolescent entry point kept for compatibility: */
  2131. int UzpUnzip OF((int argc, char **argv));/* use UzpMain */
  2132. #ifdef OS2DLL
  2133. int varmessage OF((__GPRO__ ZCONST uch *buf, ulg size));
  2134. int varputchar OF((__GPRO__ int c)); /* rexxapi.c */
  2135. int finish_REXX_redirect OF((__GPRO)); /* rexxapi.c */
  2136. #endif
  2137. #ifdef API_DOC
  2138. void APIhelp OF((__GPRO__ int argc, char **argv));
  2139. #endif /* apihelp.c */
  2140. #endif /* DLL */
  2141. /*---------------------------------------------------------------------------
  2142. MSDOS-only functions:
  2143. ---------------------------------------------------------------------------*/
  2144. #ifdef MSDOS
  2145. #if (!defined(FUNZIP) && !defined(SFX) && !defined(WINDLL))
  2146. void check_for_windows OF((ZCONST char *app)); /* msdos.c */
  2147. #endif
  2148. #if (defined(__GO32__) || defined(__EMX__))
  2149. unsigned _dos_getcountryinfo(void *); /* msdos.c */
  2150. #if (!defined(__DJGPP__) || (__DJGPP__ < 2))
  2151. unsigned _dos_setftime(int, unsigned, unsigned); /* msdos.c */
  2152. unsigned _dos_setfileattr(const char *, unsigned); /* msdos.c */
  2153. unsigned _dos_creat(const char *, unsigned, int *); /* msdos.c */
  2154. void _dos_getdrive(unsigned *); /* msdos.c */
  2155. unsigned _dos_close(int); /* msdos.c */
  2156. #endif /* !__DJGPP__ || (__DJGPP__ < 2) */
  2157. #endif /* __GO32__ || __EMX__ */
  2158. #endif
  2159. /*---------------------------------------------------------------------------
  2160. OS/2-only functions:
  2161. ---------------------------------------------------------------------------*/
  2162. #ifdef OS2 /* GetFileTime conflicts with something in Win32 header files */
  2163. #if (defined(REENTRANT) && defined(USETHREADID))
  2164. ulg GetThreadId OF((void));
  2165. #endif
  2166. int GetCountryInfo OF((void)); /* os2.c */
  2167. long GetFileTime OF((ZCONST char *name)); /* os2.c */
  2168. /* static void SetPathAttrTimes OF((__GPRO__ int flags, int dir)); os2.c */
  2169. /* static int SetEAs OF((__GPRO__ const char *path,
  2170. void *eablock)); os2.c */
  2171. /* static int SetACL OF((__GPRO__ const char *path,
  2172. void *eablock)); os2.c */
  2173. /* static int IsFileNameValid OF((const char *name)); os2.c */
  2174. /* static void map2fat OF((char *pathcomp, char **pEndFAT)); os2.c */
  2175. /* static int SetLongNameEA OF((char *name, char *longname)); os2.c */
  2176. /* static void InitNLS OF((void)); os2.c */
  2177. int IsUpperNLS OF((int nChr)); /* os2.c */
  2178. int ToLowerNLS OF((int nChr)); /* os2.c */
  2179. void DebugMalloc OF((void)); /* os2.c */
  2180. #endif
  2181. /*---------------------------------------------------------------------------
  2182. QDOS-only functions:
  2183. ---------------------------------------------------------------------------*/
  2184. #ifdef QDOS
  2185. int QMatch (uch, uch);
  2186. void QFilename (__GPRO__ char *);
  2187. char *Qstrfix (char *);
  2188. int QReturn (int zip_error);
  2189. #endif
  2190. /*---------------------------------------------------------------------------
  2191. TOPS20-only functions:
  2192. ---------------------------------------------------------------------------*/
  2193. #ifdef TOPS20
  2194. int upper OF((char *s)); /* tops20.c */
  2195. int enquote OF((char *s)); /* tops20.c */
  2196. int dequote OF((char *s)); /* tops20.c */
  2197. int fnlegal OF(()); /* error if prototyped? */ /* tops20.c */
  2198. #endif
  2199. /*---------------------------------------------------------------------------
  2200. VM/CMS- and MVS-only functions:
  2201. ---------------------------------------------------------------------------*/
  2202. #ifdef CMS_MVS
  2203. extent getVMMVSexfield OF((char *type, uch *ef_block, unsigned datalen));
  2204. FILE *vmmvs_open_infile OF((__GPRO)); /* vmmvs.c */
  2205. void close_infile OF((__GPRO)); /* vmmvs.c */
  2206. #endif
  2207. /*---------------------------------------------------------------------------
  2208. VMS-only functions:
  2209. ---------------------------------------------------------------------------*/
  2210. #ifdef VMS
  2211. int check_format OF((__GPRO)); /* vms.c */
  2212. /* int open_outfile OF((__GPRO)); * (see fileio.c) vms.c */
  2213. /* int flush OF((__GPRO__ uch *rawbuf, unsigned size,
  2214. int final_flag)); * (see fileio.c) vms.c */
  2215. char *vms_msg_text OF((void)); /* vms.c */
  2216. #ifdef RETURN_CODES
  2217. void return_VMS OF((__GPRO__ int zip_error)); /* vms.c */
  2218. #else
  2219. void return_VMS OF((int zip_error)); /* vms.c */
  2220. #endif
  2221. #ifdef VMSCLI
  2222. ulg vms_unzip_cmdline OF((int *, char ***)); /* cmdline.c */
  2223. int VMSCLI_usage OF((__GPRO__ int error)); /* cmdline.c */
  2224. #endif
  2225. #endif
  2226. /*---------------------------------------------------------------------------
  2227. WIN32-only functions:
  2228. ---------------------------------------------------------------------------*/
  2229. #ifdef WIN32
  2230. int IsWinNT OF((void)); /* win32.c */
  2231. #ifdef NTSD_EAS
  2232. void process_defer_NT OF((__GPRO)); /* win32.c */
  2233. int test_NTSD OF((__GPRO__ uch *eb, unsigned eb_size,
  2234. uch *eb_ucptr, ulg eb_ucsize)); /* win32.c */
  2235. # define TEST_NTSD test_NTSD
  2236. #endif
  2237. #ifdef W32_STAT_BANDAID
  2238. int zstat_win32 OF((__W32STAT_GLOBALS__
  2239. const char *path, z_stat *buf)); /* win32.c */
  2240. #endif
  2241. #endif
  2242. /*---------------------------------------------------------------------------
  2243. Miscellaneous/shared functions:
  2244. ---------------------------------------------------------------------------*/
  2245. Uz_Globs *globalsCtor OF((void)); /* globals.c */
  2246. int envargs OF((int *Pargc, char ***Pargv,
  2247. ZCONST char *envstr, ZCONST char *envstr2));
  2248. /* envargs.c */
  2249. void mksargs OF((int *argcp, char ***argvp)); /* envargs.c */
  2250. int match OF((ZCONST char *s, ZCONST char *p,
  2251. int ic __WDLPRO)); /* match.c */
  2252. int iswild OF((ZCONST char *p)); /* match.c */
  2253. /* declarations of public CRC-32 functions have been moved into crc32.h
  2254. (free_crc_table(), get_crc_table(), crc32()) crc32.c */
  2255. int dateformat OF((void)); /* local */
  2256. char dateseparator OF((void)); /* local */
  2257. #ifndef WINDLL
  2258. void version OF((__GPRO)); /* local */
  2259. #endif
  2260. int mapattr OF((__GPRO)); /* local */
  2261. int mapname OF((__GPRO__ int renamed)); /* local */
  2262. int checkdir OF((__GPRO__ char *pathcomp, int flag)); /* local */
  2263. char *do_wild OF((__GPRO__ ZCONST char *wildzipfn)); /* local */
  2264. char *GetLoadPath OF((__GPRO)); /* local */
  2265. #if (defined(MORE) && (defined(ATH_BEO_UNX) || defined(QDOS) || defined(VMS)))
  2266. int screensize OF((int *tt_rows, int *tt_cols)); /* local */
  2267. # if defined(VMS)
  2268. int screenlinewrap OF((void)); /* local */
  2269. # endif
  2270. #endif /* MORE && (ATH_BEO_UNX || QDOS || VMS) */
  2271. #ifdef OS2_W32
  2272. int SetFileSize OF((FILE *file, zusz_t filesize)); /* local */
  2273. #endif
  2274. #ifndef MTS /* macro in MTS */
  2275. void close_outfile OF((__GPRO)); /* local */
  2276. #endif
  2277. #ifdef SET_SYMLINK_ATTRIBS
  2278. int set_symlnk_attribs OF((__GPRO__ slinkentry *slnk_entry)); /* local */
  2279. #endif
  2280. #ifdef SET_DIR_ATTRIB
  2281. int defer_dir_attribs OF((__GPRO__ direntry **pd)); /* local */
  2282. int set_direc_attribs OF((__GPRO__ direntry *d)); /* local */
  2283. #endif
  2284. #ifdef TIMESTAMP
  2285. # ifdef WIN32
  2286. int stamp_file OF((__GPRO__
  2287. ZCONST char *fname, time_t modtime)); /* local */
  2288. # else
  2289. int stamp_file OF((ZCONST char *fname, time_t modtime)); /* local */
  2290. # endif
  2291. #endif
  2292. #ifdef NEED_ISO_OEM_INIT
  2293. void prepare_ISO_OEM_translat OF((__GPRO)); /* local */
  2294. #endif
  2295. #if (defined(MALLOC_WORK) && defined(MY_ZCALLOC))
  2296. zvoid far *zcalloc OF((unsigned int, unsigned int));
  2297. zvoid zcfree OF((zvoid far *));
  2298. #endif /* MALLOC_WORK && MY_ZCALLOC */
  2299. #ifdef SYSTEM_SPECIFIC_CTOR
  2300. void SYSTEM_SPECIFIC_CTOR OF((__GPRO)); /* local */
  2301. #endif
  2302. #ifdef SYSTEM_SPECIFIC_DTOR
  2303. void SYSTEM_SPECIFIC_DTOR OF((__GPRO)); /* local */
  2304. #endif
  2305. /************/
  2306. /* Macros */
  2307. /************/
  2308. #ifndef MAX
  2309. # define MAX(a,b) ((a) > (b) ? (a) : (b))
  2310. #endif
  2311. #ifndef MIN
  2312. # define MIN(a,b) ((a) < (b) ? (a) : (b))
  2313. #endif
  2314. #ifdef DEBUG
  2315. # if (defined(THEOS) && defined(NO_BOGUS_SPC))
  2316. # define NO_DEBUG_IN_MACROS
  2317. # define Trace(x) _fprintf x
  2318. # else
  2319. # define Trace(x) fprintf x
  2320. # endif
  2321. #else
  2322. # define Trace(x)
  2323. #endif
  2324. #ifdef DEBUG_TIME
  2325. # define TTrace(x) fprintf x
  2326. #else
  2327. # define TTrace(x)
  2328. #endif
  2329. #ifdef NO_DEBUG_IN_MACROS
  2330. # define MTrace(x)
  2331. #else
  2332. # define MTrace(x) Trace(x)
  2333. #endif
  2334. #if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
  2335. # define ToLower(x) ((char)(isupper((int)x)? tolower((int)x) : x))
  2336. #else
  2337. # define ToLower tolower /* assumed "smart"; used in match() */
  2338. #endif
  2339. #ifdef USE_STRM_INPUT
  2340. /* ``Replace'' the unbuffered UNIX style I/O function with similar
  2341. * standard C functions from <stdio.h>.
  2342. */
  2343. # define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
  2344. # ifdef zlseek
  2345. # undef zlseek
  2346. # endif
  2347. # define zlseek(fd,o,w) zfseeko((FILE *)(fd),(o),(w))
  2348. # define close(fd) fclose((FILE *)(fd))
  2349. #endif /* USE_STRM_INPUT */
  2350. /* The return value of the Info() "macro function" is never checked in
  2351. * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
  2352. * Info() definition for "FUNZIP" would have to be corrected:
  2353. * #define Info(buf,flag,sprf_arg) \
  2354. * (fputs((char *)(sprintf sprf_arg, (buf)), \
  2355. * (flag)&1? stderr : stdout) < 0)
  2356. */
  2357. #ifndef Info /* may already have been defined for redirection */
  2358. # ifdef FUNZIP
  2359. # define Info(buf,flag,sprf_arg) \
  2360. fputs((char *)(sprintf sprf_arg, (buf)), (flag)&1? stderr : stdout)
  2361. # else
  2362. # ifdef INT_SPRINTF /* optimized version for "int sprintf()" flavour */
  2363. # define Info(buf,flag,sprf_arg) \
  2364. (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
  2365. # else /* generic version, does not use sprintf() return value */
  2366. # define Info(buf,flag,sprf_arg) \
  2367. (*G.message)((zvoid *)&G, (uch *)(buf), \
  2368. (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
  2369. # endif
  2370. # endif
  2371. #endif /* !Info */
  2372. /* This wrapper macro around fzofft() is just defined to "hide" the
  2373. * argument needed to reference the global storage buffers.
  2374. */
  2375. #define FmZofft(val, pre, post) fzofft(__G__ val, pre, post)
  2376. /* The following macro wrappers around the fnfilter function are used many
  2377. * times to prepare archive entry names or name components for displaying
  2378. * listings and (warning/error) messages. They use sections in the upper half
  2379. * of 'slide' as buffer, since their output is normally fed through the
  2380. * Info() macro with 'slide' (the start of this area) as message buffer.
  2381. */
  2382. #define FnFilter1(fname) \
  2383. fnfilter((fname), slide + (extent)(WSIZE>>1), (extent)(WSIZE>>2))
  2384. #define FnFilter2(fname) \
  2385. fnfilter((fname), slide + (extent)((WSIZE>>1) + (WSIZE>>2)),\
  2386. (extent)(WSIZE>>2))
  2387. #ifndef FUNZIP /* used only in inflate.c */
  2388. # define MESSAGE(str,len,flag) (*G.message)((zvoid *)&G,(str),(len),(flag))
  2389. #endif
  2390. #if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
  2391. # define CRCVAL_INITIAL crc32(0L, NULL, 0)
  2392. #else
  2393. # define CRCVAL_INITIAL 0L
  2394. #endif
  2395. #ifdef SYMLINKS
  2396. /* This macro defines the Zip "made by" hosts that are considered
  2397. to support storing symbolic link entries. */
  2398. # define SYMLINK_HOST(hn) ((hn) == UNIX_ || (hn) == ATARI_ || \
  2399. (hn) == ATHEOS_ || (hn) == BEOS_ || (hn) == VMS_)
  2400. #endif
  2401. #ifndef TEST_NTSD /* "NTSD valid?" checking function */
  2402. # define TEST_NTSD NULL /* ... is not available */
  2403. #endif
  2404. #define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
  2405. {error_in_archive=error; if(error>1) return error;}
  2406. /*
  2407. * Skip a variable-length field, and report any errors. Used in zipinfo.c
  2408. * and unzip.c in several functions.
  2409. *
  2410. * macro SKIP_(length)
  2411. * ush length;
  2412. * {
  2413. * if (length && ((error = do_string(length, SKIP)) != 0)) {
  2414. * error_in_archive = error; /-* might be warning *-/
  2415. * if (error > 1) /-* fatal *-/
  2416. * return (error);
  2417. * }
  2418. * }
  2419. *
  2420. */
  2421. #ifdef FUNZIP
  2422. # define FLUSH(w) flush(__G__ (ulg)(w))
  2423. # define NEXTBYTE getc(G.in) /* redefined in crypt.h if full version */
  2424. #else
  2425. # define FLUSH(w) ((G.mem_mode) ? memflush(__G__ redirSlide,(ulg)(w)) \
  2426. : flush(__G__ redirSlide,(ulg)(w),0))
  2427. # define NEXTBYTE (G.incnt-- > 0 ? (int)(*G.inptr++) : readbyte(__G))
  2428. #endif
  2429. #define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
  2430. while (G.bits_left<=8*(int)(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
  2431. G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
  2432. zdest=(shrint)((unsigned)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
  2433. G.bits_left-=nbits;}
  2434. /*
  2435. * macro READBITS(nbits,zdest) * only used by unreduce and unshrink *
  2436. * {
  2437. * if (nbits > G.bits_left) { * fill G.bitbuf, 8*sizeof(ulg) bits *
  2438. * int temp;
  2439. *
  2440. * G.zipeof = 1;
  2441. * while (G.bits_left <= 8*(int)(sizeof(G.bitbuf)-1) &&
  2442. * (temp = NEXTBYTE) != EOF) {
  2443. * G.bitbuf |= (ulg)temp << G.bits_left;
  2444. * G.bits_left += 8;
  2445. * G.zipeof = 0;
  2446. * }
  2447. * }
  2448. * zdest = (shrint)((unsigned)G.bitbuf & mask_bits[nbits]);
  2449. * G.bitbuf >>= nbits;
  2450. * G.bits_left -= nbits;
  2451. * }
  2452. *
  2453. */
  2454. /* GRR: should use StringLower for STRLOWER macro if possible */
  2455. /*
  2456. * Copy the zero-terminated string in str1 into str2, converting any
  2457. * uppercase letters to lowercase as we go. str2 gets zero-terminated
  2458. * as well, of course. str1 and str2 may be the same character array.
  2459. */
  2460. #ifdef _MBCS
  2461. # define STRLOWER(str1, str2) \
  2462. { \
  2463. char *p, *q, c; unsigned i; \
  2464. p = (char *)(str1); \
  2465. q = (char *)(str2); \
  2466. while ((c = *p) != '\0') { \
  2467. if ((i = CLEN(p)) > 1) { \
  2468. while (i--) *q++ = *p++; \
  2469. } else { \
  2470. *q++ = (char)(isupper((int)(c))? tolower((int)(c)) : c); \
  2471. p++; \
  2472. } \
  2473. } \
  2474. *q = '\0'; \
  2475. }
  2476. #else
  2477. # define STRLOWER(str1, str2) \
  2478. { \
  2479. char *p, *q; \
  2480. p = (char *)(str1) - 1; \
  2481. q = (char *)(str2); \
  2482. while (*++p) \
  2483. *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
  2484. *q = '\0'; \
  2485. }
  2486. #endif
  2487. /*
  2488. * NOTES: This macro makes no assumptions about the characteristics of
  2489. * the tolower() function or macro (beyond its existence), nor does it
  2490. * make assumptions about the structure of the character set (i.e., it
  2491. * should work on EBCDIC machines, too). The fact that either or both
  2492. * of isupper() and tolower() may be macros has been taken into account;
  2493. * watch out for "side effects" (in the C sense) when modifying this
  2494. * macro.
  2495. */
  2496. #ifndef foreign
  2497. # define foreign(c) (c)
  2498. #endif
  2499. #ifndef native
  2500. # define native(c) (c)
  2501. # define A_TO_N(str1)
  2502. #else
  2503. # ifndef NATIVE
  2504. # define NATIVE "native chars"
  2505. # endif
  2506. # define A_TO_N(str1) {register uch *p;\
  2507. for (p=(uch *)(str1); *p; p++) *p=native(*p);}
  2508. #endif
  2509. /*
  2510. * Translate the zero-terminated string in str1 from ASCII to the native
  2511. * character set. The translation is performed in-place and uses the
  2512. * "native" macro to translate each character.
  2513. *
  2514. * NOTE: Using the "native" macro means that is it the only part of unzip
  2515. * which knows which translation table (if any) is actually in use to
  2516. * produce the native character set. This makes adding new character set
  2517. * translation tables easy, insofar as all that is needed is an appropriate
  2518. * "native" macro definition and the translation table itself. Currently,
  2519. * the only non-ASCII native character set implemented is EBCDIC, but this
  2520. * may not always be so.
  2521. */
  2522. /* default setup for internal codepage: assume ISO 8859-1 compatibility!! */
  2523. #if (!defined(NATIVE) && !defined(CRTL_CP_IS_ISO) && !defined(CRTL_CP_IS_OEM))
  2524. # define CRTL_CP_IS_ISO
  2525. #endif
  2526. /* Translate "extended ASCII" chars (OEM coding for DOS and OS/2; else
  2527. * ISO-8859-1 [ISO Latin 1, Win Ansi,...]) into the internal "native"
  2528. * code page. As with A_TO_N(), conversion is done in place.
  2529. */
  2530. #ifndef _ISO_INTERN
  2531. # ifdef CRTL_CP_IS_OEM
  2532. # ifndef IZ_ISO2OEM_ARRAY
  2533. # define IZ_ISO2OEM_ARRAY
  2534. # endif
  2535. # define _ISO_INTERN(str1) if (iso2oem) {register uch *p;\
  2536. for (p=(uch *)(str1); *p; p++)\
  2537. *p = native((*p & 0x80) ? iso2oem[*p & 0x7f] : *p);}
  2538. # else
  2539. # define _ISO_INTERN(str1) A_TO_N(str1)
  2540. # endif
  2541. #endif
  2542. #ifndef _OEM_INTERN
  2543. # ifdef CRTL_CP_IS_OEM
  2544. # define _OEM_INTERN(str1) A_TO_N(str1)
  2545. # else
  2546. # ifndef IZ_OEM2ISO_ARRAY
  2547. # define IZ_OEM2ISO_ARRAY
  2548. # endif
  2549. # define _OEM_INTERN(str1) if (oem2iso) {register uch *p;\
  2550. for (p=(uch *)(str1); *p; p++)\
  2551. *p = native((*p & 0x80) ? oem2iso[*p & 0x7f] : *p);}
  2552. # endif
  2553. #endif
  2554. #ifndef STR_TO_ISO
  2555. # ifdef CRTL_CP_IS_ISO
  2556. # define STR_TO_ISO strcpy
  2557. # else
  2558. # define STR_TO_ISO str2iso
  2559. # define NEED_STR2ISO
  2560. # endif
  2561. #endif
  2562. #ifndef STR_TO_OEM
  2563. # ifdef CRTL_CP_IS_OEM
  2564. # define STR_TO_OEM strcpy
  2565. # else
  2566. # define STR_TO_OEM str2oem
  2567. # define NEED_STR2OEM
  2568. # endif
  2569. #endif
  2570. #if (!defined(INTERN_TO_ISO) && !defined(ASCII2ISO))
  2571. # ifdef CRTL_CP_IS_OEM
  2572. /* know: "ASCII" is "OEM" */
  2573. # define ASCII2ISO(c) \
  2574. ((((c) & 0x80) && oem2iso) ? oem2iso[(c) & 0x7f] : (c))
  2575. # if (defined(NEED_STR2ISO) && !defined(CRYP_USES_OEM2ISO))
  2576. # define CRYP_USES_OEM2ISO
  2577. # endif
  2578. # else
  2579. /* assume: "ASCII" is "ISO-ANSI" */
  2580. # define ASCII2ISO(c) (c)
  2581. # endif
  2582. #endif
  2583. #if (!defined(INTERN_TO_OEM) && !defined(ASCII2OEM))
  2584. # ifdef CRTL_CP_IS_OEM
  2585. /* know: "ASCII" is "OEM" */
  2586. # define ASCII2OEM(c) (c)
  2587. # else
  2588. /* assume: "ASCII" is "ISO-ANSI" */
  2589. # define ASCII2OEM(c) \
  2590. ((((c) & 0x80) && iso2oem) ? iso2oem[(c) & 0x7f] : (c))
  2591. # if (defined(NEED_STR2OEM) && !defined(CRYP_USES_ISO2OEM))
  2592. # define CRYP_USES_ISO2OEM
  2593. # endif
  2594. # endif
  2595. #endif
  2596. /* codepage conversion setup for testp() in crypt.c */
  2597. #ifdef CRTL_CP_IS_ISO
  2598. # ifndef STR_TO_CP2
  2599. # define STR_TO_CP2 STR_TO_OEM
  2600. # endif
  2601. #else
  2602. # ifdef CRTL_CP_IS_OEM
  2603. # ifndef STR_TO_CP2
  2604. # define STR_TO_CP2 STR_TO_ISO
  2605. # endif
  2606. # else /* native internal CP is neither ISO nor OEM */
  2607. # ifndef STR_TO_CP1
  2608. # define STR_TO_CP1 STR_TO_ISO
  2609. # endif
  2610. # ifndef STR_TO_CP2
  2611. # define STR_TO_CP2 STR_TO_OEM
  2612. # endif
  2613. # endif
  2614. #endif
  2615. /* Convert filename (and file comment string) into "internal" charset.
  2616. * This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
  2617. * codepage when made on
  2618. * -> DOS (this includes 16-bit Windows 3.1) (FS_FAT_)
  2619. * -> OS/2 (FS_HPFS_)
  2620. * -> Win95/WinNT with Nico Mak's WinZip (FS_NTFS_ && hostver == "5.0")
  2621. * EXCEPTIONS:
  2622. * PKZIP for Windows 2.5, 2.6, and 4.0 flag their entries as "FS_FAT_", but
  2623. * the filename stored in the local header is coded in Windows ANSI (CP 1252
  2624. * resp. ISO 8859-1 on US and western Europe locale settings).
  2625. * Likewise, PKZIP for UNIX 2.51 flags its entries as "FS_FAT_", but the
  2626. * filenames stored in BOTH the local and the central header are coded
  2627. * in the local system's codepage (usually ANSI codings like ISO 8859-1).
  2628. *
  2629. * All other ports are assumed to code zip entry filenames in ISO 8859-1.
  2630. */
  2631. #ifndef Ext_ASCII_TO_Native
  2632. # define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
  2633. if (((hostnum) == FS_FAT_ && \
  2634. !(((islochdr) || (isuxatt)) && \
  2635. ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
  2636. (hostnum) == FS_HPFS_ || \
  2637. ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
  2638. _OEM_INTERN((string)); \
  2639. } else { \
  2640. _ISO_INTERN((string)); \
  2641. }
  2642. #endif
  2643. /**********************/
  2644. /* Global constants */
  2645. /**********************/
  2646. extern ZCONST unsigned near mask_bits[17];
  2647. extern ZCONST char *fnames[2];
  2648. #ifdef EBCDIC
  2649. extern ZCONST uch ebcdic[];
  2650. #endif
  2651. #ifdef IZ_ISO2OEM_ARRAY
  2652. extern ZCONST uch Far *iso2oem;
  2653. extern ZCONST uch Far iso2oem_850[];
  2654. #endif
  2655. #ifdef IZ_OEM2ISO_ARRAY
  2656. extern ZCONST uch Far *oem2iso;
  2657. extern ZCONST uch Far oem2iso_850[];
  2658. #endif
  2659. extern ZCONST char Far VersionDate[];
  2660. extern ZCONST char Far CentSigMsg[];
  2661. #ifndef SFX
  2662. extern ZCONST char Far EndSigMsg[];
  2663. #endif
  2664. extern ZCONST char Far SeekMsg[];
  2665. extern ZCONST char Far FilenameNotMatched[];
  2666. extern ZCONST char Far ExclFilenameNotMatched[];
  2667. extern ZCONST char Far ReportMsg[];
  2668. #ifndef SFX
  2669. extern ZCONST char Far Zipnfo[];
  2670. extern ZCONST char Far CompiledWith[];
  2671. #endif /* !SFX */
  2672. /***********************************/
  2673. /* Global (shared?) RTL variables */
  2674. /***********************************/
  2675. #ifdef DECLARE_ERRNO
  2676. extern int errno;
  2677. #endif
  2678. /*---------------------------------------------------------------------
  2679. Unicode Support
  2680. 28 August 2005
  2681. ---------------------------------------------------------------------*/
  2682. #if (defined(UNICODE_SUPPORT) && defined(UNICODE_WCHAR))
  2683. /* Default character when a zwchar too big for wchar_t */
  2684. # define zwchar_to_wchar_t_default_char '_'
  2685. /* Default character string when wchar_t does not convert to mb */
  2686. # define wide_to_mb_default_string "_"
  2687. /* wide character type */
  2688. typedef unsigned long zwchar;
  2689. /* UTF-8 related conversion functions, currently found in process.c */
  2690. # if 0 /* currently unused */
  2691. /* check if string is all ASCII */
  2692. int is_ascii_string OF((ZCONST char *mbstring));
  2693. # endif /* unused */
  2694. /* convert UTF-8 string to multi-byte string */
  2695. char *utf8_to_local_string OF((ZCONST char *utf8_string, int escape_all));
  2696. /* convert UTF-8 string to wide string */
  2697. zwchar *utf8_to_wide_string OF((ZCONST char *utf8_string));
  2698. /* convert wide string to multi-byte string */
  2699. char *wide_to_local_string OF((ZCONST zwchar *wide_string, int escape_all));
  2700. # if 0 /* currently unused */
  2701. /* convert local string to multi-byte display string */
  2702. char *local_to_display_string OF((ZCONST char *local_string));
  2703. # endif /* unused */
  2704. /* convert wide character to escape string */
  2705. char *wide_to_escape_string OF((unsigned long));
  2706. # define utf8_to_escaped_string(utf8_string) \
  2707. utf8_to_local_string(utf8_string, TRUE)
  2708. # if 0 /* currently unused */
  2709. /* convert escape string to wide character */
  2710. unsigned long escape_string_to_wide OF((ZCONST char *escape_string));
  2711. /* convert local to UTF-8 */
  2712. char *local_to_utf8_string OF ((ZCONST char *local_string));
  2713. /* convert local to wide string */
  2714. zwchar *local_to_wide_string OF ((ZCONST char *local_string));
  2715. /* convert wide string to UTF-8 */
  2716. char *wide_to_utf8_string OF((ZCONST zwchar *wide_string));
  2717. # endif /* unused */
  2718. #endif /* UNICODE_SUPPORT && UNICODE_WCHAR */
  2719. #endif /* !__unzpriv_h */