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

📄 qdos.c

📁 zip压缩
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (FUNCTION == APPEND_NAME) {#ifdef SHORT_NAMES        char *old_end = end;#endif        short dlen;        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 (isdirdev(buildpath))            {                dlen = 5;            }            else            {                dlen = 0;            }            if ((end-buildpath-dlen) >= 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 */            }        }        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 "));        if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1))            == (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) {        Trace((stderr, "initializing root path to [%s]\n",          FnFilter1(pathcomp)));        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) {            char *tmproot;            if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) {                rootlen = 0;                return MPN_NOMEM;            }            strcpy(tmproot, pathcomp);            if ((stat(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, 0777) == -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;                }            }            if (tmproot[rootlen-1] == '/' || tmproot[rootlen-1] == '_') {                tmproot[--rootlen] = '\0';            }            tmproot[rootlen++] = '_';            tmproot[rootlen] = '\0';            if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) {                free(tmproot);                rootlen = 0;                return MPN_NOMEM;            }        }        Trace((stderr, "rootpath now = [%s]\n", FnFilter1(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 (rootlen > 0) {            free(rootpath);            rootlen = 0;        }        return MPN_OK;    }    return MPN_INVALID; /* should never reach */} /* end function checkdir() */static void qfix(__G__ ef_ptr, ef_len)    __GDEF    uch *ef_ptr;    unsigned ef_len;{    qdosextra qextra;    while (ef_len >= EB_HEADSIZE)    {        qdosextra   *extra = &qextra;        jbextra     *jbp   = (jbextra *)&qextra;        unsigned    eb_len = makeword(EB_LEN + ef_ptr);        if (eb_len > (ef_len - EB_HEADSIZE)) {            /* discovered some extra field inconsistency! */            Trace((stderr,              "qfix: block length %u > rest ef_size %u\n", eb_len,              ef_len - EB_HEADSIZE));            break;        }        /* Must ensure that we don't use ODD addresses here */        memcpy(&qextra, ef_ptr, sizeof(qdosextra));        switch (extra->shortid) {          case SHORTID:            if (!strncmp(extra->longid, LONGID, strlen(LONGID)))            {                if (eb_len != EXTRALEN)                    fputs("warning: invalid length in Qdos field", stderr);                if (extra->header.d_type)                {                    fs_heads(fgetchid(G.outfile), (timeout_t)-1,                             &extra->header, 14);                    G.pInfo->file_attr |= S_IXUSR;                }            }            if (!strncmp(jbp->longid, JBLONGID, strlen(JBLONGID)))            {                if (eb_len != JBEXTRALEN)                    fputs("warning: invalid length in QZ field", stderr);                if (jbp->header.d_type)                {                    fs_heads(fgetchid(G.outfile), (timeout_t)-1,                             &jbp->header, 14);                    G.pInfo->file_attr |= S_IXUSR;                }            }            break;          default:            Trace((stderr,"qfix: unknown extra field block, ID=%d\n",               extra->shortid));            break;        }        /* Skip this extra field block */        ef_ptr += (eb_len + EB_HEADSIZE);        ef_len -= (eb_len + EB_HEADSIZE);    }}#ifdef QDOS#  include <utime.h>   long timezone = 0;#endif/****************************//* Function close_outfile() *//****************************/void close_outfile(__G)    __GDEF{    iztimes zt;#ifdef USE_EF_UT_TIME    unsigned eb_izux_flg;#endif    if (G.extra_field) {        qfix(__G__ G.extra_field, G.lrec.extra_field_length);    }    fclose(G.outfile);/*---------------------------------------------------------------------------    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/*---------------------------------------------------------------------------    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    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));    }#else    zt.atime = zt.mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);#endif    /* set the file's access and modification times */    if (utime(G.filename, (struct utimbuf *)&zt)) {        Info(slide, 0x201, ((char *)slide,          "warning:  cannot set the time for %s\n", FnFilter1(G.filename)));    }} /* end function close_outfile() */#ifdef TIMESTAMP/***************************//*  Function stamp_file()  *//***************************/int stamp_file(fname, modtime)    ZCONST char *fname;    time_t modtime;{    struct utimbuf tp;    tp.modtime = tp.actime = modtime;    return (utime(fname, &tp));} /* end function stamp_file() */#endif /* TIMESTAMP */#ifndef SFX/************************//*  Function version()  *//************************/void version(__G)    __GDEF{    sprintf((char *)slide, LoadFarString(CompiledWith),           "c68", " v4.2x", "SMS/QDOS",            " on ", __DATE__, "","");    (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);} /* end function version() */#endif /* !SFX */#endif /* !FUNZIP */#if CRYPTchar *getp(__G__ m, p, n)    __GDEF    const char *m;              /* prompt for password */    char *p;                    /* return value: line input */    int n;                      /* bytes available in p[] */{    int c;                      /* one-byte buffer for read() to use */    int i;                      /* number of characters input */    char *w;                    /* warning on retry */    /* get password */    w = "";    sd_cure(getchid(0), -1);    /* enable cursor */    do {        fputs(w, stderr);       /* warning if back again */        fputs(m, stderr);       /* display prompt and flush */        fflush(stderr);        i = 0;        do {            c = getch();            if (c == 0xc2) {                if (i > 0) {                    i--; /* the `del' keys works */                    fputs("\b \b", stderr);                }            }            else if (i < n) {                p[i++] = c;     /* truncate past n */                if(c != '\n') putc('*', stderr);            }        } while (c != '\n');        putc('\n', stderr);  fflush(stderr);        w = "(line too long--try again)\n";    } while (p[i-1] != '\n');    p[i-1] = 0;                 /* terminate at newline */    sd_curs(getchid(0), -1);    /* suppress cursor */    return p;                   /* return pointer to password */} /* end function getp() */#endif /* CRYPT */

⌨️ 快捷键说明

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