api.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. api.c
  10. This module supplies an UnZip engine for use directly from C/C++
  11. programs. The functions are:
  12. ZCONST UzpVer *UzpVersion(void);
  13. unsigned UzpVersion2(UzpVer2 *version)
  14. int UzpMain(int argc, char *argv[]);
  15. int UzpAltMain(int argc, char *argv[], UzpInit *init);
  16. int UzpValidate(char *archive, int AllCodes);
  17. void UzpFreeMemBuffer(UzpBuffer *retstr);
  18. int UzpUnzipToMemory(char *zip, char *file, UzpOpts *optflgs,
  19. UzpCB *UsrFuncts, UzpBuffer *retstr);
  20. non-WINDLL only (a special WINDLL variant is defined in windll/windll.c):
  21. int UzpGrep(char *archive, char *file, char *pattern, int cmd, int SkipBin,
  22. UzpCB *UsrFuncts);
  23. OS/2 only (for now):
  24. int UzpFileTree(char *name, cbList(callBack), char *cpInclude[],
  25. char *cpExclude[]);
  26. You must define `DLL' in order to include the API extensions.
  27. ---------------------------------------------------------------------------*/
  28. #ifdef OS2
  29. # define INCL_DOSMEMMGR
  30. # include <os2.h>
  31. #endif
  32. #define UNZIP_INTERNAL
  33. #include "unzip.h"
  34. #ifdef WINDLL
  35. # ifdef POCKET_UNZIP
  36. # include "wince/intrface.h"
  37. # else
  38. # include "windll/windll.h"
  39. # endif
  40. #endif
  41. #include "unzvers.h"
  42. #include <setjmp.h>
  43. #ifdef DLL /* This source file supplies DLL-only interface code. */
  44. #ifndef POCKET_UNZIP /* WinCE pUnZip defines this elsewhere. */
  45. jmp_buf dll_error_return;
  46. #endif
  47. /*---------------------------------------------------------------------------
  48. Documented API entry points
  49. ---------------------------------------------------------------------------*/
  50. ZCONST UzpVer * UZ_EXP UzpVersion() /* returns pointer to const struct */
  51. {
  52. static ZCONST UzpVer version = { /* doesn't change between calls */
  53. /* structure size */
  54. UZPVER_LEN,
  55. /* version flags */
  56. #ifdef BETA
  57. # ifdef ZLIB_VERSION
  58. 3,
  59. # else
  60. 1,
  61. # endif
  62. #else
  63. # ifdef ZLIB_VERSION
  64. 2,
  65. # else
  66. 0,
  67. # endif
  68. #endif
  69. /* betalevel and date strings */
  70. UZ_BETALEVEL, UZ_VERSION_DATE,
  71. /* zlib_version string */
  72. #ifdef ZLIB_VERSION
  73. ZLIB_VERSION,
  74. #else
  75. NULL,
  76. #endif
  77. /*== someday each of these may have a separate patchlevel: ==*/
  78. /* unzip version */
  79. {UZ_MAJORVER, UZ_MINORVER, UZ_PATCHLEVEL, 0},
  80. /* zipinfo version */
  81. {ZI_MAJORVER, ZI_MINORVER, UZ_PATCHLEVEL, 0},
  82. /* os2dll version (retained for backward compatibility) */
  83. {UZ_MAJORVER, UZ_MINORVER, UZ_PATCHLEVEL, 0},
  84. /* windll version (retained for backward compatibility)*/
  85. {UZ_MAJORVER, UZ_MINORVER, UZ_PATCHLEVEL, 0},
  86. #ifdef OS2DLL
  87. /* os2dll API minimum compatible version*/
  88. {UZ_OS2API_COMP_MAJOR, UZ_OS2API_COMP_MINOR, UZ_OS2API_COMP_REVIS, 0}
  89. #else /* !OS2DLL */
  90. #ifdef WINDLL
  91. /* windll API minimum compatible version*/
  92. {UZ_WINAPI_COMP_MAJOR, UZ_WINAPI_COMP_MINOR, UZ_WINAPI_COMP_REVIS, 0}
  93. #else /* !WINDLL */
  94. /* generic DLL API minimum compatible version*/
  95. {UZ_GENAPI_COMP_MAJOR, UZ_GENAPI_COMP_MINOR, UZ_GENAPI_COMP_REVIS, 0}
  96. #endif /* ?WINDLL */
  97. #endif /* ?OS2DLL */
  98. };
  99. return &version;
  100. }
  101. unsigned UZ_EXP UzpVersion2(UzpVer2 *version)
  102. {
  103. if (version->structlen != sizeof(UzpVer2))
  104. return sizeof(UzpVer2);
  105. #ifdef BETA
  106. version->flag = 1;
  107. #else
  108. version->flag = 0;
  109. #endif
  110. strcpy(version->betalevel, UZ_BETALEVEL);
  111. strcpy(version->date, UZ_VERSION_DATE);
  112. #ifdef ZLIB_VERSION
  113. /* Although ZLIB_VERSION is a compile-time constant, we implement an
  114. "overrun-safe" copy because its actual value is not under our control.
  115. */
  116. strncpy(version->zlib_version, ZLIB_VERSION,
  117. sizeof(version->zlib_version) - 1);
  118. version->zlib_version[sizeof(version->zlib_version) - 1] = '\0';
  119. version->flag |= 2;
  120. #else
  121. version->zlib_version[0] = '\0';
  122. #endif
  123. /* someday each of these may have a separate patchlevel: */
  124. version->unzip.major = UZ_MAJORVER;
  125. version->unzip.minor = UZ_MINORVER;
  126. version->unzip.patchlevel = UZ_PATCHLEVEL;
  127. version->zipinfo.major = ZI_MAJORVER;
  128. version->zipinfo.minor = ZI_MINORVER;
  129. version->zipinfo.patchlevel = UZ_PATCHLEVEL;
  130. /* these are retained for backward compatibility only: */
  131. version->os2dll.major = UZ_MAJORVER;
  132. version->os2dll.minor = UZ_MINORVER;
  133. version->os2dll.patchlevel = UZ_PATCHLEVEL;
  134. version->windll.major = UZ_MAJORVER;
  135. version->windll.minor = UZ_MINORVER;
  136. version->windll.patchlevel = UZ_PATCHLEVEL;
  137. #ifdef OS2DLL
  138. /* os2dll API minimum compatible version*/
  139. version->dllapimin.major = UZ_OS2API_COMP_MAJOR;
  140. version->dllapimin.minor = UZ_OS2API_COMP_MINOR;
  141. version->dllapimin.patchlevel = UZ_OS2API_COMP_REVIS;
  142. #else /* !OS2DLL */
  143. #ifdef WINDLL
  144. /* windll API minimum compatible version*/
  145. version->dllapimin.major = UZ_WINAPI_COMP_MAJOR;
  146. version->dllapimin.minor = UZ_WINAPI_COMP_MINOR;
  147. version->dllapimin.patchlevel = UZ_WINAPI_COMP_REVIS;
  148. #else /* !WINDLL */
  149. /* generic DLL API minimum compatible version*/
  150. version->dllapimin.major = UZ_GENAPI_COMP_MAJOR;
  151. version->dllapimin.minor = UZ_GENAPI_COMP_MINOR;
  152. version->dllapimin.patchlevel = UZ_GENAPI_COMP_REVIS;
  153. #endif /* ?WINDLL */
  154. #endif /* ?OS2DLL */
  155. return 0;
  156. }
  157. #ifndef SFX
  158. #ifndef WINDLL
  159. int UZ_EXP UzpAltMain(int argc, char *argv[], UzpInit *init)
  160. {
  161. int r, (*dummyfn)();
  162. CONSTRUCTGLOBALS();
  163. if (init->structlen >= (sizeof(ulg) + sizeof(dummyfn)) && init->msgfn)
  164. G.message = init->msgfn;
  165. if (init->structlen >= (sizeof(ulg) + 2*sizeof(dummyfn)) && init->inputfn)
  166. G.input = init->inputfn;
  167. if (init->structlen >= (sizeof(ulg) + 3*sizeof(dummyfn)) && init->pausefn)
  168. G.mpause = init->pausefn;
  169. if (init->structlen >= (sizeof(ulg) + 4*sizeof(dummyfn)) && init->userfn)
  170. (*init->userfn)(); /* allow void* arg? */
  171. r = unzip(__G__ argc, argv);
  172. DESTROYGLOBALS();
  173. RETURN(r);
  174. }
  175. #endif /* !WINDLL */
  176. #ifndef __16BIT__
  177. void UZ_EXP UzpFreeMemBuffer(UzpBuffer *retstr)
  178. {
  179. if (retstr != NULL && retstr->strptr != NULL) {
  180. free(retstr->strptr);
  181. retstr->strptr = NULL;
  182. retstr->strlength = 0;
  183. }
  184. }
  185. #ifndef WINDLL
  186. static int UzpDLL_Init OF((zvoid *pG, UzpCB *UsrFuncts));
  187. static int UzpDLL_Init(pG, UsrFuncts)
  188. zvoid *pG;
  189. UzpCB *UsrFuncts;
  190. {
  191. int (*dummyfn)();
  192. if (UsrFuncts->structlen >= (sizeof(ulg) + sizeof(dummyfn)) &&
  193. UsrFuncts->msgfn)
  194. ((Uz_Globs *)pG)->message = UsrFuncts->msgfn;
  195. else
  196. return FALSE;
  197. if (UsrFuncts->structlen >= (sizeof(ulg) + 2*sizeof(dummyfn)) &&
  198. UsrFuncts->inputfn)
  199. ((Uz_Globs *)pG)->input = UsrFuncts->inputfn;
  200. if (UsrFuncts->structlen >= (sizeof(ulg) + 3*sizeof(dummyfn)) &&
  201. UsrFuncts->pausefn)
  202. ((Uz_Globs *)pG)->mpause = UsrFuncts->pausefn;
  203. if (UsrFuncts->structlen >= (sizeof(ulg) + 4*sizeof(dummyfn)) &&
  204. UsrFuncts->passwdfn)
  205. ((Uz_Globs *)pG)->decr_passwd = UsrFuncts->passwdfn;
  206. if (UsrFuncts->structlen >= (sizeof(ulg) + 5*sizeof(dummyfn)) &&
  207. UsrFuncts->statrepfn)
  208. ((Uz_Globs *)pG)->statreportcb = UsrFuncts->statrepfn;
  209. return TRUE;
  210. }
  211. int UZ_EXP UzpUnzipToMemory(char *zip, char *file, UzpOpts *optflgs,
  212. UzpCB *UsrFuncts, UzpBuffer *retstr)
  213. {
  214. int r;
  215. #if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
  216. char *intern_zip, *intern_file;
  217. #endif
  218. CONSTRUCTGLOBALS();
  219. #if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
  220. intern_zip = (char *)malloc(strlen(zip)+1);
  221. if (intern_zip == NULL) {
  222. DESTROYGLOBALS();
  223. return PK_MEM;
  224. }
  225. intern_file = (char *)malloc(strlen(file)+1);
  226. if (intern_file == NULL) {
  227. DESTROYGLOBALS();
  228. free(intern_zip);
  229. return PK_MEM;
  230. }
  231. ISO_TO_INTERN(zip, intern_zip);
  232. ISO_TO_INTERN(file, intern_file);
  233. # define zip intern_zip
  234. # define file intern_file
  235. #endif
  236. /* Copy those options that are meaningful for UzpUnzipToMemory, instead of
  237. * a simple "memcpy(G.UzO, optflgs, sizeof(UzpOpts));"
  238. */
  239. uO.pwdarg = optflgs->pwdarg;
  240. uO.aflag = optflgs->aflag;
  241. uO.C_flag = optflgs->C_flag;
  242. uO.qflag = optflgs->qflag; /* currently, overridden in unzipToMemory */
  243. if (!UzpDLL_Init((zvoid *)&G, UsrFuncts)) {
  244. DESTROYGLOBALS();
  245. return PK_BADERR;
  246. }
  247. G.redirect_data = 1;
  248. r = (unzipToMemory(__G__ zip, file, retstr) <= PK_WARN);
  249. DESTROYGLOBALS();
  250. #if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
  251. # undef file
  252. # undef zip
  253. free(intern_file);
  254. free(intern_zip);
  255. #endif
  256. if (!r && retstr->strlength) {
  257. free(retstr->strptr);
  258. retstr->strptr = NULL;
  259. }
  260. return r;
  261. }
  262. #endif /* !WINDLL */
  263. #endif /* !__16BIT__ */
  264. #ifdef OS2DLL
  265. int UZ_EXP UzpFileTree(char *name, cbList(callBack), char *cpInclude[],
  266. char *cpExclude[])
  267. {
  268. int r;
  269. CONSTRUCTGLOBALS();
  270. uO.qflag = 2;
  271. uO.vflag = 1;
  272. uO.C_flag = 1;
  273. G.wildzipfn = name;
  274. G.process_all_files = TRUE;
  275. if (cpInclude) {
  276. char **ptr = cpInclude;
  277. while (*ptr != NULL) ptr++;
  278. G.filespecs = ptr - cpInclude;
  279. G.pfnames = cpInclude, G.process_all_files = FALSE;
  280. }
  281. if (cpExclude) {
  282. char **ptr = cpExclude;
  283. while (*ptr != NULL) ptr++;
  284. G.xfilespecs = ptr - cpExclude;
  285. G.pxnames = cpExclude, G.process_all_files = FALSE;
  286. }
  287. G.processExternally = callBack;
  288. r = process_zipfiles(__G)==0;
  289. DESTROYGLOBALS();
  290. return r;
  291. }
  292. #endif /* OS2DLL */
  293. #endif /* !SFX */
  294. /*---------------------------------------------------------------------------
  295. Helper functions
  296. ---------------------------------------------------------------------------*/
  297. void setFileNotFound(__G)
  298. __GDEF
  299. {
  300. G.filenotfound++;
  301. }
  302. #ifndef SFX
  303. int unzipToMemory(__GPRO__ char *zip, char *file, UzpBuffer *retstr)
  304. {
  305. int r;
  306. char *incname[2];
  307. if ((zip == NULL) || (strlen(zip) > ((WSIZE>>2) - 160)))
  308. return PK_PARAM;
  309. if ((file == NULL) || (strlen(file) > ((WSIZE>>2) - 160)))
  310. return PK_PARAM;
  311. G.process_all_files = FALSE;
  312. G.extract_flag = TRUE;
  313. uO.qflag = 2;
  314. G.wildzipfn = zip;
  315. G.pfnames = incname;
  316. incname[0] = file;
  317. incname[1] = NULL;
  318. G.filespecs = 1;
  319. r = process_zipfiles(__G);
  320. if (retstr) {
  321. retstr->strptr = (char *)G.redirect_buffer;
  322. retstr->strlength = G.redirect_size;
  323. }
  324. return r; /* returns `PK_???' error values */
  325. }
  326. #endif /* !SFX */
  327. /*
  328. With the advent of 64 bit support, for now I am assuming that
  329. if the size of the file is greater than an unsigned long, there
  330. will simply not be enough memory to handle it, and am returning
  331. FALSE.
  332. */
  333. int redirect_outfile(__G)
  334. __GDEF
  335. {
  336. #ifdef ZIP64_SUPPORT
  337. __int64 check_conversion;
  338. #endif
  339. if (G.redirect_size != 0 || G.redirect_buffer != NULL)
  340. return FALSE;
  341. #ifndef NO_SLIDE_REDIR
  342. G.redirect_slide = !G.pInfo->textmode;
  343. #endif
  344. #if (lenEOL != 1)
  345. if (G.pInfo->textmode) {
  346. G.redirect_size = (ulg)(G.lrec.ucsize * lenEOL);
  347. if (G.redirect_size < G.lrec.ucsize)
  348. G.redirect_size = (ulg)((G.lrec.ucsize > (ulg)-2L) ?
  349. G.lrec.ucsize : -2L);
  350. #ifdef ZIP64_SUPPORT
  351. check_conversion = G.lrec.ucsize * lenEOL;
  352. #endif
  353. } else
  354. #endif
  355. {
  356. G.redirect_size = (ulg)G.lrec.ucsize;
  357. #ifdef ZIP64_SUPPORT
  358. check_conversion = (__int64)G.lrec.ucsize;
  359. #endif
  360. }
  361. #ifdef ZIP64_SUPPORT
  362. if ((__int64)G.redirect_size != check_conversion)
  363. return FALSE;
  364. #endif
  365. #ifdef __16BIT__
  366. if ((ulg)((extent)G.redirect_size) != G.redirect_size)
  367. return FALSE;
  368. #endif
  369. #ifdef OS2
  370. DosAllocMem((void **)&G.redirect_buffer, G.redirect_size+1,
  371. PAG_READ|PAG_WRITE|PAG_COMMIT);
  372. G.redirect_pointer = G.redirect_buffer;
  373. #else
  374. G.redirect_pointer =
  375. G.redirect_buffer = malloc((extent)(G.redirect_size+1));
  376. #endif
  377. if (!G.redirect_buffer)
  378. return FALSE;
  379. G.redirect_pointer[G.redirect_size] = '\0';
  380. return TRUE;
  381. }
  382. int writeToMemory(__GPRO__ ZCONST uch *rawbuf, extent size)
  383. {
  384. int errflg = FALSE;
  385. if ((uch *)rawbuf != G.redirect_pointer) {
  386. extent redir_avail = (G.redirect_buffer + G.redirect_size) -
  387. G.redirect_pointer;
  388. /* Check for output buffer overflow */
  389. if (size > redir_avail) {
  390. /* limit transfer data to available space, set error return flag */
  391. size = redir_avail;
  392. errflg = TRUE;
  393. }
  394. memcpy(G.redirect_pointer, rawbuf, size);
  395. }
  396. G.redirect_pointer += size;
  397. return errflg;
  398. }
  399. int close_redirect(__G)
  400. __GDEF
  401. {
  402. if (G.pInfo->textmode) {
  403. *G.redirect_pointer = '\0';
  404. G.redirect_size = (ulg)(G.redirect_pointer - G.redirect_buffer);
  405. if ((G.redirect_buffer =
  406. realloc(G.redirect_buffer, G.redirect_size + 1)) == NULL) {
  407. G.redirect_size = 0;
  408. return EOF;
  409. }
  410. }
  411. return 0;
  412. }
  413. #ifndef SFX
  414. #ifndef __16BIT__
  415. #ifndef WINDLL
  416. /* Purpose: Determine if file in archive contains the string szSearch
  417. Parameters: archive = archive name
  418. file = file contained in the archive. This cannot be
  419. a wildcard to be meaningful
  420. pattern = string to search for
  421. cmd = 0 - case-insensitive search
  422. 1 - case-sensitve search
  423. 2 - case-insensitive, whole words only
  424. 3 - case-sensitive, whole words only
  425. SkipBin = if true, skip any files that have control
  426. characters other than CR, LF, or tab in the first
  427. 100 characters.
  428. Returns: TRUE if a match is found
  429. FALSE if no match is found
  430. -1 on error
  431. Comments: This does not pretend to be as useful as the standard
  432. Unix grep, which returns the strings associated with a
  433. particular pattern, nor does it search past the first
  434. matching occurrence of the pattern.
  435. */
  436. int UZ_EXP UzpGrep(char *archive, char *file, char *pattern, int cmd,
  437. int SkipBin, UzpCB *UsrFuncts)
  438. {
  439. int retcode = FALSE, compare;
  440. ulg i, j, patternLen, buflen;
  441. char * sz, *p;
  442. UzpOpts flgopts;
  443. UzpBuffer retstr;
  444. memzero(&flgopts, sizeof(UzpOpts)); /* no special options */
  445. if (!UzpUnzipToMemory(archive, file, &flgopts, UsrFuncts, &retstr)) {
  446. return -1; /* not enough memory, file not found, or other error */
  447. }
  448. if (SkipBin) {
  449. if (retstr.strlength < 100)
  450. buflen = retstr.strlength;
  451. else
  452. buflen = 100;
  453. for (i = 0; i < buflen; i++) {
  454. if (iscntrl(retstr.strptr[i])) {
  455. if ((retstr.strptr[i] != 0x0A) &&
  456. (retstr.strptr[i] != 0x0D) &&
  457. (retstr.strptr[i] != 0x09))
  458. {
  459. /* OK, we now think we have a binary file of some sort */
  460. free(retstr.strptr);
  461. return FALSE;
  462. }
  463. }
  464. }
  465. }
  466. patternLen = strlen(pattern);
  467. if (retstr.strlength < patternLen) {
  468. free(retstr.strptr);
  469. return FALSE;
  470. }
  471. sz = malloc(patternLen + 3); /* add two in case doing whole words only */
  472. if (cmd > 1) {
  473. strcpy(sz, " ");
  474. strcat(sz, pattern);
  475. strcat(sz, " ");
  476. } else
  477. strcpy(sz, pattern);
  478. if ((cmd == 0) || (cmd == 2)) {
  479. for (i = 0; i < strlen(sz); i++)
  480. sz[i] = toupper(sz[i]);
  481. for (i = 0; i < retstr.strlength; i++)
  482. retstr.strptr[i] = toupper(retstr.strptr[i]);
  483. }
  484. for (i = 0; i < (retstr.strlength - patternLen); i++) {
  485. p = &retstr.strptr[i];
  486. compare = TRUE;
  487. for (j = 0; j < patternLen; j++) {
  488. /* We cannot do strncmp here, as we may be dealing with a
  489. * "binary" file, such as a word processing file, or perhaps
  490. * even a true executable of some sort. */
  491. if (p[j] != sz[j]) {
  492. compare = FALSE;
  493. break;
  494. }
  495. }
  496. if (compare == TRUE) {
  497. retcode = TRUE;
  498. break;
  499. }
  500. }
  501. free(sz);
  502. free(retstr.strptr);
  503. return retcode;
  504. }
  505. #endif /* !WINDLL */
  506. #endif /* !__16BIT__ */
  507. int UZ_EXP UzpValidate(char *archive, int AllCodes)
  508. {
  509. int retcode;
  510. CONSTRUCTGLOBALS();
  511. uO.jflag = 1;
  512. uO.tflag = 1;
  513. uO.overwrite_none = 0;
  514. G.extract_flag = (!uO.zipinfo_mode &&
  515. !uO.cflag && !uO.tflag && !uO.vflag && !uO.zflag
  516. #ifdef TIMESTAMP
  517. && !uO.T_flag
  518. #endif
  519. );
  520. uO.qflag = 2; /* turn off all messages */
  521. G.fValidate = TRUE;
  522. G.pfnames = (char **)&fnames[0]; /* assign default filename vector */
  523. if (archive == NULL) { /* something is screwed up: no filename */
  524. DESTROYGLOBALS();
  525. retcode = PK_NOZIP;
  526. goto exit_retcode;
  527. }
  528. if (strlen(archive) >= FILNAMSIZ) {
  529. /* length of supplied archive name exceed the system's filename limit */
  530. DESTROYGLOBALS();
  531. retcode = PK_PARAM;
  532. goto exit_retcode;
  533. }
  534. G.wildzipfn = (char *)malloc(FILNAMSIZ);
  535. strcpy(G.wildzipfn, archive);
  536. #if (defined(WINDLL) && !defined(CRTL_CP_IS_ISO))
  537. _ISO_INTERN(G.wildzipfn);
  538. #endif
  539. #ifdef WINDLL
  540. Wiz_NoPrinting(TRUE);
  541. #endif
  542. G.process_all_files = TRUE; /* for speed */
  543. if (setjmp(dll_error_return) != 0) {
  544. #ifdef WINDLL
  545. Wiz_NoPrinting(FALSE);
  546. #endif
  547. free(G.wildzipfn);
  548. DESTROYGLOBALS();
  549. retcode = PK_BADERR;
  550. goto exit_retcode;
  551. }
  552. retcode = process_zipfiles(__G);
  553. free(G.wildzipfn);
  554. #ifdef WINDLL
  555. Wiz_NoPrinting(FALSE);
  556. #endif
  557. DESTROYGLOBALS();
  558. /* PK_WARN == 1 and PK_FIND == 11. When we are just looking at an
  559. archive, we should still be able to see the files inside it,
  560. even if we can't decode them for some reason.
  561. We also still want to be able to get at files even if there is
  562. something odd about the zip archive, hence allow PK_WARN,
  563. PK_FIND, IZ_UNSUP as well as PK_ERR
  564. */
  565. exit_retcode:
  566. if (AllCodes)
  567. return retcode;
  568. if ((retcode == PK_OK) || (retcode == PK_WARN) || (retcode == PK_ERR) ||
  569. (retcode == IZ_UNSUP) || (retcode == PK_FIND))
  570. return TRUE;
  571. else
  572. return FALSE;
  573. }
  574. #endif /* !SFX */
  575. #endif /* DLL */