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

📄 theos.c

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 C
📖 第 1 页 / 共 3 页
字号:
    }/*---------------------------------------------------------------------------    APPEND_NAME:  assume the path component is the filename; append it and    return without checking for existence.  ---------------------------------------------------------------------------*/    if (FUNCTION == APPEND_NAME) {#ifdef SHORT_NAMES        char *old_end = end;#endif        Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp)));        while ((*end = *pathcomp++) != '\0') {            ++end;#ifdef SHORT_NAMES  /* truncate name at 14 characters, typically */            if ((end-old_end) > FILENAME_MAX)      /* GRR:  proper constant? */                *(end = old_end + FILENAME_MAX) = '\0';#endif            if ((end-buildpath) >= FILNAMSIZ) {                *--end = '\0';                Info(slide, 0x201, ((char *)slide,                  "checkdir warning:  path too long; truncating\n\                   %s\n                -> %s\n",                  FnFilter1(G.filename), FnFilter2(buildpath)));                return MPN_INF_TRUNC;   /* filename truncated */            }        }        strcat(buildpath, rootdisk);        Trace((stderr, "buildpath now = [%s]\n", FnFilter1(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 ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+                                        (uO.acorn_nfs_ext ? 5 : 1)))#else        if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1))#endif            == (char *)NULL)            return MPN_NOMEM;        if ((rootlen > 0) && !renamed_fullpath) {            strcpy(buildpath, rootpath);            end = buildpath + rootlen;        } else {            *buildpath = '\0';            end = buildpath;        }        Trace((stderr, "[%s]\n", FnFilter1(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) {        if (pathcomp == (char *)NULL) {            rootlen = 0;            return MPN_OK;        }        if (rootlen > 0)        /* rootpath was already set, nothing to do */            return MPN_OK;        if ((rootlen = strlen(pathcomp)) > 0) {            int prepend_slash = 0;            char *tmproot, *p;            if (*pathcomp == ':') {                preprend_slash = 1;                rootlen++;            }            if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) {                rootlen = 0;                return MPN_NOMEM;            }            if (prepend_slash)                strcpy(tmproot, "/");            else                *tmproot = '\0';            strcat(tmproot, pathcomp);            Trace((stderr, "initializing root path to [%s]\n",              FnFilter1(tmproot)));            if (tmproot[rootlen-1] == '/') {                tmproot[--rootlen] = '\0';            }            if (rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||                                !S_ISDIR(G.statbuf.st_mode)))            {   /* path does not exist */                if (!G.create_dirs /* || iswild(tmproot) */ ) {                    free(tmproot);                    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) == -1) {                    Info(slide, 1, ((char *)slide,                      "checkdir:  cannot create extraction directory: %s\n",                      FnFilter1(tmproot)));                    free(tmproot);                    rootlen = 0;                    /* path didn't exist, tried to create, and failed: */                    /* file exists, or 2+ subdir levels required */                    return MPN_ERR_SKIP;                }            }            /* split rootpath in path and disk */            if ((p = strchr(tmproot, ':')) != NULL) {                strncpy(rootdisk, p, 2);                rootdisk[2] = '\0';                *p = '\0';                rootlen = p - tmproot;            } else                rootdisk[0] = '\0';            if (rootpath[rootlen - 1] != '/') {                rootpath[rootlen++] = '/';                rootpath[rootlen] = '\0';            }            if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) {                free(tmproot);                rootlen = 0;                return MPN_NOMEM;            }            Trace((stderr, "rootpath now = [%s], rootdisk now = [%s]\n",                FnFilter1(rootpath), FnFilter2(rootdisk)));        }        return MPN_OK;    }#endif /* !SFX || SFX_EXDIR *//*---------------------------------------------------------------------------    END:  free rootpath, immediately prior to program exit.  ---------------------------------------------------------------------------*/    if (FUNCTION == END) {        Trace((stderr, "freeing rootpath\n"));        if (rootlen > 0) {            free(rootpath);            rootlen = 0;        }        return MPN_OK;    }    return MPN_INVALID; /* should never reach */} /* end function checkdir() */#ifdef MORE/**************************//* Function screenlines() *//**************************/int screenlines(){    return getpl(27) + 1;}#endif /* MORE */#if (!defined(MTS) || defined(SET_DIR_ATTRIB))static void get_extattribs OF((__GPRO__ iztimes *pzt));static int get_extattribs(__G__ pzt)    __GDEF    iztimes *pzt;{/*---------------------------------------------------------------------------    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.  ---------------------------------------------------------------------------*/#ifdef USE_EF_UT_TIME    unsigned eb_izux_flg;    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 ? pzt : NULL),#else                   pzt,#endif                   z_uidgid) : 0);    if (eb_izux_flg & EB_UT_FL_MTIME) {        TTrace((stderr, "\nget_extattribs:  Unix e.f. modif. time = %ld\n",          pzt->mtime));    } else {        pzt->mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);    }    if (eb_izux_flg & EB_UT_FL_ATIME) {        TTrace((stderr, "get_extattribs:  Unix e.f. access time = %ld\n",          pzt->atime));    } else {        pzt->atime = pzt->mtime;        TTrace((stderr, "\nget_extattribs:  modification/access times = %ld\n",          pzt->mtime));    }#else    pzt->mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);    pzt->atime = pzt->mtime;#endif}#endif /* !MTS || SET_DIR_ATTRIB */#ifndef MTS/****************************//* Function close_outfile() *//****************************/void close_outfile(__G)    /* GRR: change to return PK-style warning level */    __GDEF{    union {        iztimes t3;             /* mtime, atime, ctime */        ztimbuf t2;             /* modtime, actime */    } zt;/*---------------------------------------------------------------------------    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.  ---------------------------------------------------------------------------*/    fclose(G.outfile);    get_extattribs(__G__ &(zt.t3));    /* set the file's access and modification times */    if (utime(G.filename, &(zt.t2))) {        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"));    }/*---------------------------------------------------------------------------    Change the file permissions from default ones to those stored in the    zipfile.  ---------------------------------------------------------------------------*/    if (chmod(G.filename, 0xffff & G.pInfo->file_attr))        perror("chmod (file attributes) error");/*---------------------------------------------------------------------------    Change the file structure and set native .  ---------------------------------------------------------------------------*/    if (isv2_3()) {        chorg(G.filename, G.extra_field[9]);        chlen(G.filename,            (ush) G.extra_field[10] | ((ush) G.extra_field[11] << 8),            (ush) G.extra_field[12] | ((ush) G.extra_field[13] << 8));        chgrow(G.filename, G.extra_field[14]);    }#if OLD_THEOS_EXTRA     else if (isv2_0()) {        chorg(G.filename, G.pInfo->file_attr & 0xFF);        chlen(G.filename, v2_0extra()->reclen, v2_0extra()->keylen);        chgrow(G.filename, v2_0extra()->filegrow);    }#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 defer_dir_attribs(__G__ pd)    __GDEF    direntry **pd;{    uxdirattr *d_entry;    d_entry = (uxdirattr *)malloc(sizeof(uxdirattr) + strlen(G.filename));    *pd = (direntry *)d_entry;    if (d_entry == (uxdirattr *)NULL) {        return PK_MEM;    }    d_entry->fn = d_entry->fnbuf;    strcpy(d_entry->fn, G.filename);    d_entry->perms = G.pInfo->file_attr;    get_extattribs(__G__ &(d_entry->u.t3));    return PK_OK;} /* end function defer_dir_attribs() */int set_direc_attribs(__G__ d)    __GDEF    direntry *d;{    int errval = PK_OK;    if (utime(d->fn, &UxAtt(d)->u.t2)) {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn)));        if (!errval)            errval = PK_WARN;    }    if (chmod(d->fn, 0xffff & UxAtt(d)->perms)) {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistChmodFailed), FnFilter1(d->fn)));        /* perror("chmod (file attributes) error"); */        if (!errval)            errval = PK_WARN;    }    return errval;} /* end function set_direc_attribs() */#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{    char buf1[40];    extern char Far  CompiledWith[];    sprintf(slide, CompiledWith,        "THEOS C ","5.28", "THEOS ", "4.x", " on ", __DATE__);    (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);} /* end function version() */#endif /* !SFX */

⌨️ 快捷键说明

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