⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32zip.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 2 页
字号:
            return ZE_MEM;          }          strcat(strcpy(a, p), e);          if ((m = procname(a)) != ZE_OK)   /* recurse on name */          {            if (m == ZE_MISS)              zipwarn("name not matched: ", a);            else              ziperr(m, a);          }          free((zvoid *)a);        }      }      Closedir(d);    }    free((zvoid *)p);  } /* (s.st_mode & S_IFDIR) == 0) */  return ZE_OK;}char *ex2in(x, isdir, pdosflag)char *x;                /* external file name */int isdir;              /* input: x is a directory */int *pdosflag;          /* output: force MSDOS file attributes? *//* Convert the external file name to a zip file name, returning the malloc'ed   string or NULL if not enough memory. */{  char *n;              /* internal file name (malloc'ed) */  char *t;              /* shortened name */  int dosflag;  dosflag = dosify || IsFileSystemOldFAT(x);  if (!dosify && use_longname_ea && (t = GetLongPathEA(x)) != NULL)  {    x = t;    dosflag = 0;  }  /* Find starting point in name before doing malloc */  t = *x && *(x + 1) == ':' ? x + 2 : x;  while (*t == '/' || *t == '\\')    t++;  /* Strip leading "./" as well as drive letter */  while (*t == '.' && (t[1] == '/' || t[1] == '\\'))    t += 2;  /* Make changes, if any, to the copied name (leave original intact) */  for (n = t; *n; n++)    if (*n == '\\')      *n = '/';  if (!pathput)    t = last(t, PATH_END);  /* Malloc space for internal name and copy it */  if ((n = malloc(strlen(t) + 1)) == NULL)    return NULL;  strcpy(n, t);  if (dosify)    msname(n);  /* Returned malloc'ed name */  if (pdosflag)    *pdosflag = dosflag;  return n;}char *in2ex(n)char *n;                /* internal file name *//* Convert the zip file name to an external file name, returning the malloc'ed   string or NULL if not enough memory. */{  char *x;              /* external file name */  if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)    return NULL;  strcpy(x, n);  return x;}void stamp(f, d)char *f;                /* name of file to change */ulg d;                  /* dos-style time to change it to *//* Set last updated and accessed time of file f to the DOS time d. */{#if defined(__TURBOC__) && !defined(__BORLANDC__)  int h;                /* file handle */  if ((h = open(f, 0)) != -1)  {    setftime(h, (struct ftime *)&d);    close(h);  }#else /* !__TURBOC__ */  struct utimbuf u;     /* argument for utime() */  /* Convert DOS time to time_t format in u.actime and u.modtime */  u.actime = u.modtime = dos2unixtime(d);  /* Set updated and accessed times of f */  utime(f, &u);#endif /* ?__TURBOC__ */}ulg filetime(f, a, n, t)char *f;                /* name of file to get info on */ulg *a;                 /* return value: file attributes */long *n;                /* return value: file size */iztimes *t;             /* return value: access, modific. and creation times *//* If file *f does not exist, return 0.  Else, return the file's last   modified date and time as an MSDOS date and time.  The date and   time is returned in a long with the date most significant to allow   unsigned integer comparison of absolute times.  Also, if a is not   a NULL pointer, store the file attributes there, with the high two   bytes being the Unix attributes, and the low byte being a mapping   of that to DOS attributes.  If n is not NULL, store the file size   there.  If t is not NULL, the file's access, modification and creation   times are stored there as UNIX time_t values.   If f is "-", use standard input as the file. If f is a device, return   a file size of -1 */{  struct stat s;        /* results of stat() */  char name[FNMAX];  int len = strlen(f), isstdin = !strcmp(f, "-");  if (f == label) {    if (a != NULL)      *a = label_mode;    if (n != NULL)      *n = -2L; /* convention for a label name */    if (t != NULL)      t->atime = t->mtime = t->ctime = label_utim;    return label_time;  }  strcpy(name, f);  if (name[len - 1] == '/')    name[len - 1] = '\0';  /* not all systems allow stat'ing a file with / appended */  if (isstdin) {    if (fstat(fileno(stdin), &s) != 0)      error("fstat(stdin)");    time((time_t *)&s.st_mtime);       /* some fstat()s return time zero */  } else if (LSSTAT(name, &s) != 0)             /* Accept about any file kind including directories              * (stored with trailing / with -r option)              */    return 0;  if (a != NULL) {    *a = ((ulg)s.st_mode << 16) | (isstdin ? 0L : (ulg)GetFileMode(name));  }  if (n != NULL)    *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;  if (t != NULL) {    t->atime = s.st_atime;    t->mtime = s.st_mtime;    t->ctime = s.st_ctime;  }  return unix2dostime((time_t *)&s.st_mtime);}#ifdef NTSD_EASlocal void GetSD(char *path, char **bufptr, size_t *size,                        char **cbufptr, size_t *csize){  unsigned char stackbuffer[NTSD_BUFFERSIZE];  unsigned long bytes = NTSD_BUFFERSIZE;  unsigned char *buffer = stackbuffer;  unsigned char *DynBuffer = NULL;  long cbytes;  PEF_NTSD_L_HEADER pLocalHeader;  PEF_NTSD_C_HEADER pCentralHeader;  VOLUMECAPS VolumeCaps;#ifndef NO_NTSD_WITH_RSXNT  /* check target volume capabilities */  if (!ZipGetVolumeCaps(path, path, &VolumeCaps) ||     !(VolumeCaps.dwFileSystemFlags & FS_PERSISTENT_ACLS)) {    return;  }  VolumeCaps.bUsePrivileges = use_privileges;  VolumeCaps.dwFileAttributes = 0; /* should set to file attributes, if possible */  if (!SecurityGet(path, &VolumeCaps, buffer, &bytes)) {    /* try to malloc the buffer if appropriate */    if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {        DynBuffer = malloc(bytes);        if(DynBuffer == NULL) return;        buffer = DynBuffer; /* switch to the new buffer and try again */        if(!SecurityGet(path, &VolumeCaps, buffer, &bytes)) {            free(DynBuffer);            return;        }    } else {        return; /* bail */    }  }#else /* NO_NTSD_WITH_RSXNT */  return; /* bail */#endif /* ?NO_NTSD_WITH_RSXNT */  /* # bytes to compress: compress type, CRC, data bytes */  cbytes = sizeof(USHORT) + sizeof(ULONG) + bytes;  /* our two possible failure points.  don't allow trashing of any data     if either fails - notice that *size and *csize don't get updated.     *bufptr leaks if malloc() was used and *cbufptr alloc fails - this     isn't relevant because it's probably indicative of a bigger problem. */  if(*size)    *bufptr = realloc(*bufptr, *size + sizeof(EF_NTSD_L_HEADER) + cbytes);  else    *bufptr = malloc(sizeof(EF_NTSD_L_HEADER) + cbytes );  if(*csize)    *cbufptr = realloc(*cbufptr, *csize + sizeof(EF_NTSD_C_HEADER));  else    *cbufptr = malloc(sizeof(EF_NTSD_C_HEADER));  if(*bufptr == NULL || *cbufptr == NULL) {    if(DynBuffer) free(DynBuffer);    return;  }  /* local header */  pLocalHeader = (PEF_NTSD_L_HEADER) (*bufptr + *size);  cbytes = memcompress((char *)(pLocalHeader + 1), cbytes,                       (char *)buffer, bytes);  *size += sizeof(EF_NTSD_L_HEADER) + cbytes;  pLocalHeader->nID = EF_NTSD;  pLocalHeader->nSize = sizeof(EF_NTSD_L_HEADER) - EB_HEADSIZE + cbytes;  pLocalHeader->lSize = bytes; /* uncompressed size */  pLocalHeader->Version = 0;  /* central header */  pCentralHeader = (PEF_NTSD_C_HEADER) (*cbufptr + *csize);  *csize += sizeof(EF_NTSD_C_HEADER);  pCentralHeader->nID = EF_NTSD;  pCentralHeader->nSize = sizeof(EF_NTSD_C_HEADER) - EB_HEADSIZE; /* sbz */  pCentralHeader->lSize = bytes;  if (noisy)    printf(" (%ld bytes security)", bytes);  if(DynBuffer) free(DynBuffer);}#endif /* NTSD_EAS */#ifdef USE_EF_UT_TIME#define EB_L_UT_SIZE    (EB_HEADSIZE + EB_UT_LEN(3))#define EB_C_UT_SIZE    (EB_HEADSIZE + EB_UT_LEN(1))local int GetExtraTime(struct zlist far *z, iztimes *z_utim){  char *eb_l_ptr;  char *eb_c_ptr;  if(z->ext)    eb_l_ptr = realloc(z->extra, (z->ext + EB_L_UT_SIZE));  else    eb_l_ptr = malloc(EB_L_UT_SIZE);  if (eb_l_ptr == NULL)    return ZE_MEM;  if(z->cext)    eb_c_ptr = realloc(z->cextra, (z->cext + EB_C_UT_SIZE));  else    eb_c_ptr = malloc(EB_C_UT_SIZE);  if (eb_c_ptr == NULL)    return ZE_MEM;  z->extra = eb_l_ptr;  eb_l_ptr += z->ext;  z->ext += EB_L_UT_SIZE;  eb_l_ptr[0]  = 'U';  eb_l_ptr[1]  = 'T';  eb_l_ptr[2]  = EB_UT_LEN(3);          /* length of data part of e.f. */  eb_l_ptr[3]  = 0;  eb_l_ptr[4]  = EB_UT_FL_MTIME | EB_UT_FL_ATIME | EB_UT_FL_CTIME;  eb_l_ptr[5]  = (char)(z_utim->mtime);  eb_l_ptr[6]  = (char)(z_utim->mtime >> 8);  eb_l_ptr[7]  = (char)(z_utim->mtime >> 16);  eb_l_ptr[8]  = (char)(z_utim->mtime >> 24);  eb_l_ptr[9]  = (char)(z_utim->atime);  eb_l_ptr[10] = (char)(z_utim->atime >> 8);  eb_l_ptr[11] = (char)(z_utim->atime >> 16);  eb_l_ptr[12] = (char)(z_utim->atime >> 24);  eb_l_ptr[13] = (char)(z_utim->ctime);  eb_l_ptr[14] = (char)(z_utim->ctime >> 8);  eb_l_ptr[15] = (char)(z_utim->ctime >> 16);  eb_l_ptr[16] = (char)(z_utim->ctime >> 24);  z->cextra = eb_c_ptr;  eb_c_ptr += z->cext;  z->cext += EB_C_UT_SIZE;  memcpy(eb_c_ptr, eb_l_ptr, EB_C_UT_SIZE);  eb_c_ptr[EB_LEN] = EB_UT_LEN(1);  return ZE_OK;}#endif /* USE_EF_UT_TIME */int set_extra_field(z, z_utim)  struct zlist far *z;  iztimes *z_utim;  /* create extra field and change z->att if desired */{#ifdef NTSD_EAS  if(ZipIsWinNT()) {    /* store SECURITY_DECRIPTOR data in local header, and size only in central headers */    GetSD(z->name, &z->extra, &z->ext, &z->cextra, &z->cext);  }#endif /* NTSD_EAS */#ifdef USE_EF_UT_TIME  /* store extended time stamps in both headers */  return GetExtraTime(z, z_utim);#else /* !USE_EF_UT_TIME */  return ZE_OK;#endif /* ?USE_EF_UT_TIME */}int deletedir(d)char *d;                /* directory to delete *//* Delete the directory *d if it is empty, do nothing otherwise.   Return the result of rmdir(), delete(), or system().   For VMS, d must be in format [x.y]z.dir;1  (not [x.y.z]). */{    return rmdir(d);}#endif /* !UTIL */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -