home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip531.zip / atari / atari.c next >
C/C++ Source or Header  |  1997-02-17  |  27KB  |  723 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   atari.c
  4.  
  5.   Atari-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   Contains:  readdir()
  8.              do_wild()           <-- generic enough to put in fileio.c?
  9.              mapattr()
  10.              mapname()
  11.              checkdir()
  12.              mkdir()
  13.              close_outfile()
  14.              version()
  15.  
  16.   Due to the amazing MiNT library being very, very close to BSD unix's
  17.   library, I'm using the unix.c as a base for this.  Note:  If you're not
  18.   going to compile this with the MiNT libraries (for GNU C, Turbo C, Pure C,
  19.   Lattice C, or Heat & Serve C), you're going to be in for some nasty work.
  20.   Most of the modifications in this file were made by Chris Herborth
  21.   (cherborth@semprini.waterloo-rdp.on.ca) and /should/ be marked with [cjh].
  22.  
  23.   ---------------------------------------------------------------------------*/
  24.  
  25.  
  26. #define UNZIP_INTERNAL
  27. #include "unzip.h"
  28. #include <dirent.h>            /* MiNTlibs has dirent [cjh] */
  29.  
  30. static int created_dir;        /* used in mapname(), checkdir() */
  31. static int renamed_fullpath;   /* ditto */
  32.  
  33.  
  34. #ifndef SFX
  35.  
  36. /**********************/
  37. /* Function do_wild() */   /* for porting:  dir separator; match(ignore_case) */
  38. /**********************/
  39.  
  40. char *do_wild(__G__ wildspec)
  41.     __GDEF
  42.     char *wildspec;         /* only used first time on a given dir */
  43. {
  44.     static DIR *dir = (DIR *)NULL;
  45.     static char *dirname, *wildname, matchname[FILNAMSIZ];
  46.     static int firstcall=TRUE, have_dirname, dirnamelen;
  47.     struct dirent *file;
  48.  
  49.  
  50.     /* Even when we're just returning wildspec, we *always* do so in
  51.      * matchname[]--calling routine is allowed to append four characters
  52.      * to the returned string, and wildspec may be a pointer to argv[].
  53.      */
  54.     if (firstcall) {        /* first call:  must initialize everything */
  55.         firstcall = FALSE;
  56.  
  57.         /* break the wildspec into a directory part and a wildcard filename */
  58.         if ((wildname = strrchr(wildspec, '/')) == (char *)NULL) {
  59.             dirname = ".";
  60.             dirnamelen = 1;
  61.             have_dirname = FALSE;
  62.             wildname = wildspec;
  63.         } else {
  64.             ++wildname;     /* point at character after '/' */
  65.             dirnamelen = wildname - wildspec;
  66.             if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
  67.                 Info(slide, 0x201, ((char *)slide,
  68.                   "warning:  can't allocate wildcard buffers\n"));
  69.                 strcpy(matchname, wildspec);
  70.                 return matchname;   /* but maybe filespec was not a wildcard */
  71.             }
  72.             strncpy(dirname, wildspec, dirnamelen);
  73.             dirname[dirnamelen] = '\0';   /* terminate for strcpy below */
  74.             have_dirname = TRUE;
  75.         }
  76.  
  77.         if ((dir = opendir(dirname)) != (DIR *)NULL) {
  78.             while ((file = readdir(dir)) != (struct dirent *)NULL) {
  79.                 if (file->d_name[0] == '.' && wildname[0] != '.')
  80.                     continue;  /* Unix:  '*' and '?' do not match leading dot */
  81.                     /* Need something here for TOS filesystem? [cjh] */
  82.                 if (match(file->d_name, wildname, 0)) {  /* 0 == case sens. */
  83.                     if (have_dirname) {
  84.                         strcpy(matchname, dirname);
  85.                         strcpy(matchname+dirnamelen, file->d_name);
  86.                     } else
  87.                         strcpy(matchname, file->d_name);
  88.                     return matchname;
  89.                 }
  90.             }
  91.             /* if we get to here directory is exhausted, so close it */
  92.             closedir(dir);
  93.             dir = (DIR *)NULL;
  94.         }
  95.  
  96.         /* return the raw wildspec in case that works (e.g., directory not
  97.          * searchable, but filespec was not wild and file is readable) */
  98.         strcpy(matchname, wildspec);
  99.         return matchname;
  100.     }
  101.  
  102.     /* last time through, might have failed opendir but returned raw wildspec */
  103.     if (dir == (DIR *)NULL) {
  104.         firstcall = TRUE;  /* nothing left to try--reset for new wildspec */
  105.         if (have_dirname)
  106.             free(dirname);
  107.         return (char *)NULL;
  108.     }
  109.  
  110.     /* If we've gotten this far, we've read and matched at least one entry
  111.      * successfully (in a previous call), so dirname has been copied into
  112.      * matchname already.
  113.      */
  114.     while ((file = readdir(dir)) != (struct dirent *)NULL)
  115.         /* May need special TOS handling here. [cjh] */
  116.         if (match(file->d_name, wildname, 0)) {   /* 0 == don't ignore case */
  117.             if (have_dirname) {
  118.                 /* strcpy(matchname, dirname); */
  119.                 strcpy(matchname+dirnamelen, file->d_name);
  120.             } else
  121.                 strcpy(matchname, file->d_name);
  122.             return matchname;
  123.         }
  124.  
  125.     closedir(dir);     /* have read at least one dir entry; nothing left */
  126.     dir = (DIR *)NULL;
  127.     firstcall = TRUE;  /* reset for new wildspec */
  128.     if (have_dirname)
  129.         free(dirname);
  130.     return (char *)NULL;
  131.  
  132. } /* end function do_wild() */
  133.  
  134. #endif /* !SFX */
  135.  
  136.  
  137.  
  138.  
  139.  
  140. /**********************/
  141. /* Function mapattr() */
  142. /**********************/
  143.  
  144. int mapattr(__G)
  145.     __GDEF
  146. {
  147.     ulg tmp = G.crec.external_file_attributes;
  148.  
  149.     switch (G.pInfo->hostnum) {
  150.         case UNIX_:
  151.         case ATARI_:
  152.             /* minix filesystem under MiNT on Atari [cjh] */
  153.         case VMS_:
  154.             G.pInfo->file_attr = (unsigned)(tmp >> 16);
  155.             return 0;
  156.         case AMIGA_:
  157.             tmp = (unsigned)(tmp>>17 & 7);   /* Amiga RWE bits */
  158.             G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  159.             break;
  160.         /* all remaining cases:  expand MSDOS read-only bit into write perms */
  161.         case FS_FAT_:
  162.         case FS_HPFS_:
  163.         case FS_NTFS_:
  164.         case MAC_:
  165.         case TOPS20_:
  166.         default:
  167.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  168.             G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  169.             break;
  170.     } /* end switch (host-OS-created-by) */
  171.  
  172.     /* for originating systems with no concept of "group," "other," "system": */
  173.     umask( (int)(tmp=umask(0)) );    /* apply mask to expanded r/w(/x) perms */
  174.     G.pInfo->file_attr &= ~tmp;
  175.  
  176.     return 0;
  177.  
  178. } /* end function mapattr() */
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /************************/
  185. /*  Function mapname()  */
  186. /************************/
  187.                              /* return 0 if no error, 1 if caution (filename */
  188. int mapname(__G__ renamed)   /*  truncated), 2 if warning (skip file because */
  189.     __GDEF                   /*  dir doesn't exist), 3 if error (skip file), */
  190.     int renamed;             /*  or 10 if out of memory (skip file) */
  191. {                            /*  [also IZ_VOL_LABEL, IZ_CREATED_DIR] */
  192.     char pathcomp[FILNAMSIZ];    /* path-component buffer */
  193.     char *pp, *cp=(char *)NULL;  /* character pointers */
  194.     char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  195.     int quote = FALSE;           /* flags */
  196.     int error = 0;
  197.     register unsigned workch;    /* hold the character being tested */
  198.  
  199.  
  200. /*---------------------------------------------------------------------------
  201.     Initialize various pointers and counters and stuff.
  202.   ---------------------------------------------------------------------------*/
  203.  
  204.     if (G.pInfo->vollabel)
  205.         return IZ_VOL_LABEL;    /* can't set disk volume labels in Unix */
  206.  
  207.     /* can create path as long as not just freshening, or if user told us */
  208.     G.create_dirs = (!G.fflag || renamed);
  209.  
  210.     created_dir = FALSE;        /* not yet */
  211.  
  212.     /* user gave full pathname:  don't prepend rootpath */
  213.     renamed_fullpath = (renamed && (*G.filename == '/'));
  214.  
  215.     if (checkdir(__G__ (char *)NULL, INIT) == 10)
  216.         return 10;              /* initialize path buffer, unless no memory */
  217.  
  218.     *pathcomp = '\0';           /* initialize translation buffer */
  219.     pp = pathcomp;              /* point to translation buffer */
  220.     if (G.jflag)                /* junking directories */
  221.         cp = (char *)strrchr(G.filename, '/');
  222.     if (cp == (char *)NULL)     /* no '/' or not junking dirs */
  223.         cp = G.filename;        /* point to internal zipfile-member pathname */
  224.     else
  225.         ++cp;                   /* point to start of last component of path */
  226.  
  227. /*---------------------------------------------------------------------------
  228.     Begin main loop through characters in filename.
  229.   ---------------------------------------------------------------------------*/
  230.  
  231.     while ((workch = (uch)*cp++) != 0) {
  232.  
  233.         if (quote) {                 /* if character quoted, */
  234.             *pp++ = (char)workch;    /*  include it literally */
  235.             quote = FALSE;
  236.         } else
  237.             switch (workch) {
  238.             case '/':             /* can assume -j flag not given */
  239.                 *pp = '\0';
  240.                 if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1)
  241.                     return error;
  242.                 pp = pathcomp;    /* reset conversion buffer for next piece */
  243.                 lastsemi = (char *)NULL; /* leave directory semi-colons alone */
  244.                 break;
  245.  
  246.             case ';':             /* VMS version (or DEC-20 attrib?) */
  247.                 lastsemi = pp;         /* keep for now; remove VMS ";##" */
  248.                 *pp++ = (char)workch;  /*  later, if requested */
  249.                 break;
  250.  
  251.             case '\026':          /* control-V quote for special chars */
  252.                 quote = TRUE;     /* set flag for next character */
  253.                 break;
  254.  
  255. #ifdef MTS
  256.             case ' ':             /* change spaces to underscore under */
  257.                 *pp++ = '_';      /*  MTS; leave as spaces under Unix */
  258.                 break;
  259. #endif
  260.  
  261.             default:
  262.                 /* allow European characters in filenames: */
  263.                 if (isprint(workch) || (128 <= workch && workch <= 254))
  264.                     *pp++ = (char)workch;
  265.             } /* end switch */
  266.  
  267.     } /* end while loop */
  268.  
  269.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  270.  
  271.     /* if not saving them, remove VMS version numbers (appended ";###") */
  272.     if (!G.V_flag && lastsemi) {
  273.         pp = lastsemi + 1;
  274.         while (isdigit((uch)(*pp)))
  275.             ++pp;
  276.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  277.             *lastsemi = '\0';
  278.     }
  279.  
  280. /*---------------------------------------------------------------------------
  281.     Report if directory was created (and no file to create:  filename ended
  282.     in '/'), check name to be sure it exists, and combine path and name be-
  283.     fore exiting.
  284.   ---------------------------------------------------------------------------*/
  285.  
  286.     if (G.filename[strlen(G.filename) - 1] == '/') {
  287.         checkdir(__G__ G.filename, GETPATH);
  288.         if (created_dir) {
  289.             if (QCOND2) {
  290.                 Info(slide, 0, ((char *)slide, "   creating: %s\n",
  291.                   G.filename));
  292.             }
  293.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  294.         }
  295.         return 2;   /* dir existed already; don't look for data to extract */
  296.     }
  297.  
  298.     if (*pathcomp == '\0') {
  299.         Info(slide, 1, ((char *)slide, "mapname:  conversion of %s failed\n",
  300.           G.filename));
  301.         return 3;
  302.     }
  303.  
  304.     checkdir(__G__ pathcomp, APPEND_NAME);  /* returns 1 if truncated: care? */
  305.     checkdir(__G__ G.filename, GETPATH);
  306.  
  307.     return error;
  308.  
  309. } /* end function mapname() */
  310.  
  311.  
  312.  
  313.  
  314. #if 0  /*========== NOTES ==========*/
  315.  
  316.   extract-to dir:      a:path/
  317.   buildpath:           path1/path2/ ...   (NULL-terminated)
  318.   pathcomp:                filename
  319.  
  320.   mapname():
  321.     loop over chars in zipfile member name
  322.       checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
  323.         (d:/tmp/unzip/)                    (disk:[tmp.unzip.)
  324.         (d:/tmp/unzip/jj/)                 (disk:[tmp.unzip.jj.)
  325.         (d:/tmp/unzip/jj/temp/)            (disk:[tmp.unzip.jj.temp.)
  326.     finally add filename itself and check for existence? (could use with rename)
  327.         (d:/tmp/unzip/jj/temp/msg.outdir)  (disk:[tmp.unzip.jj.temp]msg.outdir)
  328.     checkdir(name, GETPATH)     -->  copy path to name and free space
  329.  
  330. #endif /* 0 */
  331.  
  332.  
  333.  
  334.  
  335. /***********************/
  336. /* Function checkdir() */
  337. /***********************/
  338.  
  339. int checkdir(__G__ pathcomp, flag)
  340.     __GDEF
  341.     char *pathcomp;
  342.     int flag;
  343. /*
  344.  * returns:  1 - (on APPEND_NAME) truncated filename
  345.  *           2 - path doesn't exist, not allowed to create
  346.  *           3 - path doesn't exist, tried to create and failed; or
  347.  *               path exists and is not a directory, but is supposed to be
  348.  *           4 - path is too long
  349.  *          10 - can't allocate memory for filename buffers
  350.  */
  351. {
  352.     static int rootlen = 0;   /* length of rootpath */
  353.     static char *rootpath;    /* user's "extract-to" directory */
  354.     static char *buildpath;   /* full path (so far) to extracted file */
  355.     static char *end;         /* pointer to end of buildpath ('\0') */
  356.  
  357. #   define FN_MASK   7
  358. #   define FUNCTION  (flag & FN_MASK)
  359.  
  360.  
  361.  
  362. /*---------------------------------------------------------------------------
  363.     APPEND_DIR:  append the path component to the path being built and check
  364.     for its existence.  If doesn't exist and we are creating directories, do
  365.     so for this one; else signal success or error as appropriate.
  366.   ---------------------------------------------------------------------------*/
  367.  
  368.     if (FUNCTION == APPEND_DIR) {
  369.         int too_long = FALSE;
  370. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  371. #ifdef SHORT_NAMES
  372.         char *old_end = end;
  373. #endif
  374.  
  375.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  376.         while ((*end = *pathcomp++) != '\0')
  377.             ++end;
  378. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  379. #ifdef SHORT_NAMES   /* path components restricted to 14 chars, typically */
  380.         if ((end-old_end) > FILENAME_MAX)  /* GRR:  proper constant? */
  381.             *(end = old_end + FILENAME_MAX) = '\0';
  382. #endif
  383.  
  384.         /* GRR:  could do better check, see if overrunning buffer as we go:
  385.          * check end-buildpath after each append, set warning variable if
  386.          * within 20 of FILNAMSIZ; then if var set, do careful check when
  387.          * appending.  Clear variable when begin new path. */
  388.  
  389.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  390.             too_long = TRUE;                /* check if extracting directory? */
  391.         if (stat(buildpath, &G.statbuf)) {  /* path doesn't exist */
  392.             if (!G.create_dirs) { /* told not to create (freshening) */
  393.                 free(buildpath);
  394.                 return 2;         /* path doesn't exist:  nothing to do */
  395.             }
  396.             if (too_long) {
  397.                 Info(slide, 1, ((char *)slide,
  398.                   "checkdir error:  path too long: %s\n", buildpath));
  399.                 free(buildpath);
  400.                 return 4;         /* no room for filenames:  fatal */
  401.             }
  402.             if (mkdir(buildpath, 0777) == -1) {   /* create the directory */
  403.                 Info(slide, 1, ((char *)slide,
  404.                   "checkdir error:  can't create %s\n\
  405.                  unable to process %s.\n", buildpath, G.filename));
  406.                 free(buildpath);
  407.                 return 3;      /* path didn't exist, tried to create, failed */
  408.             }
  409.             created_dir = TRUE;
  410.         } else if (!S_ISDIR(G.statbuf.st_mode)) {
  411.             Info(slide, 1, ((char *)slide,
  412.               "checkdir error:  %s exists but is not directory\n\
  413.                  unable to process %s.\n", buildpath, G.filename));
  414.             free(buildpath);
  415.             return 3;          /* path existed but wasn't dir */
  416.         }
  417.         if (too_long) {
  418.             Info(slide, 1, ((char *)slide,
  419.               "checkdir error:  path too long: %s\n", buildpath));
  420.             free(buildpath);
  421.             return 4;         /* no room for filenames:  fatal */
  422.         }
  423.         *end++ = '/';
  424.         *end = '\0';
  425.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  426.         return 0;
  427.  
  428.     } /* end if (FUNCTION == APPEND_DIR) */
  429.  
  430. /*---------------------------------------------------------------------------
  431.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  432.     buildpath.
  433.   ---------------------------------------------------------------------------*/
  434.  
  435.     if (FUNCTION == GETPATH) {
  436.         strcpy(pathcomp, buildpath);
  437.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  438.         free(buildpath);
  439.         buildpath = end = (char *)NULL;
  440.         return 0;
  441.     }
  442.  
  443. /*---------------------------------------------------------------------------
  444.     APPEND_NAME:  assume the path component is the filename; append it and
  445.     return without checking for existence.
  446.   ---------------------------------------------------------------------------*/
  447.  
  448.     if (FUNCTION == APPEND_NAME) {
  449. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  450. #ifdef SHORT_NAMES
  451.         char *old_end = end;
  452. #endif
  453.  
  454.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  455.         while ((*end = *pathcomp++) != '\0') {
  456.             ++end;
  457. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  458. #ifdef SHORT_NAMES  /* truncate name at 14 characters, typically */
  459.             if ((end-old_end) > FILENAME_MAX)      /* GRR:  proper constant? */
  460.                 *(end = old_end + FILENAME_MAX) = '\0';
  461. #endif
  462.             if ((end-buildpath) >= FILNAMSIZ) {
  463.                 *--end = '\0';
  464.                 Info(slide, 0x201, ((char *)slide,
  465.                   "checkdir warning:  path too long; truncating\n\
  466.                    %s\n                -> %s\n", G.filename, buildpath));
  467.                 return 1;   /* filename truncated */
  468.             }
  469.         }
  470.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  471.         return 0;  /* could check for existence here, prompt for new name... */
  472.     }
  473.  
  474. /*---------------------------------------------------------------------------
  475.     INIT:  allocate and initialize buffer space for the file currently being
  476.     extracted.  If file was renamed with an absolute path, don't prepend the
  477.     extract-to path.
  478.   ---------------------------------------------------------------------------*/
  479.  
  480. /* GRR:  for VMS and TOPS-20, add up to 13 to strlen */
  481.  
  482.     if (FUNCTION == INIT) {
  483.         Trace((stderr, "initializing buildpath to "));
  484.         if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) ==
  485.             (char *)NULL)
  486.             return 10;
  487.         if ((rootlen > 0) && !renamed_fullpath) {
  488.             strcpy(buildpath, rootpath);
  489.             end = buildpath + rootlen;
  490.         } else {
  491.             *buildpath = '\0';
  492.             end = buildpath;
  493.         }
  494.         Trace((stderr, "[%s]\n", buildpath));
  495.         return 0;
  496.     }
  497.  
  498. /*---------------------------------------------------------------------------
  499.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  500.     sary; else assume it's a zipfile member and return.  This path segment
  501.     gets used in extracting all members from every zipfile specified on the
  502.     command line.
  503.   ---------------------------------------------------------------------------*/
  504.  
  505. #if (!defined(SFX) || defined(SFX_EXDIR))
  506.     if (FUNCTION == ROOT) {
  507.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  508.         if (pathcomp == (char *)NULL) {
  509.             rootlen = 0;
  510.             return 0;
  511.         }
  512.         if ((rootlen = strlen(pathcomp)) > 0) {
  513.             if (pathcomp[rootlen-1] == '/') {
  514.                 pathcomp[--rootlen] = '\0';
  515.             }
  516.             if (rootlen > 0 && (stat(pathcomp, &G.statbuf) ||
  517.                 !S_ISDIR(G.statbuf.st_mode)))       /* path does not exist */
  518.             {
  519.                 if (!G.create_dirs /* || iswild(pathcomp) */ ) {
  520.                     rootlen = 0;
  521.                     return 2;   /* skip (or treat as stored file) */
  522.                 }
  523.                 /* create the directory (could add loop here to scan pathcomp
  524.                  * and create more than one level, but why really necessary?) */
  525.                 if (mkdir(pathcomp, 0777) == -1) {
  526.                     Info(slide, 1, ((char *)slide,
  527.                       "checkdir:  can't create extraction directory: %s\n",
  528.                       pathcomp));
  529.                     rootlen = 0;   /* path didn't exist, tried to create, and */
  530.                     return 3;  /* failed:  file exists, or 2+ levels required */
  531.                 }
  532.             }
  533.             if ((rootpath = (char *)malloc(rootlen+2)) == (char *)NULL) {
  534.                 rootlen = 0;
  535.                 return 10;
  536.             }
  537.             strcpy(rootpath, pathcomp);
  538.             rootpath[rootlen++] = '/';
  539.             rootpath[rootlen] = '\0';
  540.             Trace((stderr, "rootpath now = [%s]\n", rootpath));
  541.         }
  542.         return 0;
  543.     }
  544. #endif /* !SFX || SFX_EXDIR */
  545.  
  546. /*---------------------------------------------------------------------------
  547.     END:  free rootpath, immediately prior to program exit.
  548.   ---------------------------------------------------------------------------*/
  549.  
  550.     if (FUNCTION == END) {
  551.         Trace((stderr, "freeing rootpath\n"));
  552.         if (rootlen > 0)
  553.             free(rootpath);
  554.         return 0;
  555.     }
  556.  
  557.     return 99;  /* should never reach */
  558.  
  559. } /* end function checkdir() */
  560.  
  561.  
  562.  
  563.  
  564. /****************************/
  565. /* Function close_outfile() */
  566. /****************************/
  567.  
  568. void close_outfile(__G)    /* GRR: change to return PK-style warning level */
  569.     __GDEF
  570. {
  571. #ifdef USE_EF_UT_TIME
  572.     unsigned eb_izux_flags;
  573.     iztimes zt;
  574. #endif
  575.     ztimbuf tp;
  576.  
  577. /*---------------------------------------------------------------------------
  578.     If symbolic links are supported, allocate a storage area, put the uncom-
  579.     pressed "data" in it, and create the link.  Since we know it's a symbolic
  580.     link to start with, we shouldn't have to worry about overflowing unsigned
  581.     ints with unsigned longs.
  582.   ---------------------------------------------------------------------------*/
  583.  
  584.     /* symlinks allowed on minix filesystems [cjh]
  585.      * Hopefully this will work properly... We won't bother to try if
  586.      * MiNT isn't present; the symlink should fail if we're on a TOS
  587.      * filesystem.
  588.      * BUG: should we copy the original file to the "symlink" if the
  589.      *      link fails?
  590.      */
  591.     if (G.symlnk) {
  592.         unsigned ucsize = (unsigned)G.lrec.ucsize;
  593.         char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1);
  594.  
  595.         fclose(G.outfile);                      /* close "data" file... */
  596.         G.outfile = fopen(G.filename, FOPR);    /* ...and reopen for reading */
  597.         if (!linktarget || (fread(linktarget, 1, ucsize, G.outfile) !=
  598.                             (int)ucsize)) {
  599.             Info(slide, 0x201, ((char *)slide,
  600.               "warning:  symbolic link (%s) failed\n", G.filename));
  601.             if (linktarget)
  602.                 free(linktarget);
  603.             fclose(G.outfile);
  604.             return;
  605.         }
  606.         fclose(G.outfile);                  /* close "data" file for good... */
  607.         unlink(G.filename);                 /* ...and delete it */
  608.         linktarget[ucsize] = '\0';
  609.         Info(slide, 0, ((char *)slide, "-> %s ", linktarget));
  610.         if (symlink(linktarget, G.filename))  /* create the real link */
  611.             perror("symlink error");
  612.         free(linktarget);
  613.         return;                             /* can't set time on symlinks */
  614.     }
  615.  
  616.     fclose(G.outfile);
  617.  
  618. /*---------------------------------------------------------------------------
  619.     Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
  620.     time:  adjust base year from 1980 to 1970, do usual conversions from
  621.     yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-
  622.     light savings time differences.
  623.   ---------------------------------------------------------------------------*/
  624.  
  625. #ifdef USE_EF_UT_TIME
  626.     eb_izux_flg = G.extra_field ?
  627.                  ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
  628.                                   &zt, NULL) : 0;
  629.     if (eb_izux_flg & EB_UT_FL_MTIME) {
  630.         tp.modtime = zt.mtime;
  631.         TTrace((stderr, "\nclose_outfile:  Unix e.f. modif. time = %ld\n",
  632.           tp.modtime));
  633.     } else {
  634.         tp.modtime = dos_to_unix_time(G.lrec.last_mod_file_date,
  635.                                       G.lrec.last_mod_file_time);
  636.     }
  637.     if (eb_izux_flg & EB_UT_FL_ATIME) {
  638.         tp.actime = zt.atime;
  639.         TTrace((stderr, "close_outfile:  Unix e.f. access time = %ld\n",
  640.           tp.actime));
  641.     } else {
  642.         tp.actime = tp.modtime;
  643.         TTrace((stderr, "\nclose_outfile:  modification/access times = %ld\n",
  644.           tp.modtime));
  645.     }
  646. #else /* !USE_EF_UT_TIME */
  647.     tp.actime = tp.modtime = dos_to_unix_time(G.lrec.last_mod_file_date,
  648.                                               G.lrec.last_mod_file_time);
  649.  
  650.     TTrace((stderr, "\nclose_outfile:  modification/access times = %ld\n",
  651.       tp.modtime));
  652. #endif /* ?USE_EF_UT_TIME */
  653.  
  654.     /* set the file's access and modification times */
  655.     if (utime(G.filename, &tp))
  656.         Info(slide, 0x201, ((char *)slide,
  657.           "warning:  can't set the time for %s\n", G.filename));
  658.  
  659. /*---------------------------------------------------------------------------
  660.     Change the file permissions from default ones to those stored in the
  661.     zipfile.
  662.   ---------------------------------------------------------------------------*/
  663.  
  664. #ifndef NO_CHMOD
  665.     if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
  666.             perror("chmod (file attributes) error");
  667. #endif
  668.  
  669. } /* end function close_outfile() */
  670.  
  671.  
  672.  
  673.  
  674. #ifndef SFX
  675.  
  676. /************************/
  677. /*  Function version()  */
  678. /************************/
  679.  
  680. void version(__G)
  681.     __GDEF
  682. {
  683. #ifdef __TURBOC__
  684.     char buf[40];
  685. #endif
  686.  
  687.     sprintf((char *)slide, LoadFarString(CompiledWith),
  688.  
  689. #ifdef __GNUC__
  690.       "gcc ", __VERSION__,
  691. #else
  692. #  if 0
  693.       "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
  694. #  else
  695. #  ifdef __TURBOC__
  696.       "Turbo C", (sprintf(buf, " (0x%04x = %d)", __TURBOC__, __TURBOC__), buf),
  697. #  else
  698.       "unknown compiler", "",
  699. #  endif
  700. #  endif
  701. #endif
  702.  
  703. #ifdef __MINT__
  704.       "Atari TOS/MiNT",
  705. #else
  706.       "Atari TOS",
  707. #endif
  708.  
  709.       " (Atari ST/TT/Falcon030)",
  710.  
  711. #ifdef __DATE__
  712.       " on ", __DATE__
  713. #else
  714.       "", ""
  715. #endif
  716.     );
  717.  
  718.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  719.  
  720. } /* end function version() */
  721.  
  722. #endif /* !SFX */
  723.