unzip.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <flate.h>
  13. #include "zip.h"
  14. enum
  15. {
  16. BufSize = 4096
  17. };
  18. static int cheader(Biobuf *bin, ZipHead *zh);
  19. static int copyout(int ofd, Biobuf *bin, int32_t len);
  20. static int crcwrite(void *ofd, void *buf, int n);
  21. static int findCDir(Biobuf *bin, char *file);
  22. static int get1(Biobuf *b);
  23. static int get2(Biobuf *b);
  24. static uint32_t get4(Biobuf *b);
  25. static char *getname(Biobuf *b, int len);
  26. static int header(Biobuf *bin, ZipHead *zh);
  27. static int32_t msdos2time(int time, int date);
  28. static int sunzip(Biobuf *bin);
  29. static int sunztable(Biobuf *bin);
  30. static void trailer(Biobuf *bin, ZipHead *zh);
  31. static int unzip(Biobuf *bin, char *file);
  32. static int unzipEntry(Biobuf *bin, ZipHead *czh);
  33. static int unztable(Biobuf *bin, char *file);
  34. static int wantFile(char *file);
  35. static void *emalloc(uint32_t);
  36. static void error(char*, ...);
  37. #pragma varargck argpos error 1
  38. static Biobuf bin;
  39. static uint32_t crc;
  40. static uint32_t *crctab;
  41. static int debug;
  42. static char *delfile;
  43. static int lower;
  44. static int nwant;
  45. static uint32_t rlen;
  46. static int settimes;
  47. static int stdout;
  48. static int verbose;
  49. static char **want;
  50. static int wbad;
  51. static uint32_t wlen;
  52. static jmp_buf zjmp;
  53. static jmp_buf seekjmp;
  54. static int autodir;
  55. static void
  56. usage(void)
  57. {
  58. fprint(2, "usage: unzip [-cistTvD] [-f zipfile] [file ...]\n");
  59. exits("usage");
  60. }
  61. void
  62. main(int argc, char *argv[])
  63. {
  64. char *zfile;
  65. int fd, ok, table, stream;
  66. table = 0;
  67. stream = 0;
  68. zfile = nil;
  69. ARGBEGIN{
  70. case 'a':
  71. autodir++;
  72. break;
  73. case 'D':
  74. debug++;
  75. break;
  76. case 'c':
  77. stdout++;
  78. break;
  79. case 'i':
  80. lower++;
  81. break;
  82. case 'f':
  83. zfile = ARGF();
  84. if(zfile == nil)
  85. usage();
  86. break;
  87. case 's':
  88. stream++;
  89. break;
  90. case 't':
  91. table++;
  92. break;
  93. case 'T':
  94. settimes++;
  95. break;
  96. case 'v':
  97. verbose++;
  98. break;
  99. default:
  100. usage();
  101. break;
  102. }ARGEND
  103. nwant = argc;
  104. want = argv;
  105. crctab = mkcrctab(ZCrcPoly);
  106. ok = inflateinit();
  107. if(ok != FlateOk)
  108. sysfatal("inflateinit failed: %s", flateerr(ok));
  109. if(zfile == nil){
  110. Binit(&bin, 0, OREAD);
  111. zfile = "<stdin>";
  112. }else{
  113. fd = open(zfile, OREAD);
  114. if(fd < 0)
  115. sysfatal("can't open %s: %r", zfile);
  116. Binit(&bin, fd, OREAD);
  117. }
  118. if(setjmp(seekjmp)){
  119. fprint(2, "trying to re-run assuming -s\n");
  120. stream = 1;
  121. Bseek(&bin, 0, 0);
  122. }
  123. if(table){
  124. if(stream)
  125. ok = sunztable(&bin);
  126. else
  127. ok = unztable(&bin, zfile);
  128. }else{
  129. if(stream)
  130. ok = sunzip(&bin);
  131. else
  132. ok = unzip(&bin, zfile);
  133. }
  134. exits(ok ? nil: "errors");
  135. }
  136. /*
  137. * print the table of contents from the "central directory structure"
  138. */
  139. static int
  140. unztable(Biobuf *bin, char *file)
  141. {
  142. ZipHead zh;
  143. int entries;
  144. entries = findCDir(bin, file);
  145. if(entries < 0)
  146. return 0;
  147. if(verbose > 1)
  148. print("%d items in the archive\n", entries);
  149. while(entries-- > 0){
  150. if(setjmp(zjmp)){
  151. free(zh.file);
  152. return 0;
  153. }
  154. memset(&zh, 0, sizeof(zh));
  155. if(!cheader(bin, &zh))
  156. return 1;
  157. if(wantFile(zh.file)){
  158. if(verbose)
  159. print("%-32s %10lud %s", zh.file, zh.uncsize, ctime(msdos2time(zh.modtime, zh.moddate)));
  160. else
  161. print("%s\n", zh.file);
  162. if(verbose > 1){
  163. print("\tmade by os %d vers %d.%d\n", zh.madeos, zh.madevers/10, zh.madevers % 10);
  164. print("\textract by os %d vers %d.%d\n", zh.extos, zh.extvers/10, zh.extvers % 10);
  165. print("\tflags %x\n", zh.flags);
  166. print("\tmethod %d\n", zh.meth);
  167. print("\tmod time %d\n", zh.modtime);
  168. print("\tmod date %d\n", zh.moddate);
  169. print("\tcrc %lx\n", zh.crc);
  170. print("\tcompressed size %lu\n", zh.csize);
  171. print("\tuncompressed size %lu\n", zh.uncsize);
  172. print("\tinternal attributes %x\n", zh.iattr);
  173. print("\texternal attributes %lx\n", zh.eattr);
  174. print("\tstarts at %ld\n", zh.off);
  175. }
  176. }
  177. free(zh.file);
  178. zh.file = nil;
  179. }
  180. return 1;
  181. }
  182. /*
  183. * print the "local file header" table of contents
  184. */
  185. static int
  186. sunztable(Biobuf *bin)
  187. {
  188. ZipHead zh;
  189. int64_t off;
  190. uint32_t hcrc, hcsize, huncsize;
  191. int ok, err;
  192. ok = 1;
  193. for(;;){
  194. if(setjmp(zjmp)){
  195. free(zh.file);
  196. return 0;
  197. }
  198. memset(&zh, 0, sizeof(zh));
  199. if(!header(bin, &zh))
  200. return ok;
  201. hcrc = zh.crc;
  202. hcsize = zh.csize;
  203. huncsize = zh.uncsize;
  204. wlen = 0;
  205. rlen = 0;
  206. crc = 0;
  207. wbad = 0;
  208. if(zh.meth == 0){
  209. if(!copyout(-1, bin, zh.csize))
  210. error("reading data for %s failed: %r", zh.file);
  211. }else if(zh.meth == 8){
  212. off = Boffset(bin);
  213. err = inflate((void*)-1, crcwrite, bin, (int(*)(void*))Bgetc);
  214. if(err != FlateOk)
  215. error("inflate %s failed: %s", zh.file, flateerr(err));
  216. rlen = Boffset(bin) - off;
  217. }else
  218. error("can't handle compression method %d for %s", zh.meth, zh.file);
  219. trailer(bin, &zh);
  220. if(wantFile(zh.file)){
  221. if(verbose)
  222. print("%-32s %10lud %s", zh.file, zh.uncsize, ctime(msdos2time(zh.modtime, zh.moddate)));
  223. else
  224. print("%s\n", zh.file);
  225. if(verbose > 1){
  226. print("\textract by os %d vers %d.%d\n", zh.extos, zh.extvers / 10, zh.extvers % 10);
  227. print("\tflags %x\n", zh.flags);
  228. print("\tmethod %d\n", zh.meth);
  229. print("\tmod time %d\n", zh.modtime);
  230. print("\tmod date %d\n", zh.moddate);
  231. print("\tcrc %lx\n", zh.crc);
  232. print("\tcompressed size %lu\n", zh.csize);
  233. print("\tuncompressed size %lu\n", zh.uncsize);
  234. if((zh.flags & ZTrailInfo) && (hcrc || hcsize || huncsize)){
  235. print("\theader crc %lx\n", zh.crc);
  236. print("\theader compressed size %lu\n", zh.csize);
  237. print("\theader uncompressed size %lu\n", zh.uncsize);
  238. }
  239. }
  240. }
  241. if(zh.crc != crc)
  242. error("crc mismatch for %s", zh.file);
  243. if(zh.uncsize != wlen)
  244. error("output size mismatch for %s", zh.file);
  245. if(zh.csize != rlen)
  246. error("input size mismatch for %s", zh.file);
  247. free(zh.file);
  248. zh.file = nil;
  249. }
  250. }
  251. /*
  252. * extract files using the info in the central directory structure
  253. */
  254. static int
  255. unzip(Biobuf *bin, char *file)
  256. {
  257. ZipHead zh;
  258. int64_t off;
  259. int ok, eok, entries;
  260. entries = findCDir(bin, file);
  261. if(entries < 0)
  262. return 0;
  263. ok = 1;
  264. while(entries-- > 0){
  265. if(setjmp(zjmp)){
  266. free(zh.file);
  267. return 0;
  268. }
  269. memset(&zh, 0, sizeof(zh));
  270. if(!cheader(bin, &zh))
  271. return ok;
  272. off = Boffset(bin);
  273. if(wantFile(zh.file)){
  274. if(Bseek(bin, zh.off, 0) < 0){
  275. fprint(2, "unzip: can't seek to start of %s, skipping\n", zh.file);
  276. ok = 0;
  277. }else{
  278. eok = unzipEntry(bin, &zh);
  279. if(eok <= 0){
  280. fprint(2, "unzip: skipping %s\n", zh.file);
  281. ok = 0;
  282. }
  283. }
  284. }
  285. free(zh.file);
  286. zh.file = nil;
  287. if(Bseek(bin, off, 0) < 0){
  288. fprint(2, "unzip: can't seek to start of next entry, terminating extraction\n");
  289. return 0;
  290. }
  291. }
  292. return ok;
  293. }
  294. /*
  295. * extract files using the info the "local file headers"
  296. */
  297. static int
  298. sunzip(Biobuf *bin)
  299. {
  300. int eok;
  301. for(;;){
  302. eok = unzipEntry(bin, nil);
  303. if(eok == 0)
  304. return 1;
  305. if(eok < 0)
  306. return 0;
  307. }
  308. }
  309. static int mkdirs(char *);
  310. /*
  311. * if any directories leading up to path don't exist, create them.
  312. * modifies but restores path.
  313. */
  314. static int
  315. mkpdirs(char *path)
  316. {
  317. int rv = 0;
  318. char *sl = strrchr(path, '/');
  319. print("%s\n", path);
  320. if (sl != nil) {
  321. *sl = '\0';
  322. rv = mkdirs(path);
  323. *sl = '/';
  324. }
  325. return rv;
  326. }
  327. /*
  328. * if path or any directories leading up to it don't exist, create them.
  329. * modifies but restores path.
  330. */
  331. static int
  332. mkdirs(char *path)
  333. {
  334. int fd;
  335. if (access(path, AEXIST) >= 0)
  336. return 0;
  337. /* make presumed-missing intermediate directories */
  338. if (mkpdirs(path) < 0)
  339. return -1;
  340. /* make final directory */
  341. fd = create(path, OREAD, 0755|DMDIR);
  342. if (fd < 0)
  343. /*
  344. * we may have lost a race; if the directory now exists,
  345. * it's okay.
  346. */
  347. return access(path, AEXIST) < 0? -1: 0;
  348. close(fd);
  349. return 0;
  350. }
  351. /*
  352. * extracts a single entry from a zip file
  353. * czh is the optional corresponding central directory entry
  354. */
  355. static int
  356. unzipEntry(Biobuf *bin, ZipHead *czh)
  357. {
  358. Dir *d;
  359. ZipHead zh;
  360. char *p;
  361. int64_t off;
  362. int fd, isdir, ok, err;
  363. zh.file = nil;
  364. if(setjmp(zjmp)){
  365. delfile = nil;
  366. free(zh.file);
  367. return -1;
  368. }
  369. memset(&zh, 0, sizeof(zh));
  370. if(!header(bin, &zh))
  371. return 0;
  372. ok = 1;
  373. isdir = 0;
  374. fd = -1;
  375. if(wantFile(zh.file)){
  376. if(verbose)
  377. fprint(2, "extracting %s\n", zh.file);
  378. if(czh != nil && czh->extos == ZDos){
  379. isdir = czh->eattr & ZDDir;
  380. if(isdir && zh.uncsize != 0)
  381. fprint(2, "unzip: ignoring directory data for %s\n", zh.file);
  382. }
  383. if(zh.meth == 0 && zh.uncsize == 0){
  384. p = strchr(zh.file, '\0');
  385. if(p > zh.file && p[-1] == '/')
  386. isdir = 1;
  387. }
  388. if(stdout){
  389. if(ok && !isdir)
  390. fd = 1;
  391. }else if(isdir){
  392. fd = create(zh.file, OREAD, DMDIR | 0775);
  393. if(fd < 0){
  394. d = dirstat(zh.file);
  395. if(d == nil || (d->mode & DMDIR) != DMDIR){
  396. fprint(2, "unzip: can't create directory %s: %r\n", zh.file);
  397. ok = 0;
  398. }
  399. free(d);
  400. }
  401. }else if(ok){
  402. if(autodir)
  403. mkpdirs(zh.file);
  404. fd = create(zh.file, OWRITE, 0664);
  405. if(fd < 0){
  406. fprint(2, "unzip: can't create %s: %r\n", zh.file);
  407. ok = 0;
  408. }else
  409. delfile = zh.file;
  410. }
  411. }
  412. wlen = 0;
  413. rlen = 0;
  414. crc = 0;
  415. wbad = 0;
  416. if(zh.meth == 0){
  417. if(!copyout(fd, bin, zh.csize))
  418. error("copying data for %s failed: %r", zh.file);
  419. }else if(zh.meth == 8){
  420. off = Boffset(bin);
  421. err = inflate((void*)fd, crcwrite, bin, (int(*)(void*))Bgetc);
  422. if(err != FlateOk)
  423. error("inflate failed: %s", flateerr(err));
  424. rlen = Boffset(bin) - off;
  425. }else
  426. error("can't handle compression method %d for %s", zh.meth, zh.file);
  427. trailer(bin, &zh);
  428. if(zh.crc != crc)
  429. error("crc mismatch for %s", zh.file);
  430. if(zh.uncsize != wlen)
  431. error("output size mismatch for %s", zh.file);
  432. if(zh.csize != rlen)
  433. error("input size mismatch for %s", zh.file);
  434. delfile = nil;
  435. free(zh.file);
  436. if(fd >= 0 && !stdout){
  437. if(settimes){
  438. d = dirfstat(fd);
  439. if(d != nil){
  440. d->mtime = msdos2time(zh.modtime, zh.moddate);
  441. if(d->mtime)
  442. dirfwstat(fd, d);
  443. }
  444. }
  445. close(fd);
  446. }
  447. return ok;
  448. }
  449. static int
  450. wantFile(char *file)
  451. {
  452. int i, n;
  453. if(nwant == 0)
  454. return 1;
  455. for(i = 0; i < nwant; i++){
  456. if(strcmp(want[i], file) == 0)
  457. return 1;
  458. n = strlen(want[i]);
  459. if(strncmp(want[i], file, n) == 0 && file[n] == '/')
  460. return 1;
  461. }
  462. return 0;
  463. }
  464. /*
  465. * find the start of the central directory
  466. * returns the number of entries in the directory,
  467. * or -1 if there was an error
  468. */
  469. static int
  470. findCDir(Biobuf *bin, char *file)
  471. {
  472. int64_t ecoff;
  473. int32_t off, size, m;
  474. int entries, zclen, dn, ds, de;
  475. ecoff = Bseek(bin, -ZECHeadSize, 2);
  476. if(ecoff < 0){
  477. fprint(2, "unzip: can't seek to contents of %s\n", file);
  478. longjmp(seekjmp, 1);
  479. return -1;
  480. }
  481. if(setjmp(zjmp))
  482. return -1;
  483. if((m=get4(bin)) != ZECHeader){
  484. fprint(2, "unzip: bad magic number for table of contents of %s: %#.8lx\n", file, m);
  485. longjmp(seekjmp, 1);
  486. return -1;
  487. }
  488. dn = get2(bin);
  489. ds = get2(bin);
  490. de = get2(bin);
  491. entries = get2(bin);
  492. size = get4(bin);
  493. off = get4(bin);
  494. zclen = get2(bin);
  495. while(zclen-- > 0)
  496. get1(bin);
  497. if(verbose > 1){
  498. print("table starts at %ld for %ld bytes\n", off, size);
  499. if(ecoff - size != off)
  500. print("\ttable should start at %lld-%ld=%lld\n", ecoff, size, ecoff-size);
  501. if(dn || ds || de != entries)
  502. print("\tcurrent disk=%d start disk=%d table entries on this disk=%d\n", dn, ds, de);
  503. }
  504. if(Bseek(bin, off, 0) != off){
  505. fprint(2, "unzip: can't seek to start of contents of %s\n", file);
  506. longjmp(seekjmp, 1);
  507. return -1;
  508. }
  509. return entries;
  510. }
  511. static int
  512. cheader(Biobuf *bin, ZipHead *zh)
  513. {
  514. uint32_t v;
  515. int flen, xlen, fclen;
  516. v = get4(bin);
  517. if(v != ZCHeader){
  518. if(v == ZECHeader)
  519. return 0;
  520. error("bad magic number %lx", v);
  521. }
  522. zh->madevers = get1(bin);
  523. zh->madeos = get1(bin);
  524. zh->extvers = get1(bin);
  525. zh->extos = get1(bin);
  526. zh->flags = get2(bin);
  527. zh->meth = get2(bin);
  528. zh->modtime = get2(bin);
  529. zh->moddate = get2(bin);
  530. zh->crc = get4(bin);
  531. zh->csize = get4(bin);
  532. zh->uncsize = get4(bin);
  533. flen = get2(bin);
  534. xlen = get2(bin);
  535. fclen = get2(bin);
  536. get2(bin); /* disk number start */
  537. zh->iattr = get2(bin);
  538. zh->eattr = get4(bin);
  539. zh->off = get4(bin);
  540. zh->file = getname(bin, flen);
  541. while(xlen-- > 0)
  542. get1(bin);
  543. while(fclen-- > 0)
  544. get1(bin);
  545. return 1;
  546. }
  547. static int
  548. header(Biobuf *bin, ZipHead *zh)
  549. {
  550. uint32_t v;
  551. int flen, xlen;
  552. v = get4(bin);
  553. if(v != ZHeader){
  554. if(v == ZCHeader)
  555. return 0;
  556. error("bad magic number %lx at %lld", v, Boffset(bin)-4);
  557. }
  558. zh->extvers = get1(bin);
  559. zh->extos = get1(bin);
  560. zh->flags = get2(bin);
  561. zh->meth = get2(bin);
  562. zh->modtime = get2(bin);
  563. zh->moddate = get2(bin);
  564. zh->crc = get4(bin);
  565. zh->csize = get4(bin);
  566. zh->uncsize = get4(bin);
  567. flen = get2(bin);
  568. xlen = get2(bin);
  569. zh->file = getname(bin, flen);
  570. while(xlen-- > 0)
  571. get1(bin);
  572. return 1;
  573. }
  574. static void
  575. trailer(Biobuf *bin, ZipHead *zh)
  576. {
  577. if(zh->flags & ZTrailInfo){
  578. zh->crc = get4(bin);
  579. zh->csize = get4(bin);
  580. zh->uncsize = get4(bin);
  581. }
  582. }
  583. static char*
  584. getname(Biobuf *bin, int len)
  585. {
  586. char *s;
  587. int i, c;
  588. s = emalloc(len + 1);
  589. for(i = 0; i < len; i++){
  590. c = get1(bin);
  591. if(lower)
  592. c = tolower(c);
  593. s[i] = c;
  594. }
  595. s[i] = '\0';
  596. return s;
  597. }
  598. static int
  599. crcwrite(void *out, void *buf, int n)
  600. {
  601. int fd, nw;
  602. wlen += n;
  603. crc = blockcrc(crctab, crc, buf, n);
  604. fd = (int)(uintptr)out;
  605. if(fd < 0)
  606. return n;
  607. nw = write(fd, buf, n);
  608. if(nw != n)
  609. wbad = 1;
  610. return nw;
  611. }
  612. static int
  613. copyout(int ofd, Biobuf *bin, int32_t len)
  614. {
  615. char buf[BufSize];
  616. int n;
  617. for(; len > 0; len -= n){
  618. n = len;
  619. if(n > BufSize)
  620. n = BufSize;
  621. n = Bread(bin, buf, n);
  622. if(n <= 0)
  623. return 0;
  624. rlen += n;
  625. if(crcwrite((void*)ofd, buf, n) != n)
  626. return 0;
  627. }
  628. return 1;
  629. }
  630. static uint32_t
  631. get4(Biobuf *b)
  632. {
  633. uint32_t v;
  634. int i, c;
  635. v = 0;
  636. for(i = 0; i < 4; i++){
  637. c = Bgetc(b);
  638. if(c < 0)
  639. error("unexpected eof reading file information");
  640. v |= c << (i * 8);
  641. }
  642. return v;
  643. }
  644. static int
  645. get2(Biobuf *b)
  646. {
  647. int i, c, v;
  648. v = 0;
  649. for(i = 0; i < 2; i++){
  650. c = Bgetc(b);
  651. if(c < 0)
  652. error("unexpected eof reading file information");
  653. v |= c << (i * 8);
  654. }
  655. return v;
  656. }
  657. static int
  658. get1(Biobuf *b)
  659. {
  660. int c;
  661. c = Bgetc(b);
  662. if(c < 0)
  663. error("unexpected eof reading file information");
  664. return c;
  665. }
  666. static int32_t
  667. msdos2time(int time, int date)
  668. {
  669. Tm tm;
  670. tm.hour = time >> 11;
  671. tm.min = (time >> 5) & 63;
  672. tm.sec = (time & 31) << 1;
  673. tm.year = 80 + (date >> 9);
  674. tm.mon = ((date >> 5) & 15) - 1;
  675. tm.mday = date & 31;
  676. tm.zone[0] = '\0';
  677. tm.yday = 0;
  678. return tm2sec(&tm);
  679. }
  680. static void*
  681. emalloc(uint32_t n)
  682. {
  683. void *p;
  684. p = malloc(n);
  685. if(p == nil)
  686. sysfatal("out of memory");
  687. return p;
  688. }
  689. static void
  690. error(char *fmt, ...)
  691. {
  692. va_list arg;
  693. fprint(2, "unzip: ");
  694. va_start(arg, fmt);
  695. vfprint(2, fmt, arg);
  696. va_end(arg);
  697. fprint(2, "\n");
  698. if(delfile != nil){
  699. fprint(2, "unzip: removing output file %s\n", delfile);
  700. remove(delfile);
  701. delfile = nil;
  702. }
  703. longjmp(zjmp, 1);
  704. }