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.

444 lines
17KB

  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. globals.h
  10. There is usually no need to include this file since unzip.h includes it.
  11. This header file is used by all of the UnZip source files. It contains
  12. a struct definition that is used to "house" all of the global variables.
  13. This is done to allow for multithreaded environments (OS/2, NT, Win95,
  14. Unix) to call UnZip through an API without a semaphore. REENTRANT should
  15. be defined for all platforms that require this.
  16. GLOBAL CONSTRUCTOR AND DESTRUCTOR (API WRITERS READ THIS!!!)
  17. ------------------------------------------------------------
  18. No, it's not C++, but it's as close as we can get with K&R.
  19. The main() of each process that uses these globals must include the
  20. CONSTRUCTGLOBALS; statement. This will malloc enough memory for the
  21. structure and initialize any variables that require it. This must
  22. also be done by any API function that jumps into the middle of the
  23. code.
  24. The DESTROYGLOBALS(); statement should be inserted before EVERY "EXIT(n)".
  25. Naturally, it also needs to be put before any API returns as well.
  26. In fact, it's much more important in API functions since the process
  27. will NOT end, and therefore the memory WON'T automatically be freed
  28. by the operating system.
  29. USING VARIABLES FROM THE STRUCTURE
  30. ----------------------------------
  31. All global variables must now be prefixed with `G.' which is either a
  32. global struct (in which case it should be the only global variable) or
  33. a macro for the value of a local pointer variable that is passed from
  34. function to function. Yes, this is a pain. But it's the only way to
  35. allow full reentrancy.
  36. ADDING VARIABLES TO THE STRUCTURE
  37. ---------------------------------
  38. If you make the inclusion of any variables conditional, be sure to only
  39. check macros that are GUARANTEED to be included in every module.
  40. For instance, newzip and pwdarg are needed only if CRYPT is TRUE,
  41. but this is defined after unzip.h has been read. If you are not careful,
  42. some modules will expect your variable to be part of this struct while
  43. others won't. This will cause BIG problems. (Inexplicable crashes at
  44. strange times, car fires, etc.) When in doubt, always include it!
  45. Note also that UnZipSFX needs a few variables that UnZip doesn't. However,
  46. it also includes some object files from UnZip. If we were to conditionally
  47. include the extra variables that UnZipSFX needs, the object files from
  48. UnZip would not mesh with the UnZipSFX object files. Result: we just
  49. include the UnZipSFX variables every time. (It's only an extra 4 bytes
  50. so who cares!)
  51. ADDING FUNCTIONS
  52. ----------------
  53. To support this new global struct, all functions must now conditionally
  54. pass the globals pointer (pG) to each other. This is supported by 5 macros:
  55. __GPRO, __GPRO__, __G, __G__ and __GDEF. A function that needs no other
  56. parameters would look like this:
  57. int extract_or_test_files(__G)
  58. __GDEF
  59. {
  60. ... stuff ...
  61. }
  62. A function with other parameters would look like:
  63. int memextract(__G__ tgt, tgtsize, src, srcsize)
  64. __GDEF
  65. uch *tgt, *src;
  66. ulg tgtsize, srcsize;
  67. {
  68. ... stuff ...
  69. }
  70. In the Function Prototypes section of unzpriv.h, you should use __GPRO and
  71. __GPRO__ instead:
  72. int uz_opts OF((__GPRO__ int *pargc, char ***pargv));
  73. int process_zipfiles OF((__GPRO));
  74. Note that there is NO comma after __G__ or __GPRO__ and no semi-colon after
  75. __GDEF. I wish there was another way but I don't think there is.
  76. TESTING THE CODE
  77. -----------------
  78. Whether your platform requires reentrancy or not, you should always try
  79. building with REENTRANT defined if any functions have been added. It is
  80. pretty easy to forget a __G__ or a __GDEF and this mistake will only show
  81. up if REENTRANT is defined. All platforms should run with REENTRANT
  82. defined. Platforms that can't take advantage of it will just be paying
  83. a performance penalty needlessly.
  84. SIGNAL MADNESS
  85. --------------
  86. This whole pointer passing scheme falls apart when it comes to SIGNALs.
  87. I handle this situation 2 ways right now. If you define USETHREADID,
  88. UnZip will include a 64-entry table. Each entry can hold a global
  89. pointer and thread ID for one thread. This should allow up to 64
  90. threads to access UnZip simultaneously. Calling DESTROYGLOBALS()
  91. will free the global struct and zero the table entry. If somebody
  92. forgets to call DESTROYGLOBALS(), this table will eventually fill up
  93. and UnZip will exit with an error message. A good way to test your
  94. code to make sure you didn't forget a DESTROYGLOBALS() is to change
  95. THREADID_ENTRIES to 3 or 4 in globals.c, making the table real small.
  96. Then make a small test program that calls your API a dozen times.
  97. Those platforms that don't have threads still need to be able to compile
  98. with REENTRANT defined to test and see if new code is correctly written
  99. to work either way. For these platforms, I simply keep a global pointer
  100. called GG that points to the Globals structure. Good enough for testing.
  101. I believe that NT has thread level storage. This could probably be used
  102. to store a global pointer for the sake of the signal handler more cleanly
  103. than my table approach.
  104. ---------------------------------------------------------------------------*/
  105. #ifndef __globals_h
  106. #define __globals_h
  107. #ifdef USE_ZLIB
  108. # include "zlib.h"
  109. # ifdef zlib_version /* This name is used internally in unzip */
  110. # undef zlib_version /* and must not be defined as a macro. */
  111. # endif
  112. #endif
  113. #ifdef USE_BZIP2
  114. # include "bzlib.h"
  115. #endif
  116. /*************/
  117. /* Globals */
  118. /*************/
  119. typedef struct Globals {
  120. #ifdef DLL
  121. zvoid *callerglobs; /* pointer to structure of pass-through global vars */
  122. #endif
  123. /* command options of general use */
  124. UzpOpts UzO; /* command options of general use */
  125. #ifndef FUNZIP
  126. /* command options specific to the high level command line interface */
  127. #ifdef MORE
  128. int M_flag; /* -M: built-in "more" function */
  129. #endif
  130. /* internal flags and general globals */
  131. #ifdef MORE
  132. int height; /* check for SIGWINCH, etc., eventually... */
  133. int lines; /* count of lines displayed on current screen */
  134. # if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
  135. int width;
  136. int chars; /* count of screen characters in current line */
  137. # endif
  138. #endif /* MORE */
  139. #if (defined(IZ_CHECK_TZ) && defined(USE_EF_UT_TIME))
  140. int tz_is_valid; /* indicates that timezone info can be used */
  141. #endif
  142. int noargs; /* did true command line have *any* arguments? */
  143. unsigned filespecs; /* number of real file specifications to be matched */
  144. unsigned xfilespecs; /* number of excluded filespecs to be matched */
  145. int process_all_files;
  146. int overwrite_mode; /* 0 - query, 1 - always, 2 - never */
  147. int create_dirs; /* used by main(), mapname(), checkdir() */
  148. int extract_flag;
  149. int newzip; /* reset in extract.c; used in crypt.c */
  150. zoff_t real_ecrec_offset;
  151. zoff_t expect_ecrec_offset;
  152. zoff_t csize; /* used by decompr. (NEXTBYTE): must be signed */
  153. zoff_t used_csize; /* used by extract_or_test_member(), explode() */
  154. #ifdef DLL
  155. int fValidate; /* true if only validating an archive */
  156. int filenotfound;
  157. int redirect_data; /* redirect data to memory buffer */
  158. int redirect_text; /* redirect text output to buffer */
  159. # ifndef NO_SLIDE_REDIR
  160. int redirect_slide; /* redirect decompression area to mem buffer */
  161. # if (defined(USE_DEFLATE64) && defined(INT_16BIT))
  162. ulg _wsize; /* size of sliding window exceeds "unsigned" range */
  163. # else
  164. unsigned _wsize; /* sliding window size can be hold in unsigned */
  165. # endif
  166. # endif
  167. ulg redirect_size; /* size of redirected output buffer */
  168. uch *redirect_buffer; /* pointer to head of allocated buffer */
  169. uch *redirect_pointer; /* pointer past end of written data */
  170. # ifndef NO_SLIDE_REDIR
  171. uch *redirect_sldptr; /* head of decompression slide buffer */
  172. # endif
  173. # ifdef OS2DLL
  174. cbList(processExternally); /* call-back list */
  175. # endif
  176. #endif /* DLL */
  177. char **pfnames;
  178. char **pxnames;
  179. char sig[4];
  180. char answerbuf[10];
  181. min_info info[DIR_BLKSIZ];
  182. min_info *pInfo;
  183. #endif /* !FUNZIP */
  184. union work area; /* see unzpriv.h for definition of work */
  185. #if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
  186. ZCONST ulg near *crc_32_tab;
  187. #else
  188. ZCONST ulg Far *crc_32_tab;
  189. #endif
  190. ulg crc32val; /* CRC shift reg. (was static in funzip) */
  191. #ifdef FUNZIP
  192. FILE *in; /* file descriptor of compressed stream */
  193. #endif
  194. uch *inbuf; /* input buffer (any size is OK) */
  195. uch *inptr; /* pointer into input buffer */
  196. int incnt;
  197. #ifndef FUNZIP
  198. ulg bitbuf;
  199. int bits_left; /* unreduce and unshrink only */
  200. int zipeof;
  201. char *argv0; /* used for NT and EXE_EXTENSION */
  202. char *wildzipfn;
  203. char *zipfn; /* GRR: WINDLL: must nuke any malloc'd zipfn... */
  204. #ifdef USE_STRM_INPUT
  205. FILE *zipfd; /* zipfile file descriptor */
  206. #else
  207. int zipfd; /* zipfile file handle */
  208. #endif
  209. zoff_t ziplen;
  210. zoff_t cur_zipfile_bufstart; /* extract_or_test, readbuf, ReadByte */
  211. zoff_t extra_bytes; /* used in unzip.c, misc.c */
  212. uch *extra_field; /* Unix, VMS, Mac, OS/2, Acorn, ... */
  213. uch *hold;
  214. local_file_hdr lrec; /* used in unzip.c, extract.c */
  215. cdir_file_hdr crec; /* used in unzip.c, extract.c, misc.c */
  216. ecdir_rec ecrec; /* used in unzip.c, extract.c */
  217. z_stat statbuf; /* used by main, mapname, check_for_newer */
  218. int mem_mode;
  219. uch *outbufptr; /* extract.c static */
  220. ulg outsize; /* extract.c static */
  221. int reported_backslash; /* extract.c static */
  222. int disk_full;
  223. int newfile;
  224. int didCRlast; /* fileio static */
  225. ulg numlines; /* fileio static: number of lines printed */
  226. int sol; /* fileio static: at start of line */
  227. int no_ecrec; /* process static */
  228. #ifdef SYMLINKS
  229. int symlnk;
  230. slinkentry *slink_head; /* pointer to head of symlinks list */
  231. slinkentry *slink_last; /* pointer to last entry in symlinks list */
  232. #endif
  233. #ifdef NOVELL_BUG_FAILSAFE
  234. int dne; /* true if stat() says file doesn't exist */
  235. #endif
  236. FILE *outfile;
  237. uch *outbuf;
  238. uch *realbuf;
  239. #ifndef VMS /* if SMALL_MEM, outbuf2 is initialized in */
  240. uch *outbuf2; /* process_zipfiles() (never changes); */
  241. #endif /* else malloc'd ONLY if unshrink and -a */
  242. #endif /* !FUNZIP */
  243. uch *outptr;
  244. ulg outcnt; /* number of chars stored in outbuf */
  245. #ifndef FUNZIP
  246. char filename[FILNAMSIZ]; /* also used by NT for temporary SFX path */
  247. #ifdef UNICODE_SUPPORT
  248. char *filename_full; /* the full path so Unicode checks work */
  249. extent fnfull_bufsize; /* size of allocated filename buffer */
  250. int unicode_escape_all;
  251. int unicode_mismatch;
  252. #ifdef UTF8_MAYBE_NATIVE
  253. int native_is_utf8; /* bool, TRUE => native charset == UTF-8 */
  254. #endif
  255. int unipath_version; /* version of Unicode field */
  256. ulg unipath_checksum; /* Unicode field checksum */
  257. char *unipath_filename; /* UTF-8 path */
  258. #endif /* UNICODE_SUPPORT */
  259. #ifdef CMS_MVS
  260. char *tempfn; /* temp file used; erase on close */
  261. #endif
  262. char *key; /* crypt static: decryption password or NULL */
  263. int nopwd; /* crypt static */
  264. #endif /* !FUNZIP */
  265. z_uint4 keys[3]; /* crypt static: keys defining pseudo-random sequence */
  266. #if (!defined(DOS_FLX_H68_NLM_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
  267. #if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
  268. int echofd; /* ttyio static: file descriptor whose echo is off */
  269. #endif /* !(MACOS || ATARI || VMS) */
  270. #endif /* !(DOS_FLX_H68_NLM_OS2_W32 || AMIGA || RISCOS) */
  271. unsigned hufts; /* track memory usage */
  272. #ifdef USE_ZLIB
  273. int inflInit; /* inflate static: zlib inflate() initialized */
  274. z_stream dstrm; /* inflate global: decompression stream */
  275. #else
  276. struct huft *fixed_tl; /* inflate static */
  277. struct huft *fixed_td; /* inflate static */
  278. unsigned fixed_bl, fixed_bd; /* inflate static */
  279. #ifdef USE_DEFLATE64
  280. struct huft *fixed_tl64; /* inflate static */
  281. struct huft *fixed_td64; /* inflate static */
  282. unsigned fixed_bl64, fixed_bd64; /* inflate static */
  283. struct huft *fixed_tl32; /* inflate static */
  284. struct huft *fixed_td32; /* inflate static */
  285. unsigned fixed_bl32, fixed_bd32; /* inflate static */
  286. ZCONST ush *cplens; /* inflate static */
  287. ZCONST uch *cplext; /* inflate static */
  288. ZCONST uch *cpdext; /* inflate static */
  289. #endif
  290. unsigned wp; /* inflate static: current position in slide */
  291. ulg bb; /* inflate static: bit buffer */
  292. unsigned bk; /* inflate static: bits count in bit buffer */
  293. #endif /* ?USE_ZLIB */
  294. #ifndef FUNZIP
  295. /* cylindric buffer space for formatting zoff_t values (fileio static) */
  296. char fzofft_buf[FZOFFT_NUM][FZOFFT_LEN];
  297. int fzofft_index;
  298. #ifdef SMALL_MEM
  299. char rgchBigBuffer[512];
  300. char rgchSmallBuffer[96];
  301. char rgchSmallBuffer2[160]; /* boosted to 160 for local3[] in unzip.c */
  302. #endif
  303. MsgFn *message;
  304. InputFn *input;
  305. PauseFn *mpause;
  306. PasswdFn *decr_passwd;
  307. StatCBFn *statreportcb;
  308. #ifdef WINDLL
  309. LPUSERFUNCTIONS lpUserFunctions;
  310. #endif
  311. int incnt_leftover; /* so improved NEXTBYTE does not waste input */
  312. uch *inptr_leftover;
  313. #ifdef VMS_TEXT_CONV
  314. unsigned VMS_line_length; /* so native VMS variable-length text files */
  315. int VMS_line_state; /* are readable on other platforms */
  316. int VMS_line_pad;
  317. #endif
  318. #if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
  319. char autorun_command[FILNAMSIZ];
  320. #endif
  321. #endif /* !FUNZIP */
  322. #ifdef SYSTEM_SPECIFIC_GLOBALS
  323. SYSTEM_SPECIFIC_GLOBALS
  324. #endif
  325. } Uz_Globs; /* end of struct Globals */
  326. /***************************************************************************/
  327. #define CRC_32_TAB G.crc_32_tab
  328. Uz_Globs *globalsCtor OF((void));
  329. /* pseudo constant sigs; they are initialized at runtime so unzip executable
  330. * won't look like a zipfile
  331. */
  332. extern char local_hdr_sig[4];
  333. extern char central_hdr_sig[4];
  334. extern char end_central_sig[4];
  335. extern char end_central32_sig[4];
  336. extern char end_central64_sig[4];
  337. extern char end_centloc64_sig[4];
  338. /* extern char extd_local_sig[4]; NOT USED YET */
  339. #ifdef REENTRANT
  340. # define G (*(Uz_Globs *)pG)
  341. # define __G pG
  342. # define __G__ pG,
  343. # define __GPRO Uz_Globs *pG
  344. # define __GPRO__ Uz_Globs *pG,
  345. # define __GDEF Uz_Globs *pG;
  346. # ifdef USETHREADID
  347. extern int lastScan;
  348. void deregisterGlobalPointer OF((__GPRO));
  349. Uz_Globs *getGlobalPointer OF((void));
  350. # define GETGLOBALS() Uz_Globs *pG = getGlobalPointer()
  351. # define DESTROYGLOBALS() do {free_G_buffers(pG); \
  352. deregisterGlobalPointer(pG);} while (0)
  353. # else
  354. extern Uz_Globs *GG;
  355. # define GETGLOBALS() Uz_Globs *pG = GG
  356. # define DESTROYGLOBALS() do {free_G_buffers(pG); free(pG);} while (0)
  357. # endif /* ?USETHREADID */
  358. # define CONSTRUCTGLOBALS() Uz_Globs *pG = globalsCtor()
  359. #else /* !REENTRANT */
  360. extern Uz_Globs G;
  361. # define __G
  362. # define __G__
  363. # define __GPRO void
  364. # define __GPRO__
  365. # define __GDEF
  366. # define GETGLOBALS()
  367. # define CONSTRUCTGLOBALS() globalsCtor()
  368. # define DESTROYGLOBALS()
  369. #endif /* ?REENTRANT */
  370. #define uO G.UzO
  371. #endif /* __globals_h */