?? fileio.c
字號(hào):
} else if (*pwbuf == '\0') { r = IZ_PW_CANCELALL; } return r;#else /* !CRYPT */ /* tell picky compilers to shut up about "unused variable" warnings */ pG = pG; rcnt = rcnt; pwbuf = pwbuf; size = size; zfn = zfn; efn = efn; return IZ_PW_ERROR; /* internal error; function should never get called */#endif /* ?CRYPT */} /* end function UzpPassword() *//**********************//* Function handler() *//**********************/void handler(signal) /* upon interrupt, turn on echo and exit cleanly */ int signal;{ GETGLOBALS();#if !(defined(SIGBUS) || defined(SIGSEGV)) /* add a newline if not at */ (*G.message)((zvoid *)&G, slide, 0L, 0x41); /* start of line (to stderr; */#endif /* slide[] should be safe) */ echon();#ifdef SIGBUS if (signal == SIGBUS) { Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt), "bus error")); DESTROYGLOBALS(); EXIT(PK_BADERR); }#endif /* SIGBUS */#ifdef SIGSEGV if (signal == SIGSEGV) { Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt), "segmentation violation")); DESTROYGLOBALS(); EXIT(PK_BADERR); }#endif /* SIGSEGV */ /* probably ctrl-C */ DESTROYGLOBALS();#if defined(AMIGA) && defined(__SASC) _abort();#endif EXIT(IZ_CTRLC); /* was EXIT(0), then EXIT(PK_ERR) */}#endif /* !WINDLL */#if (!defined(VMS) && !defined(CMS_MVS))#if (!defined(OS2) || defined(TIMESTAMP))#if (!defined(HAVE_MKTIME) || defined(WIN32))/* also used in amiga/filedate.c and win32/win32.c */ZCONST ush ydays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };#endif/*******************************//* Function dos_to_unix_time() */ /* used for freshening/updating/timestamps *//*******************************/time_t dos_to_unix_time(dosdatetime) ulg dosdatetime;{ time_t m_time;#ifdef HAVE_MKTIME ZCONST time_t now = time(NULL); struct tm *tm;# define YRBASE 1900 tm = localtime(&now); tm->tm_isdst = -1; /* let mktime determine if DST is in effect */ /* dissect date */ tm->tm_year = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - YRBASE); tm->tm_mon = ((int)(dosdatetime >> 21) & 0x0f) - 1; tm->tm_mday = ((int)(dosdatetime >> 16) & 0x1f); /* dissect time */ tm->tm_hour = (int)((unsigned)dosdatetime >> 11) & 0x1f; tm->tm_min = (int)((unsigned)dosdatetime >> 5) & 0x3f; tm->tm_sec = (int)((unsigned)dosdatetime << 1) & 0x3e; m_time = mktime(tm); NATIVE_TO_TIMET(m_time) /* NOP unless MSC 7.0 or Macintosh */ TTrace((stderr, " final m_time = %lu\n", (ulg)m_time));#else /* !HAVE_MKTIME */ int yr, mo, dy, hh, mm, ss;#ifdef TOPS20# define YRBASE 1900 struct tmx *tmx; char temp[20];#else /* !TOPS20 */# define YRBASE 1970 int leap; unsigned days; struct tm *tm;#if (!defined(MACOS) && !defined(RISCOS) && !defined(QDOS) && !defined(TANDEM))#ifdef WIN32 TIME_ZONE_INFORMATION tzinfo; DWORD res;#else /* ! WIN32 */#ifndef BSD4_4 /* GRR: change to !defined(MODERN) ? */#if (defined(BSD) || defined(MTS) || defined(__GO32__)) struct timeb tbp;#else /* !(BSD || MTS || __GO32__) */#ifdef DECLARE_TIMEZONE extern time_t timezone;#endif#endif /* ?(BSD || MTS || __GO32__) */#endif /* !BSD4_4 */#endif /* ?WIN32 */#endif /* !MACOS && !RISCOS && !QDOS && !TANDEM */#endif /* ?TOPS20 */ /* dissect date */ yr = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - YRBASE); mo = ((int)(dosdatetime >> 21) & 0x0f) - 1; dy = ((int)(dosdatetime >> 16) & 0x1f) - 1; /* dissect time */ hh = (int)((unsigned)dosdatetime >> 11) & 0x1f; mm = (int)((unsigned)dosdatetime >> 5) & 0x3f; ss = (int)((unsigned)dosdatetime & 0x1f) * 2;#ifdef TOPS20 tmx = (struct tmx *)malloc(sizeof(struct tmx)); sprintf (temp, "%02d/%02d/%02d %02d:%02d:%02d", mo+1, dy+1, yr, hh, mm, ss); time_parse(temp, tmx, (char *)0); m_time = time_make(tmx); free(tmx);#else /* !TOPS20 *//*--------------------------------------------------------------------------- Calculate the number of seconds since the epoch, usually 1 January 1970. ---------------------------------------------------------------------------*/ /* leap = # of leap yrs from YRBASE up to but not including current year */ leap = ((yr + YRBASE - 1) / 4); /* leap year base factor */ /* calculate days from BASE to this year and add expired days this year */ days = (yr * 365) + (leap - 492) + ydays[mo]; /* if year is a leap year and month is after February, add another day */ if ((mo > 1) && ((yr+YRBASE)%4 == 0) && ((yr+YRBASE) != 2100)) ++days; /* OK through 2199 */ /* convert date & time to seconds relative to 00:00:00, 01/01/YRBASE */ m_time = (time_t)((unsigned long)(days + dy) * 86400L + (unsigned long)hh * 3600L + (unsigned long)(mm * 60 + ss)); /* - 1; MS-DOS times always rounded up to nearest even second */ TTrace((stderr, "dos_to_unix_time:\n")); TTrace((stderr, " m_time before timezone = %lu\n", (ulg)m_time));/*--------------------------------------------------------------------------- Adjust for local standard timezone offset. ---------------------------------------------------------------------------*/#if (!defined(MACOS) && !defined(RISCOS) && !defined(QDOS) && !defined(TANDEM))#ifdef WIN32 /* account for timezone differences */ res = GetTimeZoneInformation(&tzinfo); if (res != TIME_ZONE_ID_INVALID) { m_time += 60*(tzinfo.Bias);#else /* !WIN32 */#if (defined(BSD) || defined(MTS) || defined(__GO32__))#ifdef BSD4_4 if ( (dosdatetime >= DOSTIME_2038_01_18) && (m_time < (time_t)0x70000000L) ) m_time = U_TIME_T_MAX; /* saturate in case of (unsigned) overflow */ if (m_time < (time_t)0L) /* a converted DOS time cannot be negative */ m_time = S_TIME_T_MAX; /* -> saturate at max signed time_t value */ if ((tm = localtime(&m_time)) != (struct tm *)NULL) m_time -= tm->tm_gmtoff; /* sec. EAST of GMT: subtr. */#else /* !(BSD4_4 */ ftime(&tbp); /* get `timezone' */ m_time += tbp.timezone * 60L; /* seconds WEST of GMT: add */#endif /* ?(BSD4_4 || __EMX__) */#else /* !(BSD || MTS || __GO32__) */ /* tzset was already called at start of process_zipfiles() */ /* tzset(); */ /* set `timezone' variable */#ifndef __BEOS__ /* BeOS DR8 has no timezones... */ m_time += timezone; /* seconds WEST of GMT: add */#endif#endif /* ?(BSD || MTS || __GO32__) */#endif /* ?WIN32 */ TTrace((stderr, " m_time after timezone = %lu\n", (ulg)m_time));/*--------------------------------------------------------------------------- Adjust for local daylight savings (summer) time. ---------------------------------------------------------------------------*/#ifndef BSD4_4 /* (DST already added to tm_gmtoff, so skip tm_isdst) */ if ( (dosdatetime >= DOSTIME_2038_01_18) && (m_time < (time_t)0x70000000L) ) m_time = U_TIME_T_MAX; /* saturate in case of (unsigned) overflow */ if (m_time < (time_t)0L) /* a converted DOS time cannot be negative */ m_time = S_TIME_T_MAX; /* -> saturate at max signed time_t value */ TIMET_TO_NATIVE(m_time) /* NOP unless MSC 7.0 or Macintosh */ if (((tm = localtime((time_t *)&m_time)) != NULL) && tm->tm_isdst)#ifdef WIN32 m_time += 60L * tzinfo.DaylightBias; /* adjust with DST bias */ else m_time += 60L * tzinfo.StandardBias; /* add StdBias (normally 0) */#else m_time -= 60L * 60L; /* adjust for daylight savings time */#endif NATIVE_TO_TIMET(m_time) /* NOP unless MSC 7.0 or Macintosh */ TTrace((stderr, " m_time after DST = %lu\n", (ulg)m_time));#endif /* !BSD4_4 */#ifdef WIN32 }#endif#endif /* !MACOS && !RISCOS && !QDOS && !TANDEM */#endif /* ?TOPS20 */#endif /* ?HAVE_MKTIME */ if ( (dosdatetime >= DOSTIME_2038_01_18) && (m_time < (time_t)0x70000000L) ) m_time = U_TIME_T_MAX; /* saturate in case of (unsigned) overflow */ if (m_time < (time_t)0L) /* a converted DOS time cannot be negative */ m_time = S_TIME_T_MAX; /* -> saturate at max signed time_t value */ return m_time;} /* end function dos_to_unix_time() */#endif /* !OS2 || TIMESTAMP */#endif /* !VMS && !CMS_MVS */#if (!defined(VMS) && !defined(OS2) && !defined(CMS_MVS))/******************************//* Function check_for_newer() */ /* used for overwriting/freshening/updating *//******************************/int check_for_newer(__G__ filename) /* return 1 if existing file is newer */ __GDEF /* or equal; 0 if older; -1 if doesn't */ char *filename; /* exist yet */{ time_t existing, archive;#ifdef USE_EF_UT_TIME iztimes z_utime;#endif#ifdef AOS_VS long dyy, dmm, ddd, dhh, dmin, dss; dyy = (lrec.last_mod_dos_datetime >> 25) + 1980; dmm = (lrec.last_mod_dos_datetime >> 21) & 0x0f; ddd = (lrec.last_mod_dos_datetime >> 16) & 0x1f; dhh = (lrec.last_mod_dos_datetime >> 11) & 0x1f; dmin = (lrec.last_mod_dos_datetime >> 5) & 0x3f; dss = (lrec.last_mod_dos_datetime & 0x1f) * 2; /* under AOS/VS, file times can only be set at creation time, * with the info in a special DG format. Make sure we can create * it here - we delete it later & re-create it, whether or not * it exists now. */ if (!zvs_create(filename, (((ulg)dgdate(dmm, ddd, dyy)) << 16) | (dhh*1800L + dmin*30L + dss/2L), -1L, -1L, (char *) -1, -1, -1, -1)) return DOES_NOT_EXIST;#endif /* AOS_VS */ Trace((stderr, "check_for_newer: doing stat(%s)\n", FnFilter1(filename))); if (SSTAT(filename, &G.statbuf)) { Trace((stderr, "check_for_newer: stat(%s) returns %d: file does not exist\n", FnFilter1(filename), SSTAT(filename, &G.statbuf)));#ifdef SYMLINKS Trace((stderr, "check_for_newer: doing lstat(%s)\n", FnFilter1(filename))); /* GRR OPTION: could instead do this test ONLY if G.symlnk is true */ if (lstat(filename, &G.statbuf) == 0) { Trace((stderr, "check_for_newer: lstat(%s) returns 0: symlink does exist\n", FnFilter1(filename))); if (QCOND2 && !IS_OVERWRT_ALL) Info(slide, 0, ((char *)slide, LoadFarString(FileIsSymLink), FnFilter1(filename), " with no real file")); return EXISTS_AND_OLDER; /* symlink dates are meaningless */ }#endif /* SYMLINKS */ return DOES_NOT_EXIST; } Trace((stderr, "check_for_newer: stat(%s) returns 0: file exists\n", FnFilter1(filename)));#ifdef SYMLINKS /* GRR OPTION: could instead do this test ONLY if G.symlnk is true */ if (lstat(filename, &G.statbuf) == 0 && S_ISLNK(G.statbuf.st_mode)) { Trace((stderr, "check_for_newer: %s is a symbolic link\n", FnFilter1(filename))); if (QCOND2 && !IS_OVERWRT_ALL) Info(slide, 0, ((char *)slide, LoadFarString(FileIsSymLink), FnFilter1(filename), "")); return EXISTS_AND_OLDER; /* symlink dates are meaningless */ }#endif /* SYMLINKS */ NATIVE_TO_TIMET(G.statbuf.st_mtime) /* NOP unless MSC 7.0 or Macintosh */#ifdef USE_EF_UT_TIME /* The `Unix extra field mtime' should be used for comparison with the * time stamp of the existing file >>>ONLY<<< when the EF info is also * used to set the modification time of the extracted file. */ if (G.extra_field &&#ifdef IZ_CHECK_TZ G.tz_is_valid &&#endif (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime, &z_utime, NULL) & EB_UT_FL_MTIME)) { TTrace((stderr, "check_for_newer: using Unix extra field mtime\n")); existing = G.statbuf.st_mtime; archive = z_utime.mtime; } else { /* round up existing filetime to nearest 2 seconds for comparison, * but saturate in case of arithmetic overflow */ existing = ((G.statbuf.st_mtime & 1) && (G.statbuf.st_mtime + 1 > G.statbuf.st_mtime)) ? G.statbuf.st_mtime + 1 : G.statbuf.st_mtime; archive = dos_to_unix_time(G.lrec.last_mod_dos_datetime); }#else /* !USE_EF_UT_TIME */ /* round up existing filetime to nearest 2 seconds for comparison, * but saturate in case of arithmetic overflow */ existing = ((G.statbuf.st_mtime & 1) && (G.statbuf.st_mtime + 1 > G.statbuf.st_mtime)) ? G.statbuf.st_mtime + 1 : G.statbuf.st_mtime; archive = dos_to_unix_time(G.lrec.last_mod_dos_datetime);#endif /* ?USE_EF_UT_TIME */ TTrace((stderr, "check_for_newer: existing %lu, archive %lu, e-a %ld\n", (ulg)existing, (ulg)archive, (long)(existing-archive))); return (existing >= archive);} /* end function check_for_newer() */#endif /* !VMS && !OS2 && !CMS_MVS *//************************//* Function do_string() *//************************/int do_string(__G__ length, option) /* return PK-type error code */ __GDEF unsigned int lengt
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -