📄 tanunz.c
字号:
free(buildpath); buildpath = end = (char *)NULL; return MPN_OK; }/*--------------------------------------------------------------------------- APPEND_NAME: assume the path component is the filename; append it and return without checking for existence. ---------------------------------------------------------------------------*/ if (FUNCTION == APPEND_NAME) { Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp))); if (!uO.rflag /* Do not add extension if asked */ && parsename(pathcomp, fname, ext)) { fnamelen = strlen(fname); extlen = strlen(ext); if (fnamelen+extlen > MAXFILEPARTLEN) { /* Doesn't fit. Best approx is to use up to three characters from extension and place these on the end of as much of the start of the filename part as possible. */ if (extlen > EXTENSION_MAX) extlen = EXTENSION_MAX; trunclen = MAXFILEPARTLEN - extlen; ptr = fname; for (i=0; i < trunclen; i++) *end++ = *ptr++; ptr = ext; for (i=0; i < extlen; i++) *end++ = *ptr++; *end = '\0'; /* mark end of string */ } else { /* Just join parts end to end */ ptr = fname; while ((*end = *ptr++) != '\0') ++end; ptr = ext; while ((*end = *ptr++) != '\0') ++end; } } else while ((*end = *pathcomp++) != '\0') ++end; 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 (tmproot[rootlen-1] == TANDEM_DELIMITER) { tmproot[--rootlen] = '\0'; } if (rootlen > 0 && (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; } } tmproot[rootlen++] = TANDEM_DELIMITER; 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() *//********************//* Function mkdir() *//********************/int mkdir(path, mode)const char *path; /* both */mode_t mode; /* ignored *//* * returns: 0 - successful * -1 - failed (errno not set, however) */{ return 0;}/****************************//* 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; ush z_uidgid[2]; unsigned eb_izux_flg; nsk_file_attrs *znsk_attr; short err; unsigned short len; #define alist_items 1 #define vlist_bytes 2 short alist[alist_items]={42 }; unsigned short vlist[alist_items]; short extra, *err_item=&extra; char nsk_work[FILENAME_MAX + 1], *nsk_fname=&nsk_work[0]; fclose(G.outfile); /* Set up Tandem specific file information if present */ znsk_attr = ef_scan_for_tandem(G.extra_field, G.lrec.extra_field_length); /* Currently we do not create 'proper' Tandem files in unzip - we only */ /* create unstructured (180) or edit (101) files. This code allows */ /* some limited support for restoration of Tandem file attributes */ if (znsk_attr != NULL) { /* Reset File Code */ if (!uO.bflag && !G.pInfo->textmode && znsk_attr->filetype == NSK_UNSTRUCTURED) { /* leave type 101 files alone */ vlist[0] = znsk_attr->filecode; /* Note that FILE_ALTERLIST_ expect uppercase names and that */ /* G.lrec.filename_length is the length of original zipped filename */ /* not any 'rename' name. Need to re call strlen and upshift */ len = strlen(G.filename); err = STRING_UPSHIFT_(G.filename, len, nsk_fname, len); err = FILE_ALTERLIST_(nsk_fname, len, alist, alist_items, vlist, vlist_bytes, , err_item); } }/*--------------------------------------------------------------------------- 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.t3) : NULL),#else &(zt.t3),#endif z_uidgid) : 0); if (eb_izux_flg & EB_UT_FL_MTIME) { TTrace((stderr, "\nclose_outfile: Unix e.f. modif. time = %ld\n", zt.t3.mtime)); } else { zt.t3.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.t3.atime)); } else { zt.t3.atime = zt.t3.mtime; TTrace((stderr, "\nclose_outfile: modification/access times = %ld\n", zt.t3.mtime)); }/*--------------------------------------------------------------------------- Change the file's last modified time to that stored in the zipfile. Not sure how (yet) or whether it's a good idea to set the last open time ---------------------------------------------------------------------------*/ 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. ---------------------------------------------------------------------------*/#ifndef NO_CHMOD if (chmod(G.filename, 0xffff & G.pInfo->file_attr)) perror("chmod (file attributes) error");#endif/*--------------------------------------------------------------------------- if -X option was specified and we have UID/GID info, restore it this must come after the file security and modtimes changes - since once we have secured the file to somebody else we cannot access it again. ---------------------------------------------------------------------------*/ 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])); } }} /* end function close_outfile() */#ifndef SFX/************************//* Function version() *//************************/void version(__G) __GDEF{ /* Pyramid, NeXT have problems with huge macro expansion, too: no Info() */ sprintf((char *)slide, LoadFarString(CompiledWith), "C ", "T9255D44 - (16OCT98)", "NonStop ", "(Tandem/NSK)",#ifdef __DATE__ " on ", __DATE__#else "", ""#endif ); (*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 + -