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

📄 unix.c

📁 zip压缩
💻 C
📖 第 1 页 / 共 4 页
字号:
                *--G.end = '\0';                Info(slide, 0x201, ((char *)slide,                  "checkdir warning:  path too long; truncating\n\                   %s\n                -> %s\n",                  FnFilter1(G.filename), FnFilter2(G.buildpath)));                return MPN_INF_TRUNC;   /* filename truncated */            }        }        Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath)));        /* could check for existence here, prompt for new name... */        return MPN_OK;    }/*---------------------------------------------------------------------------    INIT:  allocate and initialize buffer space for the file currently being    extracted.  If file was renamed with an absolute path, don't prepend the    extract-to path.  ---------------------------------------------------------------------------*//* GRR:  for VMS and TOPS-20, add up to 13 to strlen */    if (FUNCTION == INIT) {        Trace((stderr, "initializing buildpath to "));#ifdef ACORN_FTYPE_NFS        if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+                                          (uO.acorn_nfs_ext ? 5 : 1)))#else        if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+1))#endif            == (char *)NULL)            return MPN_NOMEM;        if ((G.rootlen > 0) && !G.renamed_fullpath) {            strcpy(G.buildpath, G.rootpath);            G.end = G.buildpath + G.rootlen;        } else {            *G.buildpath = '\0';            G.end = G.buildpath;        }        Trace((stderr, "[%s]\n", FnFilter1(G.buildpath)));        return MPN_OK;    }/*---------------------------------------------------------------------------    ROOT:  if appropriate, store the path in rootpath and create it if    necessary; else assume it's a zipfile member and return.  This path    segment gets used in extracting all members from every zipfile specified    on the command line.  ---------------------------------------------------------------------------*/#if (!defined(SFX) || defined(SFX_EXDIR))    if (FUNCTION == ROOT) {        Trace((stderr, "initializing root path to [%s]\n",          FnFilter1(pathcomp)));        if (pathcomp == (char *)NULL) {            G.rootlen = 0;            return MPN_OK;        }        if (G.rootlen > 0)      /* rootpath was already set, nothing to do */            return MPN_OK;        if ((G.rootlen = strlen(pathcomp)) > 0) {            char *tmproot;            if ((tmproot = (char *)malloc(G.rootlen+2)) == (char *)NULL) {                G.rootlen = 0;                return MPN_NOMEM;            }            strcpy(tmproot, pathcomp);            if (tmproot[G.rootlen-1] == '/') {                tmproot[--G.rootlen] = '\0';            }            if (G.rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||                                  !S_ISDIR(G.statbuf.st_mode)))            {   /* path does not exist */                if (!G.create_dirs /* || iswild(tmproot) */ ) {                    free(tmproot);                    G.rootlen = 0;                    /* skip (or treat as stored file) */                    return MPN_INF_SKIP;                }                /* create the directory (could add loop here scanning tmproot                 * to create more than one level, but why really necessary?) */                if (mkdir(tmproot, 0777) == -1) {                    Info(slide, 1, ((char *)slide,                      "checkdir:  cannot create extraction directory: %s\n",                      FnFilter1(tmproot)));                    free(tmproot);                    G.rootlen = 0;                    /* path didn't exist, tried to create, and failed: */                    /* file exists, or 2+ subdir levels required */                    return MPN_ERR_SKIP;                }            }            tmproot[G.rootlen++] = '/';            tmproot[G.rootlen] = '\0';            if ((G.rootpath = (char *)realloc(tmproot, G.rootlen+1)) == NULL) {                free(tmproot);                G.rootlen = 0;                return MPN_NOMEM;            }            Trace((stderr, "rootpath now = [%s]\n", FnFilter1(G.rootpath)));        }        return MPN_OK;    }#endif /* !SFX || SFX_EXDIR *//*---------------------------------------------------------------------------    END:  free rootpath, immediately prior to program exit.  ---------------------------------------------------------------------------*/    if (FUNCTION == END) {        Trace((stderr, "freeing rootpath\n"));        if (G.rootlen > 0) {            free(G.rootpath);            G.rootlen = 0;        }        return MPN_OK;    }    return MPN_INVALID; /* should never reach */} /* end function checkdir() */#ifdef NO_MKDIR/********************//* Function mkdir() *//********************/int mkdir(path, mode)    ZCONST char *path;    int mode;   /* ignored *//* * returns:   0 - successful *           -1 - failed (errno not set, however) */{    char command[FILNAMSIZ+40]; /* buffer for system() call */    /* GRR 930416:  added single quotes around path to avoid bug with     * creating directories with ampersands in name; not yet tested */    sprintf(command, "IFS=\" \t\n\" /bin/mkdir '%s' 2>/dev/null", path);    if (system(command))        return -1;    return 0;}#endif /* NO_MKDIR */#ifndef MTS/****************************//* Function close_outfile() *//****************************/void close_outfile(__G)    /* GRR: change to return PK-style warning level */    __GDEF{    iztimes zt;    ush z_uidgid[2];    unsigned eb_izux_flg;/*---------------------------------------------------------------------------    If symbolic links are supported, allocate a storage area, put the uncom-    pressed "data" in it, and create the link.  Since we know it's a symbolic    link to start with, we shouldn't have to worry about overflowing unsigned    ints with unsigned longs.  ---------------------------------------------------------------------------*/#ifdef SYMLINKS    if (G.symlnk) {        unsigned ucsize = (unsigned)G.lrec.ucsize;        char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1);        fclose(G.outfile);                      /* close "data" file... */        G.outfile = fopen(G.filename, FOPR);    /* ...and reopen for reading */        if (!linktarget || fread(linktarget, 1, ucsize, G.outfile) !=                           (int)ucsize)        {            Info(slide, 0x201, ((char *)slide,              "warning:  symbolic link (%s) failed\n", FnFilter1(G.filename)));            if (linktarget)                free(linktarget);            fclose(G.outfile);            return;        }        fclose(G.outfile);                  /* close "data" file for good... */        unlink(G.filename);                 /* ...and delete it */        linktarget[ucsize] = '\0';        if (QCOND2)            Info(slide, 0, ((char *)slide, "-> %s ", FnFilter1(linktarget)));        if (symlink(linktarget, G.filename))  /* create the real link */            perror("symlink error");        free(linktarget);        return;                             /* can't set time on symlinks */    }#endif /* SYMLINKS */    fclose(G.outfile);#ifdef QLZIP    if (G.extra_field) {        static void qlfix OF((__GPRO__ uch *ef_ptr, unsigned ef_len));        qlfix(__G__ G.extra_field, G.lrec.extra_field_length);    }#endif/*---------------------------------------------------------------------------    Convert from MSDOS-format local time and date to Unix-format 32-bit GMT    time:  adjust base year from 1980 to 1970, do usual conversions from    yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-    light savings time differences.  If we have a Unix extra field, however,    we're laughing:  both mtime and atime are ours.  On the other hand, we    then have to check for restoration of UID/GID.  ---------------------------------------------------------------------------*/    eb_izux_flg = (G.extra_field ? ef_scan_for_izux(G.extra_field,                   G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,#ifdef IZ_CHECK_TZ                   (G.tz_is_valid ? &zt : NULL),#else                   &zt,#endif                   z_uidgid) : 0);    if (eb_izux_flg & EB_UT_FL_MTIME) {        TTrace((stderr, "\nclose_outfile:  Unix e.f. modif. time = %ld\n",          zt.mtime));    } else {        zt.mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);    }    if (eb_izux_flg & EB_UT_FL_ATIME) {        TTrace((stderr, "close_outfile:  Unix e.f. access time = %ld\n",          zt.atime));    } else {        zt.atime = zt.mtime;        TTrace((stderr, "\nclose_outfile:  modification/access times = %ld\n",          zt.mtime));    }    /* if -X option was specified and we have UID/GID info, restore it */    if (uO.X_flag && eb_izux_flg & EB_UX2_VALID) {        TTrace((stderr, "close_outfile:  restoring Unix UID/GID info\n"));        if (chown(G.filename, (uid_t)z_uidgid[0], (gid_t)z_uidgid[1]))        {            if (uO.qflag)                Info(slide, 0x201, ((char *)slide,                  "warning:  cannot set UID %d and/or GID %d for %s\n",                  z_uidgid[0], z_uidgid[1], FnFilter1(G.filename)));            else                Info(slide, 0x201, ((char *)slide,                  " (warning) cannot set UID %d and/or GID %d",                  z_uidgid[0], z_uidgid[1]));        }    }    /* set the file's access and modification times */    if (utime(G.filename, (ztimbuf *)&zt)) {#ifdef AOS_VS        if (uO.qflag)            Info(slide, 0x201, ((char *)slide, "... cannot set time for %s\n",              FnFilter1(G.filename)));        else            Info(slide, 0x201, ((char *)slide, "... cannot set time"));#else        if (uO.qflag)            Info(slide, 0x201, ((char *)slide,              "warning:  cannot set times for %s\n", FnFilter1(G.filename)));        else            Info(slide, 0x201, ((char *)slide,              " (warning) cannot set times"));#endif /* ?AOS_VS */    }/*---------------------------------------------------------------------------    Change the file permissions from default ones to those stored in the    zipfile.  ---------------------------------------------------------------------------*/#ifndef NO_CHMOD    if (chmod(G.filename, 0xffff & G.pInfo->file_attr))        perror("chmod (file attributes) error");#endif} /* end function close_outfile() */#endif /* !MTS */#ifdef SET_DIR_ATTRIB/* messages of code for setting directory attributes */static ZCONST char Far DirlistUidGidFailed[] =  "warning:  cannot set UID %d and/or GID %d for %s\n";static ZCONST char Far DirlistUtimeFailed[] =  "warning:  cannot set modification, access times for %s\n";#  ifndef NO_CHMOD  static ZCONST char Far DirlistChmodFailed[] =    "warning:  cannot set permissions for %s\n";#  endifint set_direc_attribs(__G__ d)    __GDEF    dirtime *d;{    int errval = PK_OK;    if (d->have_uidgid &&        chown(d->fn, (uid_t)d->uidgid[0], (gid_t)d->uidgid[1]))    {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistUidGidFailed),          d->uidgid[0], d->uidgid[1], FnFilter1(d->fn)));        if (!errval)            errval = PK_WARN;    }    if (utime(d->fn, &d->u.t2)) {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn)));        if (!errval)            errval = PK_WARN;    }#ifndef NO_CHMOD    if (chmod(d->fn, 0xffff & d->perms)) {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistChmodFailed), FnFilter1(d->fn)));        /* perror("chmod (file attributes) error"); */        if (!errval)            errval = PK_WARN;    }#endif /* !NO_CHMOD */    return errval;} /* end function set_directory_attributes() */#endif /* SET_DIR_ATTRIB */#ifdef TIMESTAMP/***************************//*  Function stamp_file()  *//***************************/int stamp_file(fname, modtime)    ZCONST char *fname;    time_t modtime;{    ztimbuf tp;    tp.modtime = tp.actime = modtime;    return (utime(fname, &tp));} /* end function stamp_file() */#endif /* TIMESTAMP */#ifndef SFX/************************//*  Function version()  *//************************/void version(__G)    __GDEF{#if (defined(__GNUC__) && defined(NX_CURRENT_COMPILER_RELEASE))    char cc_namebuf[40];    char cc_versbuf[40];#else

⌨️ 快捷键说明

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