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

📄 aosvs.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <dirent.h>#include <time.h>#include "zip.h"#include <paru.h>                 /* parameter definitions */#include <sys_calls.h>            /* AOS/VS system call interface */#include <packets/filestatus.h>   /* AOS/VS ?FSTAT packet defs */#ifndef UTIL            /* AOS/VS specific fileio code not needed for UTILs */#define MATCH shmatch#define PAD 0#define PATH_END ':'/* * could probably avoid the union - * all are same size & we're going to assume this */typedef union zvsfstat_stru{     P_FSTAT        norm_fstat_packet;      /* normal fstat packet */     P_FSTAT_DIR    dir_fstat_packet;       /* DIR/CPD fstat packet */     P_FSTAT_UNIT   unit_fstat_packet;      /* unit (device) fstat packet */     P_FSTAT_IPC    ipc_fstat_packet;       /* IPC file fstat packet */} ZVSFSTAT_STRU;typedef struct zextrafld{     char           extra_header_id[2]; /* set to VS - in theory, an int */     char           extra_data_size[2]; /* size of rest, in Intel little-endian order */     char           extra_sentinel[4];  /* set to FCI w/ trailing null */     unsigned char  extra_rev;          /* set to 10 for rev 1.0 */     ZVSFSTAT_STRU  fstat_packet;       /* the fstat packet */     char           aclbuf[$MXACL];     /* raw ACL, or link-resolution name */} ZEXTRAFLD;#define ZEXTRA_HEADID   "VS"#define ZEXTRA_SENTINEL "FCI"#define ZEXTRA_REV      (unsigned char) 10local ZEXTRAFLD   zzextrafld;         /* buffer for extra field containing                                         ?FSTAT packet & ACL buffer */local char        zlinkres[$MXPL];    /* buf for link resolution contents */local char        znamebuf[$MXPL];    /* buf for AOS/VS filename */static char     vsnamebuf[$MXPL];static char     uxnamebuf[FNMAX];static P_FSTAT  vsfstatbuf;local ulg label_time = 0;local ulg label_mode = 0;local time_t label_utim = 0;/* Local functions */local char *readd OF((DIR *));char *readd(d)DIR *d;                 /* directory stream to read from *//* Return a pointer to the next name in the directory stream d, or NULL if   no more entries or an error occurs. */{  struct dirent *e;  e = readdir(d);  return e == NULL ? (char *) NULL : e->d_name;}int procname(n)char *n;                /* name to process *//* Process a name or sh expression to operate on (or exclude).  Return   an error code in the ZE_ class. */{  char *a;              /* path and name for recursion */  DIR *d;               /* directory stream from opendir() */  char *e;              /* pointer to name from readd() */  int m;                /* matched flag */  char *p;              /* path for recursion */  struct stat s;        /* result of stat() */  struct zlist far *z;  /* steps through zfiles list */  if (strcmp(n, "-") == 0)   /* if compressing stdin */    return newname(n, 0);  else if (LSSTAT(n, &s))  {    /* Not a file or directory--search for shell expression in zip file */    p = ex2in(n, 0, (int *)NULL);       /* shouldn't affect matching chars */    m = 1;    for (z = zfiles; z != NULL; z = z->nxt) {      if (MATCH(p, z->iname))      {        z->mark = pcount ? filter(z->zname) : 1;        if (verbose)            fprintf(mesg, "zip diagnostic: %scluding %s\n",               z->mark ? "in" : "ex", z->name);        m = 0;      }    }    free((zvoid *)p);    return m ? ZE_MISS : ZE_OK;  }  /* Live name--use if file, recurse if directory */  if ((s.st_mode & S_IFDIR) == 0)  {    /* add or remove name of file */    if ((m = newname(n, 0)) != ZE_OK)      return m;  } else {    /* Add trailing / to the directory name */    if ((p = malloc(strlen(n)+2)) == NULL)      return ZE_MEM;    if (strcmp(n, ".") == 0) {      *p = '\0';  /* avoid "./" prefix and do not create zip entry */    } else {      strcpy(p, n);      a = p + strlen(p);      if (a[-1] != '/')        strcpy(a, "/");      if (dirnames && (m = newname(p, 1)) != ZE_OK) {        free((zvoid *)p);        return m;      }    }    /* recurse into directory */    if (recurse && (d = opendir(n)) != NULL)    {      while ((e = readd(d)) != NULL) {        if (strcmp(e, ".") && strcmp(e, ".."))        {          if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)          {            closedir(d);            free((zvoid *)p);            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 *strlower(s)char *s;                /* string to convert *//* Convert all uppercase letters to lowercase in string s */{  char *p;              /* scans string */  for (p = s; *p; p++)    if (*p >= 'A' && *p <= 'Z')      *p += 'a' - 'A';  return s;}char *strupper(s)char *s;                /* string to convert *//* Convert all lowercase letters to uppercase in string s */{  char *p;              /* scans string */  for (p = s; *p; p++)    if (*p >= 'a' && *p <= 'z')      *p -= 'a' - 'A';  return s;}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; /* default for non-DOS and non-OS/2 */  /* Find starting point in name before doing malloc */  for (t = x; *t == '/'; t++)    ;  if (*t == '=')                /* AOS/VS for ./ */    t++;  else if (*t == ':')           /* AOS/VS for / */    t++;  if (!pathput)    t = last(t, PATH_END);  if (*t == '^')        /* AOS/VS for ../ */  {    if ((n = malloc(strlen(t) + 3)) == NULL)      return NULL;    strcpy(n, "../");    strcpy(n + 3, t + 1);  }  else if (*t == '@')   /* AOS/VS for :PER:, kind of like /dev/ */  {    if ((n = malloc(strlen(t) + 5)) == NULL)      return NULL;    strcpy(n, "/PER/");    strcpy(n + 5, t + 1);  }  else  {    if ((n = malloc(strlen(t) + 1)) == NULL)      return NULL;    strcpy(n, t);  }  /* now turn AOS/VS dir separators (colons) into slashes */  for (t = n;  *t != '\0';  t++)    if (*t == ':')      *t = '/';  /*   * Convert filename to uppercase (for correct matching).   * (It may make more sense to patch the matching code, since   * we may want those filenames in uppercase on the target system,   * but this seems better at present.  If we're converting, uppercase   * also seems to make sense.)   */  strupper(n);  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. */{  time_t u[2];          /* argument for utime() */  /* Convert DOS time to time_t format in u */  u[0] = u[1] = dos2unixtime(d);  utime(f, u);}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);  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 (strcmp(f, "-") == 0) {    if (fstat(fileno(stdin), &s) != 0)      error("fstat(stdin)");  } 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) | !(s.st_mode & S_IWRITE);    if ((s.st_mode & S_IFDIR) != 0) {      *a |= MSDOS_DIR_ATTR;    }  }  if (n != NULL)    *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;  if (t != NULL) {

⌨️ 快捷键说明

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