📄 fileio.c
字号:
#ifdef DLL/*****************************//* Function UzpMessageNull() */ /* convenience routine for no output at all *//*****************************/int UZ_EXP UzpMessageNull(pG, buf, size, flag) zvoid *pG; /* globals struct: always passed */ uch *buf; /* preformatted string to be printed */ ulg size; /* length of string (may include nulls) */ int flag; /* flag bits */{ return 0;} /* end function UzpMessageNull() */#endif /* DLL *//***********************//* Function UzpInput() */ /* GRR: this is a placeholder for now *//***********************/int UZ_EXP UzpInput(pG, buf, size, flag) zvoid *pG; /* globals struct: always passed */ uch *buf; /* preformatted string to be printed */ int *size; /* (address of) size of buf and of returned string */ int flag; /* flag bits (bit 0: no echo) */{ /* tell picky compilers to shut up about "unused variable" warnings */ pG = pG; buf = buf; flag = flag; *size = 0; return 0;} /* end function UzpInput() */#if (!defined(WINDLL) && !defined(MACOS))/***************************//* Function UzpMorePause() *//***************************/void UZ_EXP UzpMorePause(pG, prompt, flag) zvoid *pG; /* globals struct: always passed */ ZCONST char *prompt; /* "--More--" prompt */ int flag; /* 0 = any char OK; 1 = accept only '\n', ' ', q */{ uch c;/*--------------------------------------------------------------------------- Print a prompt and wait for the user to press a key, then erase prompt if possible. ---------------------------------------------------------------------------*/ if (!((Uz_Globs *)pG)->sol) fprintf(stderr, "\n"); /* numlines may or may not be used: */ fprintf(stderr, prompt, ((Uz_Globs *)pG)->numlines); fflush(stderr); if (flag & 1) { do { c = (uch)FGETCH(0); } while (c != '\r' && c != '\n' && c != ' ' && c != 'q' && c != 'Q'); } else c = (uch)FGETCH(0); /* newline was not echoed, so cover up prompt line */ fprintf(stderr, LoadFarString(HidePrompt)); fflush(stderr); if (ToLower(c) == 'q') { DESTROYGLOBALS() EXIT(PK_COOL); } ((Uz_Globs *)pG)->sol = TRUE;} /* end function UzpMorePause() */#endif /* !WINDLL && !MACOS */#ifndef WINDLL/**************************//* Function UzpPassword() *//**************************/int UZ_EXP UzpPassword (pG, rcnt, pwbuf, size, zfn, efn) zvoid *pG; /* pointer to UnZip's internal global vars */ int *rcnt; /* retry counter */ char *pwbuf; /* buffer for password */ int size; /* size of password buffer */ ZCONST char *zfn; /* name of zip archive */ ZCONST char *efn; /* name of archive entry being processed */{#if CRYPT int r = IZ_PW_ENTERED; char *m; char *prompt;#ifndef REENTRANT /* tell picky compilers to shut up about "unused variable" warnings */ pG = pG;#endif if (*rcnt == 0) { /* First call for current entry */ *rcnt = 2; if ((prompt = (char *)malloc(2*FILNAMSIZ + 15)) != (char *)NULL) { sprintf(prompt, LoadFarString(PasswPrompt), FnFilter1(zfn), FnFilter2(efn)); m = prompt; } else m = (char *)LoadFarString(PasswPrompt2); } else { /* Retry call, previous password was wrong */ (*rcnt)--; prompt = NULL; m = (char *)LoadFarString(PasswRetry); } m = getp(__G__ m, pwbuf, size); if (prompt != (char *)NULL) { free(prompt); } if (m == (char *)NULL) { r = IZ_PW_ERROR; } 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(AMIGA) || 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_UNKNOWN) { 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));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -