home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip52.zip / process.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  42KB  |  1,105 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   process.c
  4.  
  5.   This file contains the top-level routines for processing multiple zipfiles.
  6.  
  7.   Contains:  process_zipfiles()
  8.              do_seekable()
  9.              find_ecrec()
  10.              uz_end_central()
  11.              process_cdir_file_hdr()
  12.              get_cdir_ent()
  13.              process_local_file_hdr()
  14.              ef_scan_for_izux()
  15.  
  16.   ---------------------------------------------------------------------------*/
  17.  
  18.  
  19. #define UNZIP_INTERNAL
  20. #include "unzip.h"
  21. #ifdef MSWIN
  22. #  include <windows.h>
  23. #  include "wingui\wizunzip.h"
  24. #endif
  25.  
  26. static int    do_seekable        OF((__GPRO__ int lastchance));
  27. static int    find_ecrec         OF((__GPRO__ long searchlen));
  28.  
  29. static char Far CantAllocateBuffers[] =
  30.   "error:  can't allocate unzip buffers\n";
  31.  
  32. #ifdef SFX
  33.    static char Far CantFindMyself[] =
  34.      "unzipsfx:  can't find myself! [%s]\n";
  35. #else /* !SFX */
  36.  
  37.    /* process_zipfiles() strings */
  38.    static char Far FilesProcessOK[] = "%d archive%s successfully processed.\n";
  39.    static char Far ArchiveWarning[] =
  40.      "%d archive%s had warnings but no fatal errors.\n";
  41.    static char Far ArchiveFatalError[] = "%d archive%s had fatal errors.\n";
  42.    static char Far FileHadNoZipfileDir[] =
  43.      "%d file%s had no zipfile directory.\n";
  44.    static char Far ZipfileWasDir[] = "1 \"zipfile\" was a directory.\n";
  45.    static char Far ManyZipfilesWereDir[] =
  46.      "%d \"zipfiles\" were directories.\n";
  47.    static char Far NoZipfileFound[] = "No zipfiles found.\n";
  48.  
  49.    /* do_seekable() strings */
  50. # ifdef UNIX
  51.    static char Far CantFindZipfileDirMsg[] =
  52.      "%s:  can't find zipfile directory in one of %s or\n\
  53.         %s%s.zip, and can't find %s, period.\n";
  54.    static char Far CantFindEitherZipfile[] =
  55.      "%s:  can't find %s, %s.zip or %s, so there.\n";
  56. # else /* !UNIX */
  57.    static char Far CantFindWildcardMatch[] =
  58.      "%s:  can't find any matches for wildcard specification \"%s\".\n";
  59.    static char Far CantFindZipfileDirMsg[] =
  60.      "%s:  can't find zipfile directory in %s,\n\
  61.         %sand can't find %s, period.\n";
  62.    static char Far CantFindEitherZipfile[] =
  63.      "%s:  can't find either %s or %s, so there.\n";
  64. # endif /* ?UNIX */
  65.    extern char Far Zipnfo[];              /* in unzip.c */
  66. #ifndef MSWIN
  67.    static char Far Unzip[] = "unzip";
  68. #else
  69.    static char Far Unzip[] = "WizUnZip";
  70. #endif
  71.    static char Far MaybeExe[] =
  72.      "note:  %s may be a plain executable, not an archive\n";
  73.    static char Far CentDirNotInZipMsg[] = "\n\
  74.    [%s]:\n\
  75.      Zipfile is disk %u of a multi-disk archive, and this is not the disk on\n\
  76.      which the central zipfile directory begins (disk %u).\n";
  77.    static char Far EndCentDirBogus[] =
  78.      "\nwarning [%s]:  end-of-central-directory record claims this\n\
  79.   is disk %u but that the central directory starts on disk %u; this is a\n\
  80.   contradiction.  Attempting to process anyway.\n";
  81. # ifdef NO_MULTIPART
  82.    static char Far NoMultiDiskArcSupport[] =
  83.      "\nerror [%s]:  zipfile is part of multi-disk archive\n\
  84.   (sorry, not yet supported).\n";
  85.    static char Far MaybePakBug[] = "warning [%s]:\
  86.   zipfile claims to be 2nd disk of a 2-part archive;\n\
  87.   attempting to process anyway.  If no further errors occur, this archive\n\
  88.   was probably created by PAK v2.51 or earlier.  This bug was reported to\n\
  89.   NoGate in March 1991 and was supposed to have been fixed by mid-1991; as\n\
  90.   of mid-1992 it still hadn't been.  (If further errors do occur, archive\n\
  91.   was probably created by PKZIP 2.04c or later; UnZip does not yet support\n\
  92.   multi-part archives.)\n";
  93. # else
  94.    static char Far MaybePakBug[] = "warning [%s]:\
  95.   zipfile claims to be last disk of a multi-part archive;\n\
  96.   attempting to process anyway, assuming all parts have been concatenated\n\
  97.   together in order.  Expect \"errors\" and warnings...true multi-part support\
  98. \n  doesn't exist yet (coming soon).\n";
  99. # endif
  100.    static char Far ExtraBytesAtStart[] =
  101.      "warning [%s]:  %ld extra byte%s at beginning or within zipfile\n\
  102.   (attempting to process anyway)\n";
  103. #endif /* ?SFX */
  104.  
  105. static char Far MissingBytes[] =
  106.   "error [%s]:  missing %ld bytes in zipfile\n\
  107.   (attempting to process anyway)\n";
  108. static char Far NullCentDirOffset[] =
  109.   "error [%s]:  NULL central directory offset\n\
  110.   (attempting to process anyway)\n";
  111. static char Far ZipfileEmpty[] = "warning [%s]:  zipfile is empty\n";
  112. static char Far CentDirStartNotFound[] =
  113.   "error [%s]:  start of central directory not found;\n\
  114.   zipfile corrupt.\n%s";
  115. static char Far CentDirTooLong[] =
  116.   "error [%s]:  reported length of central directory is\n\
  117.   %ld bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1\n\
  118.   zipfile?).  Compensating...\n";
  119. static char Far CentDirEndSigNotFound[] = "\
  120.   End-of-central-directory signature not found.  Either this file is not\n\
  121.   a zipfile, or it constitutes one disk of a multi-part archive.  In the\n\
  122.   latter case the central directory and zipfile comment will be found on\n\
  123.   the last disk(s) of this archive.\n";
  124. static char Far ZipfileCommTrunc1[] = "\ncaution:  zipfile comment truncated\n";
  125.  
  126.  
  127.  
  128.  
  129. /*******************************/
  130. /* Function process_zipfiles() */
  131. /*******************************/
  132.  
  133. int process_zipfiles(__G)    /* return PK-type error code */
  134.      __GDEF
  135. {
  136. #ifndef SFX
  137.     char *lastzipfn = (char *)NULL;
  138.     int NumWinFiles, NumLoseFiles, NumWarnFiles;
  139.     int NumMissDirs, NumMissFiles;
  140. #endif
  141.     int error=0, error_in_archive=0;
  142.  
  143.  
  144. /*---------------------------------------------------------------------------
  145.     Start by allocating buffers and (re)constructing the various PK signature
  146.     strings.
  147.   ---------------------------------------------------------------------------*/
  148.  
  149.     G.inbuf = (uch *)malloc(INBUFSIZ + 4);    /* 4 extra for hold[] (below) */
  150.  
  151.     /* Normally realbuf and outbuf will be the same.  However, if the data
  152.      * are redirected to a large memory buffer, realbuf will point to the
  153.      * new location while outbuf will remain pointing to the malloc'd
  154.      * memory buffer.  (The extra "1" is for string termination.) */
  155.     G.realbuf = G.outbuf = (uch *)malloc(OUTBUFSIZ + 1);
  156.  
  157.     if ((G.inbuf == (uch *)NULL) || (G.outbuf == (uch *)NULL)) {
  158.         Info(slide, 0x401, ((char *)slide, LoadFarString(CantAllocateBuffers)));
  159.         RETURN(PK_MEM);
  160.     }
  161.     G.hold = G.inbuf + INBUFSIZ;     /* to check for boundary-spanning sigs */
  162. #ifndef VMS     /* VMS uses its own buffer scheme for textmode flush(). */
  163. #ifdef SMALL_MEM
  164.     G.outbuf2 = G.outbuf+RAWBUFSIZ;  /* never changes */
  165. #endif
  166. #endif /* !VMS */
  167.  
  168. #if 0 /* CRC_32_TAB has been NULLified by CONSTRUCTGLOBALS !!!! */
  169.     /* allocate the CRC table only later when we know we have a zipfile */
  170.     CRC_32_TAB = (ulg *)NULL;
  171. #endif /* 0 */
  172.  
  173.     G.local_hdr_sig[0]  /* = extd_local_sig[0] */  = 0x50;   /* ASCII 'P', */
  174.     G.central_hdr_sig[0] = G.end_central_sig[0] = 0x50;     /* not EBCDIC */
  175.  
  176.     G.local_hdr_sig[1]  /* = extd_local_sig[1] */  = 0x4B;   /* ASCII 'K', */
  177.     G.central_hdr_sig[1] = G.end_central_sig[1] = 0x4B;     /* not EBCDIC */
  178.  
  179.     /* GRR FIX:  no need for these to be in global struct; OK to "overwrite" */
  180.     strcpy(G.local_hdr_sig+2, LOCAL_HDR_SIG);
  181.     strcpy(G.central_hdr_sig+2, CENTRAL_HDR_SIG);
  182.     strcpy(G.end_central_sig+2, END_CENTRAL_SIG);
  183. /*  strcpy(extd_local_sig+2, EXTD_LOCAL_SIG);   still to be used in multi? */
  184.  
  185. #if (defined(OS2) && defined(__IBMC__))
  186.     _tzset();   /* initialize timezone info (from TZ) since no other chance */
  187. #endif          /*  (underscore name is accepted by all versions of C Set) */
  188.  
  189. /*---------------------------------------------------------------------------
  190.     Match (possible) wildcard zipfile specification with existing files and
  191.     attempt to process each.  If no hits, try again after appending ".zip"
  192.     suffix.  If still no luck, give up.
  193.   ---------------------------------------------------------------------------*/
  194.  
  195. #ifdef SFX
  196.     if ((error = do_seekable(__G__ 0)) == PK_NOZIP) {
  197. #ifdef EXE_EXTENSION
  198.         int len=strlen(G.argv0);
  199.  
  200.         /* append .exe if appropriate; also .sfx? */
  201.         if ( (G.zipfn = (char *)malloc(len+sizeof(EXE_EXTENSION))) !=
  202.              (char *)NULL ) {
  203.             strcpy(G.zipfn, G.argv0);
  204.             strcpy(G.zipfn+len, EXE_EXTENSION);
  205.             error = do_seekable(__G__ 0);
  206.             free(G.zipfn);
  207.             G.zipfn = G.argv0;  /* for "can't find myself" message only */
  208.         }
  209. #endif /* EXE_EXTENSION */
  210. #ifdef WIN32
  211.         G.zipfn = G.argv0;  /* for "can't find myself" message only */
  212. #endif
  213.     }
  214.     if (error) {
  215.         if (error == IZ_DIR)
  216.             error_in_archive = PK_NOZIP;
  217.         else
  218.             error_in_archive = error;
  219.         if (error == PK_NOZIP)
  220.             Info(slide, 1, ((char *)slide, LoadFarString(CantFindMyself),
  221.               G.zipfn));
  222.     }
  223.  
  224. #else /* !SFX */
  225.     NumWinFiles = NumLoseFiles = NumWarnFiles = 0;
  226.     NumMissDirs = NumMissFiles = 0;
  227.  
  228.     while ((G.zipfn = do_wild(__G__ G.wildzipfn)) != (char *)NULL) {
  229.         Trace((stderr, "do_wild( %s ) returns %s\n", G.wildzipfn, G.zipfn));
  230.  
  231.         lastzipfn = G.zipfn;
  232.  
  233.         /* print a blank line between the output of different zipfiles */
  234. #ifdef TIMESTAMP
  235.         if (!G.qflag  &&  !G.T_flag  &&  error != PK_NOZIP  &&  error != IZ_DIR
  236.             && (NumWinFiles+NumLoseFiles+NumWarnFiles+NumMissFiles) > 0)
  237. #else
  238.         if (!G.qflag  &&  error != PK_NOZIP  &&  error != IZ_DIR
  239.             && (NumWinFiles+NumLoseFiles+NumWarnFiles+NumMissFiles) > 0)
  240. #endif
  241.             (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);
  242.  
  243.         if ((error = do_seekable(__G__ 0)) == PK_WARN)
  244.             ++NumWarnFiles;
  245.         else if (error == IZ_DIR)
  246.             ++NumMissDirs;
  247.         else if (error == PK_NOZIP)
  248.             ++NumMissFiles;
  249.         else if (error)
  250.             ++NumLoseFiles;
  251.         else
  252.             ++NumWinFiles;
  253.  
  254.         if (error != IZ_DIR && error > error_in_archive)
  255.             error_in_archive = error;
  256.         Trace((stderr, "do_seekable(0) returns %d\n", error));
  257.  
  258.     } /* end while-loop (wildcard zipfiles) */
  259.  
  260.     if ((NumWinFiles + NumWarnFiles + NumLoseFiles) == 0  &&
  261.         (NumMissDirs + NumMissFiles) == 1  &&  lastzipfn != (char *)NULL)
  262.     {
  263.         NumMissDirs = NumMissFiles = 0;
  264.         if (error_in_archive == PK_NOZIP)
  265.             error_in_archive = PK_COOL;
  266.  
  267. #if (!defined(UNIX) && !defined(AMIGA)) /* filenames with wildcard characters */
  268.         if (iswild(G.wildzipfn))
  269.             Info(slide, 0x401, ((char *)slide,
  270.               LoadFarString(CantFindWildcardMatch), G.zipinfo_mode?
  271.               LoadFarStringSmall(Zipnfo) : LoadFarStringSmall(Unzip),
  272.               G.wildzipfn));
  273.         else
  274. #endif
  275.         {
  276.             char *p = lastzipfn + strlen(lastzipfn);
  277.  
  278.             G.zipfn = lastzipfn;
  279.             strcpy(p, ZSUFX);
  280.  
  281. #ifdef UNIX   /* only Unix has case-sensitive filesystems */
  282.             if ((error = do_seekable(__G__ 0)) == PK_NOZIP || error == IZ_DIR) {
  283.                 if (error == IZ_DIR)
  284.                     ++NumMissDirs;
  285.                 strcpy(p, ".ZIP");
  286.                 error = do_seekable(__G__ 1);
  287.             }
  288. #else
  289.             error = do_seekable(__G__ 1);
  290. #endif
  291.             if (error == PK_WARN)   /* GRR: make this a switch/case stmt ... */
  292.                 ++NumWarnFiles;
  293.             else if (error == IZ_DIR)
  294.                 ++NumMissDirs;
  295.             else if (error == PK_NOZIP)
  296.                 /* increment again => bug: "1 file had no zipfile directory." */
  297.                 /* ++NumMissFiles */ ;
  298.             else if (error)
  299.                 ++NumLoseFiles;
  300.             else
  301.                 ++NumWinFiles;
  302.  
  303.             if (error > error_in_archive)
  304.                 error_in_archive = error;
  305.             Trace((stderr, "do_seekable(1) returns %d\n", error));
  306.         }
  307.     }
  308. #endif /* ?SFX */
  309.  
  310. /*---------------------------------------------------------------------------
  311.     Print summary of all zipfiles, assuming zipfile spec was a wildcard (no
  312.     need for a summary if just one zipfile).
  313.   ---------------------------------------------------------------------------*/
  314.  
  315. #ifndef SFX
  316.     if (iswild(G.wildzipfn) && G.qflag < 3
  317. #ifdef TIMESTAMP
  318.                                            && !(G.T_flag && G.qflag)
  319. #endif
  320.                                                                     )
  321.     {
  322.         if (NumMissFiles + NumLoseFiles + NumWarnFiles > 0 || NumWinFiles != 1)
  323.             if (!(G.tflag && G.qflag > 1)
  324. #ifdef TIMESTAMP
  325.                                           && !G.T_flag
  326. #endif
  327.                                                       )
  328.                 (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0x401);
  329.         if ((NumWinFiles > 1) || (NumWinFiles == 1 &&
  330.             NumMissDirs + NumMissFiles + NumLoseFiles + NumWarnFiles > 0))
  331.             Info(slide, 0x401, ((char *)slide, LoadFarString(FilesProcessOK),
  332.               NumWinFiles, (NumWinFiles == 1)? " was" : "s were"));
  333.         if (NumWarnFiles > 0)
  334.             Info(slide, 0x401, ((char *)slide, LoadFarString(ArchiveWarning),
  335.               NumWarnFiles, (NumWarnFiles == 1)? "" : "s"));
  336.         if (NumLoseFiles > 0)
  337.             Info(slide, 0x401, ((char *)slide, LoadFarString(ArchiveFatalError),
  338.               NumLoseFiles, (NumLoseFiles == 1)? "" : "s"));
  339.         if (NumMissFiles > 0)
  340.             Info(slide, 0x401, ((char *)slide,
  341.               LoadFarString(FileHadNoZipfileDir), NumMissFiles,
  342.               (NumMissFiles == 1)? "" : "s"));
  343.         if (NumMissDirs == 1)
  344.             Info(slide, 0x401, ((char *)slide, LoadFarString(ZipfileWasDir)));
  345.         else if (NumMissDirs > 0)
  346.             Info(slide, 0x401, ((char *)slide,
  347.               LoadFarString(ManyZipfilesWereDir), NumMissDirs));
  348.         if (NumWinFiles + NumLoseFiles + NumWarnFiles == 0)
  349.             Info(slide, 0x401, ((char *)slide, LoadFarString(NoZipfileFound)));
  350.     }
  351. #endif /* !SFX */
  352.  
  353.     /* free allocated memory */
  354.     inflate_free(__G);
  355.     checkdir(__G__ (char *)NULL, END);
  356. #ifdef DYNALLOC_CRCTAB
  357.     if (G.extract_flag && CRC_32_TAB)
  358.         nearfree((zvoid near *)CRC_32_TAB);
  359. #endif /* DYNALLOC_CRCTAB */
  360. #ifndef VMS     /* VMS uses its own buffer scheme for textmode flush(). */
  361. #ifndef SMALL_MEM
  362.     if (G.outbuf2)
  363.         free(G.outbuf2);   /* malloc'd ONLY if unshrink and -a */
  364. #endif
  365. #endif /* VMS */
  366.     free(G.outbuf);
  367.     free(G.inbuf);
  368.  
  369.     return error_in_archive;
  370.  
  371. } /* end function process_zipfiles() */
  372.  
  373.  
  374.  
  375.  
  376.  
  377. /**************************/
  378. /* Function do_seekable() */
  379. /**************************/
  380.  
  381. static int do_seekable(__G__ lastchance)        /* return PK-type error code */
  382.      __GDEF
  383.     int lastchance;
  384. {
  385. #ifndef SFX
  386.     /* static int no_ecrec = FALSE;  SKM: moved to globals.h */
  387.     int maybe_exe=FALSE;
  388.     int too_weird_to_continue=FALSE;
  389. #endif
  390.     int error=0, error_in_archive;
  391.  
  392.  
  393. /*---------------------------------------------------------------------------
  394.     Open the zipfile for reading in BINARY mode to prevent CR/LF translation,
  395.     which would corrupt the bit streams.
  396.   ---------------------------------------------------------------------------*/
  397.  
  398.     if (SSTAT(G.zipfn, &G.statbuf) ||
  399.         (error = S_ISDIR(G.statbuf.st_mode)) != 0)
  400.     {
  401. #ifndef SFX
  402.         if (lastchance)
  403. #ifdef UNIX
  404.             if (G.no_ecrec)
  405.                 Info(slide, 1, ((char *)slide,
  406.                   LoadFarString(CantFindZipfileDirMsg), G.zipinfo_mode?
  407.                   LoadFarStringSmall(Zipnfo) : LoadFarStringSmall(Unzip),
  408.                   G.wildzipfn, G.zipinfo_mode? "  " : "", G.wildzipfn,
  409.                   G.zipfn));
  410.             else
  411.                 Info(slide, 1, ((char *)slide,
  412.                   LoadFarString(CantFindEitherZipfile), G.zipinfo_mode?
  413.                   LoadFarStringSmall(Zipnfo) : LoadFarStringSmall(Unzip),
  414.                   G.wildzipfn, G.wildzipfn, G.zipfn));
  415. #else /* !UNIX */
  416.             if (G.no_ecrec)
  417.                 Info(slide, 0x401, ((char *)slide,
  418.                   LoadFarString(CantFindZipfileDirMsg), G.zipinfo_mode?
  419.                   LoadFarStringSmall(Zipnfo) : LoadFarStringSmall(Unzip),
  420.                   G.wildzipfn, G.zipinfo_mode? "  " : "", G.zipfn));
  421.             else
  422.                 Info(slide, 0x401, ((char *)slide,
  423.                   LoadFarString(CantFindEitherZipfile), G.zipinfo_mode?
  424.                   LoadFarStringSmall(Zipnfo) : LoadFarStringSmall(Unzip),
  425.                   G.wildzipfn, G.zipfn));
  426. #endif /* ?UNIX */
  427. #endif /* !SFX */
  428.         return error? IZ_DIR : PK_NOZIP;
  429.     }
  430.     G.ziplen = G.statbuf.st_size;
  431.  
  432. #ifndef SFX
  433. #if defined(UNIX) || defined(DOS_OS2_W32)
  434.     if (G.statbuf.st_mode & S_IEXEC)   /* no extension on Unix exes:  might */
  435.         maybe_exe = TRUE;               /*  find unzip, not unzip.zip; etc. */
  436. #endif
  437. #endif /* !SFX */
  438.  
  439. #ifdef VMS
  440.     if (check_format(__G))              /* check for variable-length format */
  441.         return PK_ERR;
  442. #endif
  443.  
  444.     if (open_input_file(__G))   /* this should never happen, given */
  445.         return PK_NOZIP;        /*  the stat() test above, but... */
  446.  
  447. /*---------------------------------------------------------------------------
  448.     Find and process the end-of-central-directory header.  UnZip need only
  449.     check last 65557 bytes of zipfile:  comment may be up to 65535, end-of-
  450.     central-directory record is 18 bytes, and signature itself is 4 bytes;
  451.     add some to allow for appended garbage.  Since ZipInfo is often used as
  452.     a debugging tool, search the whole zipfile if zipinfo_mode is true.
  453.   ---------------------------------------------------------------------------*/
  454.  
  455.     /* initialize the CRC table pointer (once) */
  456.     if (CRC_32_TAB == (ulg near *)NULL) {
  457.         if ((CRC_32_TAB = (ulg near *)get_crc_table()) == (ulg near *)NULL)
  458.             return PK_MEM2;
  459.     }
  460.  
  461.     G.cur_zipfile_bufstart = 0;
  462.     G.inptr = G.inbuf;
  463.  
  464. #if (!defined(MSWIN) && !defined(SFX))
  465. #ifdef TIMESTAMP
  466.     if (!G.qflag && !G.T_flag && !G.zipinfo_mode)
  467. #else
  468.     if (!G.qflag && !G.zipinfo_mode)
  469. #endif
  470.         Info(slide, 0, ((char *)slide, "Archive:  %s\n", G.zipfn));
  471. #endif /* !MSWIN && !SFX */
  472.  
  473.     if ((
  474. #ifndef NO_ZIPINFO
  475.          G.zipinfo_mode &&
  476.           ((error_in_archive = find_ecrec(__G__ G.ziplen)) != 0 ||
  477.           (error_in_archive = zi_end_central(__G)) > PK_WARN))
  478.         || (!G.zipinfo_mode &&
  479. #endif
  480.           ((error_in_archive = find_ecrec(__G__ MIN(G.ziplen,66000L))) != 0 ||
  481.           (error_in_archive = uz_end_central(__G)) > PK_WARN)))
  482.     {
  483.         close(G.zipfd);
  484. #ifdef SFX
  485.         ++lastchance;   /* avoid picky compiler warnings */
  486.         return error_in_archive;
  487. #else
  488.         if (maybe_exe)
  489.             Info(slide, 0x401, ((char *)slide, LoadFarString(MaybeExe),
  490.             G.zipfn));
  491.         if (lastchance)
  492.             return error_in_archive;
  493.         else {
  494.             G.no_ecrec = TRUE;    /* assume we found wrong file:  e.g., */
  495.             return PK_NOZIP;       /*  unzip instead of unzip.zip */
  496.         }
  497. #endif /* ?SFX */
  498.     }
  499.  
  500.     if ((G.zflag > 0) && !G.zipinfo_mode) {  /* unzip: zflag = comment ONLY */
  501.         close(G.zipfd);
  502.         return error_in_archive;
  503.     }
  504.  
  505. /*---------------------------------------------------------------------------
  506.     Test the end-of-central-directory info for incompatibilities (multi-disk
  507.     archives) or inconsistencies (missing or extra bytes in zipfile).
  508.   ---------------------------------------------------------------------------*/
  509.  
  510. #ifdef NO_MULTIPART
  511.     error = !G.zipinfo_mode && (G.ecrec.number_this_disk == 1) &&
  512.             (G.ecrec.num_disk_start_cdir == 1);
  513. #else
  514.     error = !G.zipinfo_mode && (G.ecrec.number_this_disk != 0);
  515. #endif
  516.  
  517. #ifndef SFX
  518.     if (G.zipinfo_mode &&
  519.         G.ecrec.number_this_disk != G.ecrec.num_disk_start_cdir)
  520.     {
  521.         if (G.ecrec.number_this_disk > G.ecrec.num_disk_start_cdir) {
  522.             Info(slide, 0x401, ((char *)slide,
  523.               LoadFarString(CentDirNotInZipMsg), G.zipfn,
  524.               G.ecrec.number_this_disk, G.ecrec.num_disk_start_cdir));
  525.             error_in_archive = PK_FIND;
  526.             too_weird_to_continue = TRUE;
  527.         } else {
  528.             Info(slide, 0x401, ((char *)slide,
  529.               LoadFarString(EndCentDirBogus), G.zipfn,
  530.               G.ecrec.number_this_disk, G.ecrec.num_disk_start_cdir));
  531.             error_in_archive = PK_WARN;
  532.         }
  533. #ifdef NO_MULTIPART   /* concatenation of multiple parts works in some cases */
  534.     } else if (!G.zipinfo_mode && !error && G.ecrec.number_this_disk != 0) {
  535.         Info(slide, 0x401, ((char *)slide, LoadFarString(NoMultiDiskArcSupport),
  536.           G.zipfn));
  537.         error_in_archive = PK_FIND;
  538.         too_weird_to_continue = TRUE;
  539. #endif
  540.     }
  541.  
  542.     if (!too_weird_to_continue) {  /* (relatively) normal zipfile:  go for it */
  543.         if (error) {
  544.             Info(slide, 0x401, ((char *)slide, LoadFarString(MaybePakBug),
  545.               G.zipfn));
  546.             error_in_archive = PK_WARN;
  547.         }
  548. #endif /* !SFX */
  549.         if ((G.extra_bytes = G.real_ecrec_offset-G.expect_ecrec_offset) <
  550.             (LONGINT)0)
  551.         {
  552.             Info(slide, 0x401, ((char *)slide, LoadFarString(MissingBytes),
  553.               G.zipfn, (long)(-G.extra_bytes)));
  554.             error_in_archive = PK_ERR;
  555.         } else if (G.extra_bytes > 0) {
  556.             if ((G.ecrec.offset_start_central_directory == 0) &&
  557.                 (G.ecrec.size_central_directory != 0))   /* zip 1.5 -go bug */
  558.             {
  559.                 Info(slide, 0x401, ((char *)slide,
  560.                   LoadFarString(NullCentDirOffset), G.zipfn));
  561.                 G.ecrec.offset_start_central_directory = G.extra_bytes;
  562.                 G.extra_bytes = 0;
  563.                 error_in_archive = PK_ERR;
  564.             }
  565. #ifndef SFX
  566.             else {
  567.                 Info(slide, 0x401, ((char *)slide,
  568.                   LoadFarString(ExtraBytesAtStart), G.zipfn,
  569.                   (long)G.extra_bytes, (G.extra_bytes == 1)? "":"s"));
  570.                 error_in_archive = PK_WARN;
  571.             }
  572. #endif /* !SFX */
  573.         }
  574.  
  575.     /*-----------------------------------------------------------------------
  576.         Check for empty zipfile and exit now if so.
  577.       -----------------------------------------------------------------------*/
  578.  
  579.         if (G.expect_ecrec_offset==0L && G.ecrec.size_central_directory==0) {
  580.             if (G.zipinfo_mode)
  581.                 Info(slide, 0, ((char *)slide, "%sEmpty zipfile.\n",
  582.                   G.lflag>9? "\n  " : ""));
  583.             else
  584.                 Info(slide, 0x401, ((char *)slide, LoadFarString(ZipfileEmpty),
  585.                                     G.zipfn));
  586.             close(G.zipfd);
  587.             return (error_in_archive > PK_WARN)? error_in_archive : PK_WARN;
  588.         }
  589.  
  590.     /*-----------------------------------------------------------------------
  591.         Compensate for missing or extra bytes, and seek to where the start
  592.         of central directory should be.  If header not found, uncompensate
  593.         and try again (necessary for at least some Atari archives created
  594.         with STZip, as well as archives created by J.H. Holm's ZIPSPLIT 1.1).
  595.       -----------------------------------------------------------------------*/
  596.  
  597.         ZLSEEK( G.ecrec.offset_start_central_directory )
  598. #ifdef OLD_SEEK_TEST
  599.         if (readbuf(G.sig, 4) == 0) {
  600.             close(G.zipfd);
  601.             return PK_ERR;  /* file may be locked, or possibly disk error(?) */
  602.         }
  603.         if (strncmp(G.sig, G.central_hdr_sig, 4))
  604. #else
  605.         if ((readbuf(__G__ G.sig, 4) == 0) || strncmp(G.sig,
  606.             G.central_hdr_sig, 4))
  607. #endif
  608.         {
  609.             long tmp = G.extra_bytes;
  610.  
  611.             G.extra_bytes = 0;
  612.             ZLSEEK( G.ecrec.offset_start_central_directory )
  613.             if ((readbuf(__G__ G.sig, 4) == 0) ||
  614.                 strncmp(G.sig, G.central_hdr_sig, 4))
  615.             {
  616.                 Info(slide, 0x401, ((char *)slide,
  617.                   LoadFarString(CentDirStartNotFound), G.zipfn,
  618.                   LoadFarStringSmall(ReportMsg)));
  619.                 close(G.zipfd);
  620.                 return PK_BADERR;
  621.             }
  622.             Info(slide, 0x401, ((char *)slide, LoadFarString(CentDirTooLong),
  623.               G.zipfn, -tmp));
  624.             error_in_archive = PK_ERR;
  625.         }
  626.  
  627.     /*-----------------------------------------------------------------------
  628.         Seek to the start of the central directory one last time, since we
  629.         have just read the first entry's signature bytes; then list, extract
  630.         or test member files as instructed, and close the zipfile.
  631.       -----------------------------------------------------------------------*/
  632.  
  633.         Trace((stderr, "about to extract/list files (error = %d)\n",
  634.           error_in_archive));
  635.  
  636.         ZLSEEK( G.ecrec.offset_start_central_directory )
  637.  
  638. #ifndef NO_ZIPINFO
  639.         if (G.zipinfo_mode) {
  640.             error = zipinfo(__G);                     /* ZIPINFO 'EM */
  641.             if (G.lflag > 9)
  642.                 (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);
  643.         } else
  644. #endif
  645. #ifndef SFX
  646. #ifdef TIMESTAMP
  647.             if (G.T_flag)
  648.                 error = time_stamp(__G);              /* TIME-STAMP 'EM */
  649.             else
  650. #endif
  651.             if (G.vflag && !G.tflag && !G.cflag)
  652.                 error = list_files(__G);              /* LIST 'EM */
  653.             else
  654. #endif
  655.                 error = extract_or_test_files(__G);   /* EXTRACT OR TEST 'EM */
  656.  
  657.         Trace((stderr, "done with extract/list files (error = %d)\n", error));
  658.  
  659.         if (error > error_in_archive)   /* don't overwrite stronger error */
  660.             error_in_archive = error;   /*  with (for example) a warning */
  661. #ifndef SFX
  662.     } /* end if (!too_weird_to_continue) */
  663. #endif
  664.  
  665.     close(G.zipfd);
  666.     return error_in_archive;
  667.  
  668. } /* end function do_seekable() */
  669.  
  670.  
  671.  
  672.  
  673.  
  674. /*************************/
  675. /* Function find_ecrec() */
  676. /*************************/
  677.  
  678. static int find_ecrec(__G__ searchlen)          /* return PK-class error */
  679.     long searchlen;
  680.      __GDEF
  681. {
  682.     int i, numblks, found=FALSE;
  683.     LONGINT tail_len;
  684.     ec_byte_rec byterec;
  685.  
  686.  
  687. /*---------------------------------------------------------------------------
  688.     Treat case of short zipfile separately.
  689.   ---------------------------------------------------------------------------*/
  690.  
  691.     if (G.ziplen <= INBUFSIZ) {
  692.         lseek(G.zipfd, 0L, SEEK_SET);
  693.         if ((G.incnt = read(G.zipfd,(char *)G.inbuf,(unsigned int)G.ziplen))
  694.             == (int)G.ziplen)
  695.  
  696.             /* 'P' must be at least 22 bytes from end of zipfile */
  697.             for (G.inptr = G.inbuf+(int)G.ziplen-22;  G.inptr >= G.inbuf;
  698.                  --G.inptr)
  699.                 if ((native(*G.inptr) == 'P')  &&
  700.                      !strncmp((char *)G.inptr, G.end_central_sig, 4)) {
  701.                     G.incnt -= (int)(G.inptr - G.inbuf);
  702.                     found = TRUE;
  703.                     break;
  704.                 }
  705.  
  706. /*---------------------------------------------------------------------------
  707.     Zipfile is longer than INBUFSIZ:  may need to loop.  Start with short
  708.     block at end of zipfile (if not TOO short).
  709.   ---------------------------------------------------------------------------*/
  710.  
  711.     } else {
  712.         if ((tail_len = G.ziplen % INBUFSIZ) > ECREC_SIZE) {
  713. #ifdef USE_STRM_INPUT
  714.             fseek((FILE *)G.zipfd, G.ziplen-tail_len, SEEK_SET);
  715.             G.cur_zipfile_bufstart = ftell((FILE *)G.zipfd);
  716. #else /* !USE_STRM_INPUT */
  717.             G.cur_zipfile_bufstart = lseek(G.zipfd, G.ziplen-tail_len,
  718.               SEEK_SET);
  719. #endif /* ?USE_STRM_INPUT */
  720.             if ((G.incnt = read(G.zipfd, (char *)G.inbuf,
  721.                 (unsigned int)tail_len)) != (int)tail_len)
  722.                 goto fail;      /* it's expedient... */
  723.  
  724.             /* 'P' must be at least 22 bytes from end of zipfile */
  725.             for (G.inptr = G.inbuf+(int)tail_len-22;  G.inptr >= G.inbuf;
  726.                  --G.inptr)
  727.                 if ((native(*G.inptr) == 'P')  &&
  728.                      !strncmp((char *)G.inptr, G.end_central_sig, 4)) {
  729.                     G.incnt -= (int)(G.inptr - G.inbuf);
  730.                     found = TRUE;
  731.                     break;
  732.                 }
  733.             /* sig may span block boundary: */
  734.             strncpy((char *)G.hold, (char *)G.inbuf, 3);
  735.         } else
  736.             G.cur_zipfile_bufstart = G.ziplen - tail_len;
  737.  
  738.     /*-----------------------------------------------------------------------
  739.         Loop through blocks of zipfile data, starting at the end and going
  740.         toward the beginning.  In general, need not check whole zipfile for
  741.         signature, but may want to do so if testing.
  742.       -----------------------------------------------------------------------*/
  743.  
  744.         numblks = (int)((searchlen - tail_len + (INBUFSIZ-1)) / INBUFSIZ);
  745.         /*               ==amount=   ==done==   ==rounding==    =blksiz=  */
  746.  
  747.         for (i = 1;  !found && (i <= numblks);  ++i) {
  748.             G.cur_zipfile_bufstart -= INBUFSIZ;
  749.             lseek(G.zipfd, G.cur_zipfile_bufstart, SEEK_SET);
  750.             if ((G.incnt = read(G.zipfd,(char *)G.inbuf,INBUFSIZ))
  751.                 != INBUFSIZ)
  752.                 break;          /* fall through and fail */
  753.  
  754.             for (G.inptr = G.inbuf+INBUFSIZ-1;  G.inptr >= G.inbuf;
  755.                  --G.inptr)
  756.                 if ((native(*G.inptr) == 'P')  &&
  757.                      !strncmp((char *)G.inptr, G.end_central_sig, 4)) {
  758.                     G.incnt -= (int)(G.inptr - G.inbuf);
  759.                     found = TRUE;
  760.                     break;
  761.                 }
  762.             /* sig may span block boundary: */
  763.             strncpy((char *)G.hold, (char *)G.inbuf, 3);
  764.         }
  765.     } /* end if (ziplen > INBUFSIZ) */
  766.  
  767. /*---------------------------------------------------------------------------
  768.     Searched through whole region where signature should be without finding
  769.     it.  Print informational message and die a horrible death.
  770.   ---------------------------------------------------------------------------*/
  771.  
  772. fail:
  773.     if (!found) {
  774. #ifdef MSWIN
  775.         MessageBeep(1);
  776. #endif
  777.         if (G.qflag || G.zipinfo_mode)
  778.             Info(slide, 0x401, ((char *)slide, "[%s]\n", G.zipfn));
  779.         Info(slide, 0x401, ((char *)slide,
  780.           LoadFarString(CentDirEndSigNotFound)));
  781.         return PK_ERR;   /* failed */
  782.     }
  783.  
  784. /*---------------------------------------------------------------------------
  785.     Found the signature, so get the end-central data before returning.  Do
  786.     any necessary machine-type conversions (byte ordering, structure padding
  787.     compensation) by reading data into character array and copying to struct.
  788.   ---------------------------------------------------------------------------*/
  789.  
  790.     G.real_ecrec_offset = G.cur_zipfile_bufstart + (G.inptr-G.inbuf);
  791. #ifdef TEST
  792.     printf("\n  found end-of-central-dir signature at offset %ld (%.8lXh)\n",
  793.       G.real_ecrec_offset, G.real_ecrec_offset);
  794.     printf("    from beginning of file; offset %d (%.4Xh) within block\n",
  795.       G.inptr-G.inbuf, G.inptr-G.inbuf);
  796. #endif
  797.  
  798.     if (readbuf(__G__ (char *)byterec, ECREC_SIZE+4) == 0)
  799.         return PK_EOF;
  800.  
  801.     G.ecrec.number_this_disk =
  802.       makeword(&byterec[NUMBER_THIS_DISK]);
  803.     G.ecrec.num_disk_start_cdir =
  804.       makeword(&byterec[NUM_DISK_WITH_START_CENTRAL_DIR]);
  805.     G.ecrec.num_entries_centrl_dir_ths_disk =
  806.       makeword(&byterec[NUM_ENTRIES_CENTRL_DIR_THS_DISK]);
  807.     G.ecrec.total_entries_central_dir =
  808.       makeword(&byterec[TOTAL_ENTRIES_CENTRAL_DIR]);
  809.     G.ecrec.size_central_directory =
  810.       makelong(&byterec[SIZE_CENTRAL_DIRECTORY]);
  811.     G.ecrec.offset_start_central_directory =
  812.       makelong(&byterec[OFFSET_START_CENTRAL_DIRECTORY]);
  813.     G.ecrec.zipfile_comment_length =
  814.       makeword(&byterec[ZIPFILE_COMMENT_LENGTH]);
  815.  
  816.     G.expect_ecrec_offset = G.ecrec.offset_start_central_directory +
  817.                           G.ecrec.size_central_directory;
  818.     return PK_COOL;
  819.  
  820. } /* end function find_ecrec() */
  821.  
  822.  
  823.  
  824.  
  825.  
  826. /*****************************/
  827. /* Function uz_end_central() */
  828. /*****************************/
  829.  
  830. int uz_end_central(__G)    /* return PK-type error code */
  831.      __GDEF
  832. {
  833.     int error = PK_COOL;
  834.  
  835.  
  836. /*---------------------------------------------------------------------------
  837.     Get the zipfile comment (up to 64KB long), if any, and print it out.
  838.     Then position the file pointer to the beginning of the central directory
  839.     and fill buffer.
  840.   ---------------------------------------------------------------------------*/
  841.  
  842. #ifdef MSWIN
  843.     cchComment = G.ecrec.zipfile_comment_length; /* save for comment button */
  844.     if (G.ecrec.zipfile_comment_length && (G.zflag > 0))
  845. #else
  846.     if (G.ecrec.zipfile_comment_length && (G.zflag > 0 ||
  847.         (G.zflag == 0 &&
  848. #ifdef TIMESTAMP
  849.                          !G.T_flag &&
  850. #endif
  851.                                       !G.qflag)))
  852. #endif /* ?MSWIN */
  853.     {
  854.         if (do_string(__G__ G.ecrec.zipfile_comment_length,DISPLAY)) {
  855.             Info(slide, 0x401, ((char *)slide,
  856.               LoadFarString(ZipfileCommTrunc1)));
  857.             error = PK_WARN;
  858.         }
  859.     }
  860.     return error;
  861.  
  862. } /* end function uz_end_central() */
  863.  
  864.  
  865.  
  866.  
  867.  
  868. /************************************/
  869. /* Function process_cdir_file_hdr() */
  870. /************************************/
  871.  
  872. int process_cdir_file_hdr(__G)    /* return PK-type error code */
  873.      __GDEF
  874. {
  875.     int error;
  876.  
  877.  
  878. /*---------------------------------------------------------------------------
  879.     Get central directory info, save host and method numbers, and set flag
  880.     for lowercase conversion of filename, depending on the OS from which the
  881.     file is coming.
  882.   ---------------------------------------------------------------------------*/
  883.  
  884.     if ((error = get_cdir_ent(__G)) != 0)
  885.         return error;
  886.  
  887.     G.pInfo->hostnum = MIN(G.crec.version_made_by[1], NUM_HOSTS);
  888. /*  extnum = MIN(crec.version_needed_to_extract[1], NUM_HOSTS); */
  889.  
  890.     G.pInfo->lcflag = 0;
  891.     if (G.L_flag)             /* user specified case-conversion */
  892.         switch (G.pInfo->hostnum) {
  893.             case FS_FAT_:     /* PKZIP and zip -k store in uppercase */
  894.             case CPM_:        /* like MS-DOS, right? */
  895.             case VM_CMS_:     /* all caps? */
  896.             case MVS_:        /* all caps? */
  897.             case TOPS20_:
  898.             case VMS_:        /* our Zip uses lowercase, but ASi's doesn't */
  899.         /*  case Z_SYSTEM_:   ? */
  900.         /*  case QDOS_:       ? */
  901.                 G.pInfo->lcflag = 1;   /* convert filename to lowercase */
  902.                 break;
  903.  
  904.             default:     /* AMIGA_, FS_HPFS_, FS_NTFS_, MAC_, UNIX_, ATARI_, */
  905.                 break;   /*  FS_VFAT_, BEBOX_ (Z_SYSTEM_):  no conversion */
  906.         }
  907.  
  908.     /* do Amigas (AMIGA_) also have volume labels? */
  909.     if (IS_VOLID(G.crec.external_file_attributes) &&
  910.         (G.pInfo->hostnum == FS_FAT_ || G.pInfo->hostnum == FS_HPFS_ ||
  911.          G.pInfo->hostnum == FS_NTFS_ || G.pInfo->hostnum == ATARI_))
  912.     {
  913.         G.pInfo->vollabel = TRUE;
  914.         G.pInfo->lcflag = 0;        /* preserve case of volume labels */
  915.     } else
  916.         G.pInfo->vollabel = FALSE;
  917.  
  918.     return PK_COOL;
  919.  
  920. } /* end function process_cdir_file_hdr() */
  921.  
  922.  
  923.  
  924.  
  925.  
  926. /***************************/
  927. /* Function get_cdir_ent() */
  928. /***************************/
  929.  
  930. int get_cdir_ent(__G)   /* return PK-type error code */
  931.      __GDEF
  932. {
  933.     cdir_byte_hdr byterec;
  934.  
  935.  
  936. /*---------------------------------------------------------------------------
  937.     Read the next central directory entry and do any necessary machine-type
  938.     conversions (byte ordering, structure padding compensation--do so by
  939.     copying the data from the array into which it was read (byterec) to the
  940.     usable struct (crec)).
  941.   ---------------------------------------------------------------------------*/
  942.  
  943.     if (readbuf(__G__ (char *)byterec, CREC_SIZE) == 0)
  944.         return PK_EOF;
  945.  
  946.     G.crec.version_made_by[0] = byterec[C_VERSION_MADE_BY_0];
  947.     G.crec.version_made_by[1] = byterec[C_VERSION_MADE_BY_1];
  948.     G.crec.version_needed_to_extract[0] =
  949.       byterec[C_VERSION_NEEDED_TO_EXTRACT_0];
  950.     G.crec.version_needed_to_extract[1] =
  951.       byterec[C_VERSION_NEEDED_TO_EXTRACT_1];
  952.  
  953.     G.crec.general_purpose_bit_flag =
  954.       makeword(&byterec[C_GENERAL_PURPOSE_BIT_FLAG]);
  955.     G.crec.compression_method =
  956.       makeword(&byterec[C_COMPRESSION_METHOD]);
  957.     G.crec.last_mod_file_time =
  958.       makeword(&byterec[C_LAST_MOD_FILE_TIME]);
  959.     G.crec.last_mod_file_date =
  960.       makeword(&byterec[C_LAST_MOD_FILE_DATE]);
  961.     G.crec.crc32 =
  962.       makelong(&byterec[C_CRC32]);
  963.     G.crec.csize =
  964.       makelong(&byterec[C_COMPRESSED_SIZE]);
  965.     G.crec.ucsize =
  966.       makelong(&byterec[C_UNCOMPRESSED_SIZE]);
  967.     G.crec.filename_length =
  968.       makeword(&byterec[C_FILENAME_LENGTH]);
  969.     G.crec.extra_field_length =
  970.       makeword(&byterec[C_EXTRA_FIELD_LENGTH]);
  971.     G.crec.file_comment_length =
  972.       makeword(&byterec[C_FILE_COMMENT_LENGTH]);
  973.     G.crec.disk_number_start =
  974.       makeword(&byterec[C_DISK_NUMBER_START]);
  975.     G.crec.internal_file_attributes =
  976.       makeword(&byterec[C_INTERNAL_FILE_ATTRIBUTES]);
  977.     G.crec.external_file_attributes =
  978.       makelong(&byterec[C_EXTERNAL_FILE_ATTRIBUTES]);  /* LONG, not word! */
  979.     G.crec.relative_offset_local_header =
  980.       makelong(&byterec[C_RELATIVE_OFFSET_LOCAL_HEADER]);
  981.  
  982.     return PK_COOL;
  983.  
  984. } /* end function get_cdir_ent() */
  985.  
  986.  
  987.  
  988.  
  989.  
  990. /*************************************/
  991. /* Function process_local_file_hdr() */
  992. /*************************************/
  993.  
  994. int process_local_file_hdr(__G)    /* return PK-type error code */
  995.      __GDEF
  996. {
  997.     local_byte_hdr byterec;
  998.  
  999.  
  1000. /*---------------------------------------------------------------------------
  1001.     Read the next local file header and do any necessary machine-type con-
  1002.     versions (byte ordering, structure padding compensation--do so by copy-
  1003.     ing the data from the array into which it was read (byterec) to the
  1004.     usable struct (lrec)).
  1005.   ---------------------------------------------------------------------------*/
  1006.  
  1007.     if (readbuf(__G__ (char *)byterec, LREC_SIZE) == 0)
  1008.         return PK_EOF;
  1009.  
  1010.     G.lrec.version_needed_to_extract[0] =
  1011.       byterec[L_VERSION_NEEDED_TO_EXTRACT_0];
  1012.     G.lrec.version_needed_to_extract[1] =
  1013.       byterec[L_VERSION_NEEDED_TO_EXTRACT_1];
  1014.  
  1015.     G.lrec.general_purpose_bit_flag =
  1016.       makeword(&byterec[L_GENERAL_PURPOSE_BIT_FLAG]);
  1017.     G.lrec.compression_method = makeword(&byterec[L_COMPRESSION_METHOD]);
  1018.     G.lrec.last_mod_file_time = makeword(&byterec[L_LAST_MOD_FILE_TIME]);
  1019.     G.lrec.last_mod_file_date = makeword(&byterec[L_LAST_MOD_FILE_DATE]);
  1020.     G.lrec.crc32 = makelong(&byterec[L_CRC32]);
  1021.     G.lrec.csize = makelong(&byterec[L_COMPRESSED_SIZE]);
  1022.     G.lrec.ucsize = makelong(&byterec[L_UNCOMPRESSED_SIZE]);
  1023.     G.lrec.filename_length = makeword(&byterec[L_FILENAME_LENGTH]);
  1024.     G.lrec.extra_field_length = makeword(&byterec[L_EXTRA_FIELD_LENGTH]);
  1025.  
  1026.     G.csize = (long) G.lrec.csize;
  1027.     G.ucsize = (long) G.lrec.ucsize;
  1028.  
  1029.     if ((G.lrec.general_purpose_bit_flag & 8) != 0) {
  1030.         /* can't trust local header, use central directory: */
  1031.         G.lrec.crc32 = G.pInfo->crc;
  1032.         G.csize = (long)(G.lrec.csize = G.pInfo->compr_size);
  1033.     }
  1034.  
  1035.     return PK_COOL;
  1036.  
  1037. } /* end function process_local_file_hdr() */
  1038.  
  1039.  
  1040. #ifdef USE_EF_UX_TIME
  1041.  
  1042. /*************************************/
  1043. /* Function ef_scan_for_izux() */
  1044. /*************************************/
  1045.  
  1046. unsigned ef_scan_for_izux(ef_buf, ef_len, z_utim, z_uidgid)
  1047.     uch *ef_buf;                /* buffer containing extra field */
  1048.     unsigned ef_len;            /* total length of extra field */
  1049.     ztimbuf *z_utim;            /* return storage: atime and mtime */
  1050.     ush *z_uidgid;              /* return storage: uid and gid */
  1051. /* This function scans the extra field for a IZUNIX block containing
  1052.  * Unix style time_t (GMT) values for the entry's access and modification
  1053.  * time.  If a valid block is found, both time stamps are copied to the
  1054.  * ztimebuf structure (provided the z_utim pointer is not NULL).
  1055.  * If the IZUNIX block contains UID/GID fields and the z_uidgid array
  1056.  * pointer is valid (!= NULL), the owner info is transfered as well.
  1057.  * The return value is the size of the IZUNIX block found, or 0 in case
  1058.  * of failure.
  1059.  */
  1060. {
  1061.   unsigned r = 0;
  1062.   unsigned eb_id;
  1063.   unsigned eb_len;
  1064.  
  1065.   if (ef_len == 0 || ef_buf == NULL)
  1066.     return 0;
  1067.  
  1068.   TTrace((stderr,"\nef_scan_ux_: scanning extra field of length %u\n",
  1069.           ef_len));
  1070.   while (ef_len >= EB_HEADSIZE) {
  1071.     eb_id = makeword(EB_ID + ef_buf);
  1072.     eb_len = makeword(EB_LEN + ef_buf);
  1073.  
  1074.     if (eb_len > (ef_len - EB_HEADSIZE)) {
  1075.       /* Discovered some extra field inconsistency! */
  1076.       TTrace((stderr,"ef_scan_for_izux: block length %u > rest ef_size %u\n",
  1077.               eb_len, ef_len - EB_HEADSIZE));
  1078.       break;
  1079.     }
  1080.  
  1081.     if (eb_id == EF_IZUNIX && eb_len >= EB_UX_MINLEN) {
  1082.        TTrace((stderr,"ef_scan_ux_time: Found IZUNIX extra field\n"));
  1083.        if (z_utim != NULL) {
  1084.          z_utim->actime  = makelong((EB_HEADSIZE+EB_UX_ATIME) + ef_buf);
  1085.          z_utim->modtime = makelong((EB_HEADSIZE+EB_UX_MTIME) + ef_buf);
  1086.          TTrace((stderr,"  Unix EF access time = %ld\n",z_utim->actime));
  1087.          TTrace((stderr,"  Unix EF modif. time = %ld\n",z_utim->modtime));
  1088.        }
  1089.        if (eb_len >= EB_UX_FULLSIZE && z_uidgid != NULL) {
  1090.          z_uidgid[0] = makeword((EB_HEADSIZE+EB_UX_UID) + ef_buf);
  1091.          z_uidgid[1] = makeword((EB_HEADSIZE+EB_UX_GID) + ef_buf);
  1092.        }
  1093.        r = eb_len;              /* signal success */
  1094.        break;
  1095.     }
  1096.     /* Skip this extra field block */
  1097.     ef_buf += (eb_len + EB_HEADSIZE);
  1098.     ef_len -= (eb_len + EB_HEADSIZE);
  1099.   }
  1100.  
  1101.   return r;
  1102. }
  1103.  
  1104. #endif /* USE_EF_UX_TIME */
  1105.