?? vmmvs.c
字號:
/* Copyright (c) 1990-2002 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html*//*--------------------------------------------------------------------------- vmmvs.c (for both VM/CMS and MVS) Contains: vmmvs_open_infile() open_outfile() close_outfile() close_infile() getVMMVSexfield() do_wild() mapattr() mapname() checkdir() check_for_newer() stat() version() ---------------------------------------------------------------------------*/#define __VMMVS_C /* identifies this source module */#define UNZIP_INTERNAL#include "unzip.h"/********************************//* Function vmmvs_open_infile() *//********************************/FILE *vmmvs_open_infile(__G) __GDEF{ FILE *fzip; G.tempfn = NULL; fzip = fopen(G.zipfn, FOPR);#if 0 /* Let's try it without the convert for a while -- RG Hartwig */ if ((fzip = fopen(G.zipfn,"rb,recfm=fb")) == NULL) { size_t cnt; char *buf; FILE *in, *out; if ((buf = (char *)malloc(32768)) == NULL) return NULL; if ((G.tempfn = tmpnam(NULL)) == NULL) return NULL; if ((in = fopen(G.zipfn,"rb")) != NULL && (out = fopen(G.tempfn,"wb,recfm=fb,lrecl=1")) != NULL) { Trace((stdout,"Converting ZIP file to fixed record format...\n")); while (!feof(in)) { cnt = fread(buf,1,32768,in); if (cnt) fwrite(buf,1,cnt,out); } } else { free(buf); fclose(out); fclose(in); return NULL; } free(buf); fclose(out); fclose(in); fzip = fopen(G.tempfn,"rb,recfm=fb"); if (fzip == NULL) return NULL; /* Update the G.ziplen value since it might have changed after the reformatting copy. */ fseek(fzip,0L,SEEK_SET); fseek(fzip,0L,SEEK_END); G.ziplen = ftell(fzip); }#endif return fzip;}/***************************//* Function open_outfile() *//***************************/int open_outfile(__G) /* return 1 if fail */ __GDEF{ char type[100]; char *mode = NULL;#ifdef MVS /* Check if the output file already exists and do not overwrite its DCB */ char basefilename[PATH_MAX], *p; FILE *exists; /* Get the base file name, without any member name */ strcpy(basefilename, G.filename); if ((p = strchr(basefilename, '(')) != NULL) { if (basefilename[0] == '\'') *p++ = '\''; *p = '\0'; } exists = fopen(basefilename, FOPR); if (exists) { if (G.pInfo->textmode) mode = FOPWTE; /* Text file, existing */ else mode = FOPWE; /* Binary file, existing */ fclose(exists); } else /* continued on next line */#endif /* MVS */ if (G.pInfo->textmode) { if (mode == NULL) mode = FOPWT; } else if (G.lrec.extra_field_length > 0 && G.extra_field != NULL) { unsigned lef_len = (unsigned)(G.lrec.extra_field_length); uch *lef_buf = G.extra_field; while (lef_len > EB_HEADSIZE) { unsigned eb_id = makeword(&lef_buf[EB_ID]); unsigned eb_dlen = makeword(&lef_buf[EB_LEN]); if (eb_dlen > (lef_len - EB_HEADSIZE)) { /* Discovered some extra field inconsistency! */ TTrace((stderr, "open_outfile: block length %u > rest lef_size %u\n", eb_dlen, lef_len - EB_HEADSIZE)); break; } if ((eb_id == EF_VMCMS || eb_id == EF_MVS) && (getVMMVSexfield(type, lef_buf, eb_dlen) > 0)) { mode = type; break; } /* Skip this extra field block */ lef_buf += (eb_dlen + EB_HEADSIZE); lef_len -= (eb_dlen + EB_HEADSIZE); } } if (mode == NULL) mode = FOPW; Trace((stderr, "Output file='%s' opening with '%s'\n", G.filename, mode)); if ((G.outfile = fopen(G.filename, mode)) == NULL) { Info(slide, 0x401, ((char *)slide, "\nerror: cannot create %s\n", FnFilter1(G.filename))); Trace((stderr, "error %d: '%s'\n", errno, strerror(errno))); return 1; } return 0;} /* end function open_outfile() *//****************************//* Function close_outfile() *//****************************/void close_outfile(__G) __GDEF{ fclose(G.outfile);} /* end function close_outfile() *//***************************//* Function close_infile() *//***************************/void close_infile(__G) __GDEF{ fclose(G.zipfd); /* If we're working from a temp file, erase it now */ if (G.tempfn) remove(G.tempfn);} /* end function close_infile() *//******************************//* Function getVMMVSexfield() *//******************************/extent getVMMVSexfield(type, ef_block, datalen) char *type; uch *ef_block; unsigned datalen;{ fldata_t *fdata = (fldata_t *) &ef_block[4]; if (datalen < sizeof(fldata_t)) return 0; strcpy(type, "w"); strcat(type, fdata->__openmode == __TEXT ? "" :fdata->__openmode == __BINARY ? "b" :fdata->__openmode == __RECORD ? "b,type=record" : ""); strcat(type, ",recfm="); strcat(type, fdata->__recfmF? "F" :fdata->__recfmV? "V" :fdata->__recfmU? "U" : "?"); if (fdata->__recfmBlk) strcat(type, "B"); if (fdata->__recfmS) strcat(type, "S"); if (fdata->__recfmASA) strcat(type, "A"); if (fdata->__recfmM) strcat(type, "M"); sprintf(type+strlen(type), ",lrecl=%ld", fdata->__recfmV ? fdata->__maxreclen+4 : fdata->__maxreclen);#ifdef VM_CMS /* For CMS, use blocksize for FB files only */ if (fdata->__recfmBlk) sprintf(type+strlen(type), ",blksize=%ld", fdata->__blksize);#else /* For MVS, always use blocksize */ sprintf(type+strlen(type), ",blksize=%ld", fdata->__blksize);#endif return strlen(type);} /* end function getVMMVSexfield() */#ifndef SFX/**********************//* Function do_wild() */ /* for porting: dir separator; match(ignore_case) *//**********************/char *do_wild(__G__ wld) __GDEF ZCONST char *wld; /* only used first time on a given dir */{ static int First = 0; static char filename[256]; if (First == 0) { First = 1; strcpy( filename, wld ); return filename; } else return (char *)NULL;} /* end function do_wild() */#endif /* !SFX *//************************//* Function mapattr() *//************************/int mapattr(__G) __GDEF{ return 0;}/************************//* Function mapname() *//************************/int mapname(__G__ renamed) __GDEF int renamed;/* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - caution (truncated filename) * MPN_INF_SKIP - info "skip entry" (dir doesn't exist) * MPN_ERR_SKIP - error -> skip entry * MPN_ERR_TOOLONG - error -> path is too long * MPN_NOMEM - error (memory allocation failed) -> skip entry * [also MPN_VOL_LABEL, MPN_CREATED_DIR] */{ char newname[FILNAMSIZ], *lbar;#ifdef MVS char *pmember;#endif int name_changed = MPN_OK; if (G.pInfo->vollabel) return MPN_VOL_LABEL; /* can't set disk volume labels in CMS_MVS */#ifdef MVS /* Remove bad characters for MVS from the filename */ while ((lbar = strpbrk(G.filename, "_+-")) != NULL) { /* Must use memmove() here because data overlaps. */ /* strcpy() gives undefined behavior in this case. */ memmove(lbar, lbar+1, strlen(lbar)); name_changed = MPN_INF_TRUNC; }#endif /* Remove bad characters for MVS/CMS from the filename */ while ((lbar = strpbrk(G.filename, "()")) != NULL) { memmove(lbar, lbar+1, strlen(lbar)); name_changed = MPN_INF_TRUNC; }#ifdef VM_CMS if ((lbar = strrchr(G.filename, '/')) != NULL) { strcpy(newname, lbar+1); Trace((stderr, "File '%s' renamed to '%s'\n", G.filename, newname)); strcpy(G.filename, newname); name_changed = MPN_INF_TRUNC; }#else /* MVS */ if ((pmember = strrchr(G.filename, '/')) == NULL) pmember = G.filename; else pmember++; /* search for extension in file name */ if ((lbar = strrchr(pmember, '.')) != NULL) { *lbar++ = '\0'; strcpy(newname, pmember); strcpy(pmember, lbar); strcat(pmember, "("); strcat(pmember, newname); strcat(pmember, ")"); } /* Remove all 'internal' dots '.', to prevent false consideration as * MVS path delimiters! */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -