home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip22.zip / win32 / win32zip.c < prev    next >
C/C++ Source or Header  |  1997-08-19  |  21KB  |  735 lines

  1. /*
  2.  
  3.  Copyright (C) 1990-1997 Mark Adler, Richard B. Wales, Jean-loup Gailly,
  4.  Kai Uwe Rommel, Onno van der Linden and Igor Mandrichenko.
  5.  Permission is granted to any individual or institution to use, copy, or
  6.  redistribute this software so long as all of the original files are included,
  7.  that it is not sold for profit, and that this copyright notice is retained.
  8.  
  9. */
  10.  
  11. #ifndef UTIL    /* this file contains nothing used by UTIL */
  12.  
  13. #include "zip.h"
  14.  
  15. #ifndef __EMX__
  16. #include <direct.h>     /* for rmdir() */
  17. #endif
  18. #include <time.h>
  19.  
  20. #ifndef __BORLANDC__
  21. #include <sys/utime.h>
  22. #else
  23. #include <utime.h>
  24. #endif
  25. #include <windows.h> /* for findfirst/findnext stuff */
  26. #ifdef __RSXNT__
  27. #  include "win32/rsxntwin.h"
  28. #endif
  29. char *GetLongPathEA OF((char *name));
  30.  
  31. #include <io.h>
  32. #define MATCH         dosmatch
  33.  
  34. #define PAD           0
  35. #define PATH_END      '/'
  36. #define HIDD_SYS_BITS (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)
  37.  
  38.  
  39. typedef struct zdirent {
  40.   ush    d_date, d_time;
  41.   ulg    d_size;
  42.   char   d_attr;
  43.   char   d_name[MAX_PATH];
  44.   int    d_first;
  45.   HANDLE d_hFindFile;
  46. } zDIR;
  47.  
  48. #include "win32/win32zip.h"
  49. #include "win32/nt.h"
  50.  
  51. /* Local functions */
  52. local zDIR           *Opendir      OF((ZCONST char *n));
  53. local struct zdirent *Readdir      OF((zDIR *d));
  54. local void            Closedir     OF((zDIR *d));
  55.  
  56. local char           *readd        OF((zDIR *));
  57. local int             wild_recurse OF((char *, char *));
  58. #ifdef NTSD_EAS
  59.    local void GetSD OF((char *path, char **bufptr, size_t *size,
  60.                         char **cbufptr, size_t *csize));
  61. #endif
  62. #ifdef USE_EF_UT_TIME
  63.    local int GetExtraTime OF((struct zlist far *z, iztimes *z_utim));
  64. #endif
  65.  
  66. /* Module level variables */
  67. extern char *label /* = NULL */ ;       /* defined in fileio.c */
  68. local ulg label_time = 0;
  69. local ulg label_mode = 0;
  70. local time_t label_utim = 0;
  71.  
  72. /* Module level constants */
  73. local ZCONST char wild_match_all[] = "*.*";
  74.  
  75. local zDIR *Opendir(n)
  76. ZCONST char *n;          /* directory to open */
  77. /* Start searching for files in the MSDOS directory n */
  78. {
  79.   zDIR *d;              /* malloc'd return value */
  80.   char *p;              /* malloc'd temporary string */
  81.   char *q;
  82.   WIN32_FIND_DATA fd;
  83.  
  84.   if ((d = (zDIR *)malloc(sizeof(zDIR))) == NULL ||
  85.       (p = malloc(strlen(n) + 5)) == NULL) {
  86.     if (d != NULL) free((zvoid *)d);
  87.     return NULL;
  88.   }
  89.   strcpy(p, n);
  90.   q = p + strlen(p);
  91.   if (q[-1] == ':')
  92.       *q++ = '.';
  93.   if ((q - p) > 0 && *(q - 1) != '/')
  94.     *q++ = '/';
  95.   strcpy(q, wild_match_all);
  96.  
  97. #ifdef __RSXNT__        /* RSXNT/EMX C rtl uses OEM charset */
  98.   OemToAnsi(p, p);
  99. #endif
  100.   d->d_hFindFile = FindFirstFile(p, &fd);
  101.   free((zvoid *)p);
  102.  
  103.   if (d->d_hFindFile == INVALID_HANDLE_VALUE)
  104.   {
  105.     free((zvoid *)d);
  106.     return NULL;
  107.   }
  108.  
  109.   strcpy(d->d_name, fd.cFileName);
  110.   d->d_attr = (unsigned char) fd.dwFileAttributes;
  111.   d->d_first = 1;
  112.   return d;
  113. }
  114.  
  115. local struct zdirent *Readdir(d)
  116. zDIR *d;                /* directory stream to read from */
  117. /* Return pointer to first or next directory entry, or NULL if end. */
  118. {
  119.   if (d->d_first)
  120.     d->d_first = 0;
  121.   else
  122.   {
  123.     WIN32_FIND_DATA fd;
  124.  
  125.     if (!FindNextFile(d->d_hFindFile, &fd))
  126.         return NULL;
  127.     strcpy(d->d_name, fd.cFileName);
  128.     d->d_attr = (unsigned char) fd.dwFileAttributes;
  129.   }
  130. #ifdef __RSXNT__        /* RSXNT/EMX C rtl uses OEM charset */
  131.   AnsiToOem(d->d_name, d->d_name);
  132. #endif
  133.   return (struct zdirent *)d;
  134. }
  135.  
  136. local void Closedir(d)
  137. zDIR *d;                /* directory stream to close */
  138. {
  139.   FindClose(d->d_hFindFile);
  140.   free((zvoid *)d);
  141. }
  142.  
  143.  
  144. local char *readd(d)
  145. zDIR *d;                /* directory stream to read from */
  146. /* Return a pointer to the next name in the directory stream d, or NULL if
  147.    no more entries or an error occurs. */
  148. {
  149.   struct zdirent *e;
  150.  
  151.   do
  152.     e = Readdir(d);
  153.   while (!hidden_files && e && e->d_attr & HIDD_SYS_BITS);
  154.   return e == NULL ? (char *) NULL : e->d_name;
  155. }
  156.  
  157.  
  158. #define ONENAMELEN 255
  159.  
  160. /* whole is a pathname with wildcards, wildtail points somewhere in the  */
  161. /* middle of it.  All wildcards to be expanded must come AFTER wildtail. */
  162.  
  163. local int wild_recurse(whole, wildtail)
  164. char *whole;
  165. char *wildtail;
  166. {
  167.     zDIR *dir;
  168.     char *subwild, *name, *newwhole = NULL, *glue = NULL, plug = 0, plug2;
  169.     ush newlen, amatch = 0;
  170.     int e = ZE_MISS;
  171.  
  172.     if (!isshexp(wildtail))
  173.         if (GetFileAttributes(whole) != 0xFFFFFFFF)     /* file exists? */
  174.             return procname(whole);
  175.         else
  176.             return ZE_MISS;                     /* woops, no wildcards! */
  177.  
  178.     /* back up thru path components till existing dir found */
  179.     do {
  180.         name = wildtail + strlen(wildtail) - 1;
  181.         for (;;)
  182.             if (name-- <= wildtail || *name == PATH_END) {
  183.                 subwild = name + 1;
  184.                 plug2 = *subwild;
  185.                 *subwild = 0;
  186.                 break;
  187.             }
  188.         if (glue)
  189.             *glue = plug;
  190.         glue = subwild;
  191.         plug = plug2;
  192.         dir = Opendir(whole);
  193.     } while (!dir && subwild > wildtail);
  194.     wildtail = subwild;                 /* skip past non-wild components */
  195.  
  196.     if ((subwild = strchr(wildtail + 1, PATH_END)) != NULL) {
  197.         /* this "+ 1" dodges the  ^^^ hole left by *glue == 0 */
  198.         *(subwild++) = 0;               /* wildtail = one component pattern */
  199.         newlen = strlen(whole) + strlen(subwild) + ONENAMELEN + 2;
  200.     } else
  201.         newlen = strlen(whole) + ONENAMELEN + 1;
  202.     if (!dir || ((newwhole = malloc(newlen)) == NULL)) {
  203.         if (glue)
  204.             *glue = plug;
  205.         e = dir ? ZE_MEM : ZE_MISS;
  206.         goto ohforgetit;
  207.     }
  208.     strcpy(newwhole, whole);
  209.     newlen = strlen(newwhole);
  210.     if (glue)
  211.         *glue = plug;                           /* repair damage to whole */
  212.     if (!isshexp(wildtail)) {
  213.         e = ZE_MISS;                            /* non-wild name not found */
  214.         goto ohforgetit;
  215.     }
  216.  
  217.     while ((name = readd(dir)) != NULL) {
  218.         if (strcmp(name, ".") && strcmp(name, "..") && MATCH(wildtail, name)) {
  219.             strcpy(newwhole + newlen, name);
  220.             if (subwild) {
  221.                 name = newwhole + strlen(newwhole);
  222.                 *(name++) = PATH_END;
  223.                 strcpy(name, subwild);
  224.                 e = wild_recurse(newwhole, name);
  225.             } else
  226.                 e = procname(newwhole);
  227.             newwhole[newlen] = 0;
  228.             if (e == ZE_OK)
  229.                 amatch = 1;
  230.             else if (e != ZE_MISS)
  231.                 break;
  232.         }
  233.     }
  234.  
  235.   ohforgetit:
  236.     if (dir) Closedir(dir);
  237.     if (subwild) *--subwild = PATH_END;
  238.     if (newwhole) free(newwhole);
  239.     if (e == ZE_MISS && amatch)
  240.         e = ZE_OK;
  241.     return e;
  242. }
  243.  
  244. int wild(w)
  245. char *w;                /* path/pattern to match */
  246. /* If not in exclude mode, expand the pattern based on the contents of the
  247.    file system.  Return an error code in the ZE_ class. */
  248. {
  249.     char *p;              /* path */
  250.     char *q;              /* diskless path */
  251.     int e;                /* result */
  252.  
  253.     if (volume_label == 1) {
  254.       volume_label = 2;
  255.       label = getVolumeLabel((w != NULL && w[1] == ':') ? to_up(w[0]) : '\0',
  256.                              &label_time, &label_mode, &label_utim);
  257.       if (label != NULL)
  258.         (void)newname(label, 0);
  259.       if (w == NULL || (w[1] == ':' && w[2] == '\0')) return ZE_OK;
  260.       /* "zip -$ foo a:" can be used to force drive name */
  261.     }
  262.     /* special handling of stdin request */
  263.     if (strcmp(w, "-") == 0)   /* if compressing stdin */
  264.         return newname(w, 0);
  265.  
  266.     /* Allocate and copy pattern, leaving room to add "." if needed */
  267.     if ((p = malloc(strlen(w) + 2)) == NULL)
  268.         return ZE_MEM;
  269.     strcpy(p, w);
  270.  
  271.     /* Normalize path delimiter as '/' */
  272.     for (q = p; *q; q++)                  /* use / consistently */
  273.         if (*q == '\\')
  274.             *q = '/';
  275.  
  276.     /* Separate the disk part of the path */
  277.     if ((q = strchr(p, ':')) != NULL) {
  278.         if (strchr(++q, ':'))     /* sanity check for safety of wild_recurse */
  279.             return ZE_MISS;
  280.     } else
  281.         q = p;
  282.  
  283.     /* Normalize bare disk names */
  284.     if (q > p && !*q)
  285.         strcpy(q, ".");
  286.  
  287.     /* Here we go */
  288.     e = wild_recurse(p, q);
  289.     free((zvoid *)p);
  290.     return e;
  291. }
  292.  
  293. int procname(n)
  294. char *n;                /* name to process */
  295. /* Process a name or sh expression to operate on (or exclude).  Return
  296.    an error code in the ZE_ class. */
  297. {
  298.   char *a;              /* path and name for recursion */
  299.   zDIR *d;              /* directory stream from opendir() */
  300.   char *e;              /* pointer to name from readd() */
  301.   int m;                /* matched flag */
  302.   char *p;              /* path for recursion */
  303.   struct stat s;        /* result of stat() */
  304.   struct zlist far *z;  /* steps through zfiles list */
  305.  
  306.   if (strcmp(n, "-") == 0)   /* if compressing stdin */
  307.     return newname(n, 0);
  308.   else if (LSSTAT(n, &s)
  309. #ifdef __TURBOC__
  310.            /* For this compiler, stat() succeeds on wild card names! */
  311.            /* Unfortunately, this causes failure on names containing */
  312.            /* square bracket characters, which are legal in win32.   */
  313.            || isshexp(n)
  314. #endif
  315.           )
  316.   {
  317.     /* Not a file or directory--search for shell expression in zip file */
  318.     p = ex2in(n, 0, (int *)NULL);       /* shouldn't affect matching chars */
  319.     m = 1;
  320.     for (z = zfiles; z != NULL; z = z->nxt) {
  321.       if (MATCH(p, z->iname))
  322.       {
  323.         z->mark = pcount ? filter(z->zname) : 1;
  324.         if (verbose)
  325.             fprintf(mesg, "zip diagnostic: %scluding %s\n",
  326.                z->mark ? "in" : "ex", z->name);
  327.         m = 0;
  328.       }
  329.     }
  330.     free((zvoid *)p);
  331.     return m ? ZE_MISS : ZE_OK;
  332.   }
  333.  
  334.   /* Live name--use if file, recurse if directory */
  335.   for (p = n; *p; p++)          /* use / consistently */
  336.     if (*p == '\\')
  337.       *p = '/';
  338.   if ((s.st_mode & S_IFDIR) == 0)
  339.   {
  340.     /* add or remove name of file */
  341.     if ((m = newname(n, 0)) != ZE_OK)
  342.       return m;
  343.   } else {
  344.     /* Add trailing / to the directory name */
  345.     if ((p = malloc(strlen(n)+2)) == NULL)
  346.       return ZE_MEM;
  347.     if (strcmp(n, ".") == 0 || strcmp(n, "/.") == 0) {
  348.       *p = '\0';  /* avoid "./" prefix and do not create zip entry */
  349.     } else {
  350.       strcpy(p, n);
  351.       a = p + strlen(p);
  352.       if (a[-1] != '/')
  353.         strcpy(a, "/");
  354.       if (dirnames && (m = newname(p, 1)) != ZE_OK) {
  355.         free((zvoid *)p);
  356.         return m;
  357.       }
  358.     }
  359.     /* recurse into directory */
  360.     if (recurse && (d = Opendir(n)) != NULL)
  361.     {
  362.       while ((e = readd(d)) != NULL) {
  363.         if (strcmp(e, ".") && strcmp(e, ".."))
  364.         {
  365.           if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)
  366.           {
  367.             Closedir(d);
  368.             free((zvoid *)p);
  369.             return ZE_MEM;
  370.           }
  371.           strcat(strcpy(a, p), e);
  372.           if ((m = procname(a)) != ZE_OK)   /* recurse on name */
  373.           {
  374.             if (m == ZE_MISS)
  375.               zipwarn("name not matched: ", a);
  376.             else
  377.               ziperr(m, a);
  378.           }
  379.           free((zvoid *)a);
  380.         }
  381.       }
  382.       Closedir(d);
  383.     }
  384.     free((zvoid *)p);
  385.   } /* (s.st_mode & S_IFDIR) == 0) */
  386.   return ZE_OK;
  387. }
  388.  
  389. char *ex2in(x, isdir, pdosflag)
  390. char *x;                /* external file name */
  391. int isdir;              /* input: x is a directory */
  392. int *pdosflag;          /* output: force MSDOS file attributes? */
  393. /* Convert the external file name to a zip file name, returning the malloc'ed
  394.    string or NULL if not enough memory. */
  395. {
  396.   char *n;              /* internal file name (malloc'ed) */
  397.   char *t;              /* shortened name */
  398.   int dosflag;
  399.  
  400.  
  401.   dosflag = dosify || IsFileSystemOldFAT(x);
  402.   if (!dosify && use_longname_ea && (t = GetLongPathEA(x)) != NULL)
  403.   {
  404.     x = t;
  405.     dosflag = 0;
  406.   }
  407.  
  408.   /* Find starting point in name before doing malloc */
  409.   t = *x && *(x + 1) == ':' ? x + 2 : x;
  410.   while (*t == '/' || *t == '\\')
  411.     t++;
  412.   /* Strip leading "./" as well as drive letter */
  413.   while (*t == '.' && (t[1] == '/' || t[1] == '\\'))
  414.     t += 2;
  415.  
  416.   /* Make changes, if any, to the copied name (leave original intact) */
  417.   for (n = t; *n; n++)
  418.     if (*n == '\\')
  419.       *n = '/';
  420.  
  421.   if (!pathput)
  422.     t = last(t, PATH_END);
  423.  
  424.   /* Malloc space for internal name and copy it */
  425.   if ((n = malloc(strlen(t) + 1)) == NULL)
  426.     return NULL;
  427.   strcpy(n, t);
  428.  
  429.   if (dosify)
  430.     msname(n);
  431.  
  432.   /* Returned malloc'ed name */
  433.   if (pdosflag)
  434.     *pdosflag = dosflag;
  435.   return n;
  436. }
  437.  
  438.  
  439. char *in2ex(n)
  440. char *n;                /* internal file name */
  441. /* Convert the zip file name to an external file name, returning the malloc'ed
  442.    string or NULL if not enough memory. */
  443. {
  444.   char *x;              /* external file name */
  445.  
  446.   if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
  447.     return NULL;
  448.   strcpy(x, n);
  449.  
  450.   return x;
  451. }
  452.  
  453.  
  454. void stamp(f, d)
  455. char *f;                /* name of file to change */
  456. ulg d;                  /* dos-style time to change it to */
  457. /* Set last updated and accessed time of file f to the DOS time d. */
  458. {
  459. #if defined(__TURBOC__) && !defined(__BORLANDC__)
  460.   int h;                /* file handle */
  461.  
  462.   if ((h = open(f, 0)) != -1)
  463.   {
  464.     setftime(h, (struct ftime *)&d);
  465.     close(h);
  466.   }
  467. #else /* !__TURBOC__ */
  468.  
  469.   struct utimbuf u;     /* argument for utime() */
  470.  
  471.   /* Convert DOS time to time_t format in u.actime and u.modtime */
  472.   u.actime = u.modtime = dos2unixtime(d);
  473.  
  474.   /* Set updated and accessed times of f */
  475.   utime(f, &u);
  476. #endif /* ?__TURBOC__ */
  477. }
  478.  
  479.  
  480. ulg filetime(f, a, n, t)
  481. char *f;                /* name of file to get info on */
  482. ulg *a;                 /* return value: file attributes */
  483. long *n;                /* return value: file size */
  484. iztimes *t;             /* return value: access, modific. and creation times */
  485. /* If file *f does not exist, return 0.  Else, return the file's last
  486.    modified date and time as an MSDOS date and time.  The date and
  487.    time is returned in a long with the date most significant to allow
  488.    unsigned integer comparison of absolute times.  Also, if a is not
  489.    a NULL pointer, store the file attributes there, with the high two
  490.    bytes being the Unix attributes, and the low byte being a mapping
  491.    of that to DOS attributes.  If n is not NULL, store the file size
  492.    there.  If t is not NULL, the file's access, modification and creation
  493.    times are stored there as UNIX time_t values.
  494.    If f is "-", use standard input as the file. If f is a device, return
  495.    a file size of -1 */
  496. {
  497.   struct stat s;        /* results of stat() */
  498.   char name[FNMAX];
  499.   int len = strlen(f), isstdin = !strcmp(f, "-");
  500.  
  501.   if (f == label) {
  502.     if (a != NULL)
  503.       *a = label_mode;
  504.     if (n != NULL)
  505.       *n = -2L; /* convention for a label name */
  506.     if (t != NULL)
  507.       t->atime = t->mtime = t->ctime = label_utim;
  508.     return label_time;
  509.   }
  510.   strcpy(name, f);
  511.   if (name[len - 1] == '/')
  512.     name[len - 1] = '\0';
  513.   /* not all systems allow stat'ing a file with / appended */
  514.  
  515.   if (isstdin) {
  516.     if (fstat(fileno(stdin), &s) != 0)
  517.       error("fstat(stdin)");
  518.     time((time_t *)&s.st_mtime);       /* some fstat()s return time zero */
  519.   } else if (LSSTAT(name, &s) != 0)
  520.              /* Accept about any file kind including directories
  521.               * (stored with trailing / with -r option)
  522.               */
  523.     return 0;
  524.  
  525.   if (a != NULL) {
  526.     *a = ((ulg)s.st_mode << 16) | (isstdin ? 0L : (ulg)GetFileMode(name));
  527.   }
  528.   if (n != NULL)
  529.     *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;
  530.   if (t != NULL) {
  531.     t->atime = s.st_atime;
  532.     t->mtime = s.st_mtime;
  533.     t->ctime = s.st_ctime;
  534.   }
  535.  
  536.   return unix2dostime((time_t *)&s.st_mtime);
  537. }
  538.  
  539.  
  540. #ifdef NTSD_EAS
  541.  
  542. local void GetSD(char *path, char **bufptr, size_t *size,
  543.                         char **cbufptr, size_t *csize)
  544. {
  545.   unsigned char stackbuffer[NTSD_BUFFERSIZE];
  546.   unsigned long bytes = NTSD_BUFFERSIZE;
  547.   unsigned char *buffer = stackbuffer;
  548.   unsigned char *DynBuffer = NULL;
  549.   long cbytes;
  550.   PEF_NTSD_L_HEADER pLocalHeader;
  551.   PEF_NTSD_C_HEADER pCentralHeader;
  552.   VOLUMECAPS VolumeCaps;
  553.  
  554. #ifndef NO_NTSD_WITH_RSXNT
  555.   /* check target volume capabilities */
  556.   if (!ZipGetVolumeCaps(path, path, &VolumeCaps) ||
  557.      !(VolumeCaps.dwFileSystemFlags & FS_PERSISTENT_ACLS)) {
  558.     return;
  559.   }
  560.  
  561.   VolumeCaps.bUsePrivileges = use_privileges;
  562.   VolumeCaps.dwFileAttributes = 0; /* should set to file attributes, if possible */
  563.  
  564.   if (!SecurityGet(path, &VolumeCaps, buffer, &bytes)) {
  565.  
  566.     /* try to malloc the buffer if appropriate */
  567.     if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
  568.         DynBuffer = malloc(bytes);
  569.         if(DynBuffer == NULL) return;
  570.  
  571.         buffer = DynBuffer; /* switch to the new buffer and try again */
  572.  
  573.         if(!SecurityGet(path, &VolumeCaps, buffer, &bytes)) {
  574.             free(DynBuffer);
  575.             return;
  576.         }
  577.  
  578.     } else {
  579.         return; /* bail */
  580.     }
  581.   }
  582. #else /* NO_NTSD_WITH_RSXNT */
  583.   return; /* bail */
  584. #endif /* ?NO_NTSD_WITH_RSXNT */
  585.  
  586.   /* # bytes to compress: compress type, CRC, data bytes */
  587.   cbytes = sizeof(USHORT) + sizeof(ULONG) + bytes;
  588.  
  589.  
  590.   /* our two possible failure points.  don't allow trashing of any data
  591.      if either fails - notice that *size and *csize don't get updated.
  592.      *bufptr leaks if malloc() was used and *cbufptr alloc fails - this
  593.      isn't relevant because it's probably indicative of a bigger problem. */
  594.  
  595.   if(*size)
  596.     *bufptr = realloc(*bufptr, *size + sizeof(EF_NTSD_L_HEADER) + cbytes);
  597.   else
  598.     *bufptr = malloc(sizeof(EF_NTSD_L_HEADER) + cbytes );
  599.  
  600.   if(*csize)
  601.     *cbufptr = realloc(*cbufptr, *csize + sizeof(EF_NTSD_C_HEADER));
  602.   else
  603.     *cbufptr = malloc(sizeof(EF_NTSD_C_HEADER));
  604.  
  605.   if(*bufptr == NULL || *cbufptr == NULL) {
  606.     if(DynBuffer) free(DynBuffer);
  607.     return;
  608.   }
  609.  
  610.   /* local header */
  611.  
  612.   pLocalHeader = (PEF_NTSD_L_HEADER) (*bufptr + *size);
  613.  
  614.   cbytes = memcompress((char *)(pLocalHeader + 1), cbytes,
  615.                        (char *)buffer, bytes);
  616.  
  617.   *size += sizeof(EF_NTSD_L_HEADER) + cbytes;
  618.  
  619.   pLocalHeader->nID = EF_NTSD;
  620.   pLocalHeader->nSize = sizeof(EF_NTSD_L_HEADER) - EB_HEADSIZE + cbytes;
  621.   pLocalHeader->lSize = bytes; /* uncompressed size */
  622.   pLocalHeader->Version = 0;
  623.  
  624.   /* central header */
  625.  
  626.   pCentralHeader = (PEF_NTSD_C_HEADER) (*cbufptr + *csize);
  627.   *csize += sizeof(EF_NTSD_C_HEADER);
  628.  
  629.   pCentralHeader->nID = EF_NTSD;
  630.   pCentralHeader->nSize = sizeof(EF_NTSD_C_HEADER) - EB_HEADSIZE; /* sbz */
  631.   pCentralHeader->lSize = bytes;
  632.  
  633.   if (noisy)
  634.     printf(" (%ld bytes security)", bytes);
  635.  
  636.   if(DynBuffer) free(DynBuffer);
  637. }
  638. #endif /* NTSD_EAS */
  639.  
  640.  
  641. #ifdef USE_EF_UT_TIME
  642.  
  643. #define EB_L_UT_SIZE    (EB_HEADSIZE + EB_UT_LEN(3))
  644. #define EB_C_UT_SIZE    (EB_HEADSIZE + EB_UT_LEN(1))
  645.  
  646. local int GetExtraTime(struct zlist far *z, iztimes *z_utim)
  647. {
  648.   char *eb_l_ptr;
  649.   char *eb_c_ptr;
  650.  
  651.   if(z->ext)
  652.     eb_l_ptr = realloc(z->extra, (z->ext + EB_L_UT_SIZE));
  653.   else
  654.     eb_l_ptr = malloc(EB_L_UT_SIZE);
  655.  
  656.   if (eb_l_ptr == NULL)
  657.     return ZE_MEM;
  658.  
  659.   if(z->cext)
  660.     eb_c_ptr = realloc(z->cextra, (z->cext + EB_C_UT_SIZE));
  661.   else
  662.     eb_c_ptr = malloc(EB_C_UT_SIZE);
  663.  
  664.   if (eb_c_ptr == NULL)
  665.     return ZE_MEM;
  666.  
  667.   z->extra = eb_l_ptr;
  668.   eb_l_ptr += z->ext;
  669.   z->ext += EB_L_UT_SIZE;
  670.  
  671.   eb_l_ptr[0]  = 'U';
  672.   eb_l_ptr[1]  = 'T';
  673.   eb_l_ptr[2]  = EB_UT_LEN(3);          /* length of data part of e.f. */
  674.   eb_l_ptr[3]  = 0;
  675.   eb_l_ptr[4]  = EB_UT_FL_MTIME | EB_UT_FL_ATIME | EB_UT_FL_CTIME;
  676.   eb_l_ptr[5]  = (char)(z_utim->mtime);
  677.   eb_l_ptr[6]  = (char)(z_utim->mtime >> 8);
  678.   eb_l_ptr[7]  = (char)(z_utim->mtime >> 16);
  679.   eb_l_ptr[8]  = (char)(z_utim->mtime >> 24);
  680.   eb_l_ptr[9]  = (char)(z_utim->atime);
  681.   eb_l_ptr[10] = (char)(z_utim->atime >> 8);
  682.   eb_l_ptr[11] = (char)(z_utim->atime >> 16);
  683.   eb_l_ptr[12] = (char)(z_utim->atime >> 24);
  684.   eb_l_ptr[13] = (char)(z_utim->ctime);
  685.   eb_l_ptr[14] = (char)(z_utim->ctime >> 8);
  686.   eb_l_ptr[15] = (char)(z_utim->ctime >> 16);
  687.   eb_l_ptr[16] = (char)(z_utim->ctime >> 24);
  688.  
  689.   z->cextra = eb_c_ptr;
  690.   eb_c_ptr += z->cext;
  691.   z->cext += EB_C_UT_SIZE;
  692.  
  693.   memcpy(eb_c_ptr, eb_l_ptr, EB_C_UT_SIZE);
  694.   eb_c_ptr[EB_LEN] = EB_UT_LEN(1);
  695.  
  696.   return ZE_OK;
  697. }
  698.  
  699. #endif /* USE_EF_UT_TIME */
  700.  
  701.  
  702.  
  703. int set_extra_field(z, z_utim)
  704.   struct zlist far *z;
  705.   iztimes *z_utim;
  706.   /* create extra field and change z->att if desired */
  707. {
  708.  
  709. #ifdef NTSD_EAS
  710.   if(ZipIsWinNT()) {
  711.     /* store SECURITY_DECRIPTOR data in local header, and size only in central headers */
  712.     GetSD(z->name, &z->extra, &z->ext, &z->cextra, &z->cext);
  713.   }
  714. #endif /* NTSD_EAS */
  715.  
  716. #ifdef USE_EF_UT_TIME
  717.   /* store extended time stamps in both headers */
  718.   return GetExtraTime(z, z_utim);
  719. #else /* !USE_EF_UT_TIME */
  720.   return ZE_OK;
  721. #endif /* ?USE_EF_UT_TIME */
  722. }
  723.  
  724. int deletedir(d)
  725. char *d;                /* directory to delete */
  726. /* Delete the directory *d if it is empty, do nothing otherwise.
  727.    Return the result of rmdir(), delete(), or system().
  728.    For VMS, d must be in format [x.y]z.dir;1  (not [x.y.z]).
  729.  */
  730. {
  731.     return rmdir(d);
  732. }
  733.  
  734. #endif /* !UTIL */
  735.