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