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

📄 unix.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 2 页
字号:
    t->mtime = s.st_mtime;    t->ctime = t->mtime;   /* best guess, (s.st_ctime: last status change!!) */  }  return unix2dostime(&s.st_mtime);}#ifndef QLZIP /* QLZIP Unix2QDOS cross-Zip supplies an extended variant */int set_extra_field(z, z_utim)  struct zlist far *z;  iztimes *z_utim;  /* store full data in local header but just modification time stamp info     in central header */{  struct stat s;  char *name;  int len = strlen(z->name);  /* For the full sized UT local field including the UID/GID fields, we   * have to stat the file again. */  if ((name = malloc(len + 1)) == NULL) {    ZIPERR(ZE_MEM, "set_extra_field");  }  strcpy(name, z->name);  if (name[len - 1] == '/')    name[len - 1] = '\0';  /* not all systems allow stat'ing a file with / appended */  if (LSSTAT(name, &s)) {    free(name);    return ZE_OPEN;  }  free(name);#define EB_L_UT_SIZE    (EB_HEADSIZE + EB_UT_LEN(2))#define EB_C_UT_SIZE    (EB_HEADSIZE + EB_UT_LEN(1))#define EB_L_UX2_SIZE   (EB_HEADSIZE + EB_UX2_MINLEN)#define EB_C_UX2_SIZE   EB_HEADSIZE#define EF_L_UNIX_SIZE  (EB_L_UT_SIZE + EB_L_UX2_SIZE)#define EF_C_UNIX_SIZE  (EB_C_UT_SIZE + EB_C_UX2_SIZE)  if ((z->extra = (char *)malloc(EF_L_UNIX_SIZE)) == NULL)    return ZE_MEM;  if ((z->cextra = (char *)malloc(EF_C_UNIX_SIZE)) == NULL)    return ZE_MEM;  z->extra[0]  = 'U';  z->extra[1]  = 'T';  z->extra[2]  = (char)EB_UT_LEN(2);    /* length of data part of local e.f. */  z->extra[3]  = 0;  z->extra[4]  = EB_UT_FL_MTIME | EB_UT_FL_ATIME;    /* st_ctime != creation */  z->extra[5]  = (char)(s.st_mtime);  z->extra[6]  = (char)(s.st_mtime >> 8);  z->extra[7]  = (char)(s.st_mtime >> 16);  z->extra[8]  = (char)(s.st_mtime >> 24);  z->extra[9]  = (char)(s.st_atime);  z->extra[10] = (char)(s.st_atime >> 8);  z->extra[11] = (char)(s.st_atime >> 16);  z->extra[12] = (char)(s.st_atime >> 24);  z->extra[13] = 'U';  z->extra[14] = 'x';  z->extra[15] = (char)EB_UX2_MINLEN;   /* length of data part of local e.f. */  z->extra[16] = 0;  z->extra[17] = (char)(s.st_uid);  z->extra[18] = (char)(s.st_uid >> 8);  z->extra[19] = (char)(s.st_gid);  z->extra[20] = (char)(s.st_gid >> 8);  z->ext = EF_L_UNIX_SIZE;  memcpy(z->cextra, z->extra, EB_C_UT_SIZE);  z->cextra[EB_LEN] = (char)EB_UT_LEN(1);  memcpy(z->cextra+EB_C_UT_SIZE, z->extra+EB_L_UT_SIZE, EB_C_UX2_SIZE);  z->cextra[EB_LEN+EB_C_UT_SIZE] = 0;  z->cext = EF_C_UNIX_SIZE;#if 0  /* UID/GID presence is now signaled by central EF_IZUNIX2 field ! */  /* lower-middle external-attribute byte (unused until now):   *   high bit        => (have GMT mod/acc times) >>> NO LONGER USED! <<<   *   second-high bit => have Unix UID/GID info   * NOTE: The high bit was NEVER used in any official Info-ZIP release,   *       but its future use should be avoided (if possible), since it   *       was used as "GMT mod/acc times local extra field" flags in Zip beta   *       versions 2.0j up to 2.0v, for about 1.5 years.   */  z->atx |= 0x4000;#endif /* never */  return ZE_OK;}#endif /* !QLZIP */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]). */{# ifdef NO_RMDIR    /* code from Greg Roelofs, who horked it from Mark Edwards (unzip) */    int r, len;    char *s;              /* malloc'd string for system command */    len = strlen(d);    if ((s = malloc(len + 34)) == NULL)      return 127;    sprintf(s, "IFS=\" \t\n\" /bin/rmdir %s 2>/dev/null", d);    r = system(s);    free(s);    return r;# else /* !NO_RMDIR */    return rmdir(d);# endif /* ?NO_RMDIR */}#endif /* !UTIL *//******************************//*  Function version_local()  *//******************************/#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__386BSD__) || \    defined(__OpenBSD__) || defined(__bsdi__)#include <sys/param.h> /* for the BSD define *//* if we have something newer than NET/2 we'll use uname(3) */#if (BSD > 199103)#include <sys/utsname.h>#endif /* BSD > 199103 */#endif /* __{Net,Free,Open,386}BSD__ || __bsdi__ */void version_local(){#ifdef __GNUC__#  ifdef NX_CURRENT_COMPILER_RELEASE    char compiler_name[80];#  endif#else#  if (defined( __SUNPRO_C))    char compiler_name[33];#  else#    if (defined( __HP_cc))    char compiler_name[33];#    else#      if (defined( __DECC_VER))    char compiler_name[33];    int compiler_typ;#      else#        if ((defined(CRAY) || defined(cray)) && defined(_RELEASE))    char compiler_name[40];#        endif#      endif#    endif#  endif#endif#ifdef BSD# if (BSD > 199103)    struct utsname u;    char os_name[40];# else# if defined(__NETBSD__))    static ZCONST char *netbsd[] = { "_ALPHA", "", "A", "B" };    char os_name[40];# endif /* __NETBSD__ */# endif /* BSD > 199103 */#else /* !BSD */#if ((defined(CRAY) || defined(cray)) && defined(_UNICOS))    char os_name[40];#endif /* (CRAY && defined(_UNICOS)) */#endif /* ?BSD *//* Define the compiler name and version string */#ifdef __GNUC__#  ifdef NX_CURRENT_COMPILER_RELEASE    sprintf(compiler_name, "NeXT DevKit %d.%02d (gcc " __VERSION__ ")",        NX_CURRENT_COMPILER_RELEASE/100, NX_CURRENT_COMPILER_RELEASE%100);#    define COMPILER_NAME compiler_name#  else#    define COMPILER_NAME "gcc " __VERSION__#  endif#else /* !__GNUC__ */#  if defined(__SUNPRO_C)    sprintf( compiler_name, "Sun C version %x", __SUNPRO_C);#    define COMPILER_NAME compiler_name#  else#    if (defined( __HP_cc))    if ((__HP_cc% 100) == 0)    {      sprintf( compiler_name, "HP C version A.%02d.%02d",       (__HP_cc/ 10000), ((__HP_cc% 10000)/ 100));    }    else    {      sprintf( compiler_name, "HP C version A.%02d.%02d.%02d",       (__HP_cc/ 10000), ((__HP_cc% 10000)/ 100), (__HP_cc% 100));    }#      define COMPILER_NAME compiler_name#    else#      if (defined( __DECC_VER))    sprintf( compiler_name, "DEC C version %c%d.%d-%03d",     ((compiler_typ = (__DECC_VER / 10000) % 10) == 6 ? 'T' :     (compiler_typ == 8 ? 'S' : 'V')),     __DECC_VER / 10000000,     (__DECC_VER % 10000000) / 100000, __DECC_VER % 1000);#        define COMPILER_NAME compiler_name#      else#        if ((defined(CRAY) || defined(cray)) && defined(_RELEASE))    sprintf(compiler_name, "cc version %d", _RELEASE);#          define COMPILER_NAME compiler_name#        else#          ifdef __VERSION__#            define COMPILER_NAME "cc " __VERSION__#          else#            define COMPILER_NAME "cc"#          endif#        endif#      endif#    endif#  endif#endif /* ?__GNUC__ *//* Define the name to use for the OS we're compiling on */#if defined(sgi) || defined(__sgi)#  define OS_NAME "Silicon Graphics IRIX"#else#ifdef sun#  ifdef sparc#    ifdef __SVR4#      define OS_NAME "Sun SPARC/Solaris"#    else /* may or may not be SunOS */#      define OS_NAME "Sun SPARC"#    endif#  else#  if defined(sun386) || defined(i386)#    define OS_NAME "Sun 386i"#  else#  if defined(mc68020) || defined(__mc68020__)#    define OS_NAME "Sun 3"#  else /* mc68010 or mc68000:  Sun 2 or earlier */#    define OS_NAME "Sun 2"#  endif#  endif#  endif#else#ifdef __hpux#  define OS_NAME "HP-UX"#else#ifdef __osf__#  define OS_NAME "DEC OSF/1"#else#ifdef _AIX#  define OS_NAME "IBM AIX"#else#ifdef aiws#  define OS_NAME "IBM RT/AIX"#else#if defined(CRAY) || defined(cray)#  ifdef _UNICOS    sprintf(os_name, "Cray UNICOS release %d", _UNICOS);#    define OS_NAME os_name#  else#    define OS_NAME "Cray UNICOS"#  endif#else#if defined(uts) || defined(UTS)#  define OS_NAME "Amdahl UTS"#else#ifdef NeXT#  ifdef mc68000#    define OS_NAME "NeXTStep/black"#  else#    define OS_NAME "NeXTStep for Intel"#  endif#else#if defined(linux) || defined(__linux__)#  ifdef __ELF__#    define OS_NAME "Linux ELF"#  else#    define OS_NAME "Linux a.out"#  endif#else#ifdef MINIX#  define OS_NAME "Minix"#else#ifdef M_UNIX#  define OS_NAME "SCO Unix"#else#ifdef M_XENIX#  define OS_NAME "SCO Xenix"#else#ifdef BSD# if (BSD > 199103)#    define OS_NAME os_name    uname(&u);    sprintf(os_name, "%s %s", u.sysname, u.release);# else# ifdef __NetBSD__#   define OS_NAME os_name#   ifdef NetBSD0_8      sprintf(os_name, "NetBSD 0.8%s", netbsd[NetBSD0_8]);#   else#   ifdef NetBSD0_9      sprintf(os_name, "NetBSD 0.9%s", netbsd[NetBSD0_9]);#   else#   ifdef NetBSD1_0      sprintf(os_name, "NetBSD 1.0%s", netbsd[NetBSD1_0]);#   endif /* NetBSD1_0 */#   endif /* NetBSD0_9 */#   endif /* NetBSD0_8 */# else# ifdef __FreeBSD__#    define OS_NAME "FreeBSD 1.x"# else# ifdef __bsdi__#    define OS_NAME "BSD/386 1.0"# else# ifdef __386BSD__#    define OS_NAME "386BSD"# else#    define OS_NAME "Unknown BSD"# endif /* __386BSD__ */# endif /* __bsdi__ */# endif /* FreeBSD */# endif /* NetBSD */# endif /* BSD > 199103 */#else#ifdef __CYGWIN__#  define OS_NAME "Cygwin"#else#if defined(i686) || defined(__i686) || defined(__i686__)#  define OS_NAME "Intel 686"#else#if defined(i586) || defined(__i586) || defined(__i586__)#  define OS_NAME "Intel 586"#else#if defined(i486) || defined(__i486) || defined(__i486__)#  define OS_NAME "Intel 486"#else#if defined(i386) || defined(__i386) || defined(__i386__)#  define OS_NAME "Intel 386"#else#ifdef pyr#  define OS_NAME "Pyramid"#else#if defined(ultrix) || defined(__ultrix)#  if defined(mips) || defined(__mips)#    define OS_NAME "DEC/MIPS"#  else#  if defined(vax) || defined(__vax)#    define OS_NAME "DEC/VAX"#  else /* __alpha? */#    define OS_NAME "DEC/Alpha"#  endif#  endif#else#ifdef gould#  define OS_NAME "Gould"#else#ifdef MTS#  define OS_NAME "MTS"#else#ifdef __convexc__#  define OS_NAME "Convex"#else#ifdef __QNX__#  define OS_NAME "QNX 4"#else#ifdef __QNXNTO__#  define OS_NAME "QNX Neutrino"#else#ifdef __APPLE__#  define OS_NAME "Mac OS X"#else#  define OS_NAME "Unknown"#endif /* Apple */#endif /* QNX Neutrino */#endif /* QNX 4 */#endif /* Convex */#endif /* MTS */#endif /* Gould */#endif /* DEC */#endif /* Pyramid */#endif /* 386 */#endif /* 486 */#endif /* 586 */#endif /* 686 */#endif /* Cygwin */#endif /* BSD */#endif /* SCO Xenix */#endif /* SCO Unix */#endif /* Minix */#endif /* Linux */#endif /* NeXT */#endif /* Amdahl */#endif /* Cray */#endif /* RT/AIX */#endif /* AIX */#endif /* OSF/1 */#endif /* HP-UX */#endif /* Sun */#endif /* SGI *//* Define the compile date string */#ifdef __DATE__#  define COMPILE_DATE " on " __DATE__#else#  define COMPILE_DATE ""#endif    printf("Compiled with %s for Unix (%s)%s.\n\n",           COMPILER_NAME, OS_NAME, COMPILE_DATE);} /* end function version_local() */

⌨️ 快捷键说明

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