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

📄 filedate.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 2 页
字号:
int setenv(const char *var, const char *value, int overwrite){    struct Process *me = (void *) FindTask(NULL);    void *old_window = me->pr_WindowPtr;    int ret = -1;    me->pr_WindowPtr = (void *) -1;   /* suppress any "Please insert" popups */    if (SysBase->LibNode.lib_Version >= ReqVers)        ret = !SetVar((char *) var, (char *) value, -1, GVF_GLOBAL_ONLY | LV_VAR);    else {        BPTR hand, foot, spine;        int len = value ? strlen(value) : 0;        if (foot = Lock("ENV:", ACCESS_READ)) {            spine = CurrentDir(foot);            if (len) {                if (hand = Open((char *) var, MODE_NEWFILE)) {                    ret = Write(hand, (char *) value, len + 1) >= len;                    Close(hand);                }            } else                ret = DeleteFile((char *) var);            UnLock(CurrentDir(spine));        }    }    me->pr_WindowPtr = old_window;    return ret;}#endif /* AZTEC_C */#if (!defined(ZIP) || !defined(NO_MKTIME)) && !defined(USE_TIME_LIB)/* this mkgmtime() code is a simplified version taken from Zip's mktime.c *//* Return the equivalent in seconds past 12:00:00 a.m. Jan 1, 1970 GMT   of the Greenwich Mean time and date in the exploded time structure `tm',   and set `tm->tm_yday' and `tm->tm_wday', but not `tm->tm_isdst'.   Return -1 if any of the other fields in `tm' has an invalid value. *//* Nonzero if `y' is a leap year, else zero. */#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)/* Number of leap years from 1970 to `y' (not including `y' itself). */#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)/* Accumulated number of days from 01-Jan up to start of current month. */#ifdef ZIPstatic const unsigned short ydays[] ={  0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };#elseextern const unsigned short ydays[];  /* in unzip's fileio.c */#endiftime_t mkgmtime(struct tm *tm){  int years, months, days, hours, minutes, seconds;  years = tm->tm_year + 1900;   /* year - 1900 -> year */  months = tm->tm_mon;          /* 0..11 */  days = tm->tm_mday - 1;       /* 1..31 -> 0..30 */  hours = tm->tm_hour;          /* 0..23 */  minutes = tm->tm_min;         /* 0..59 */  seconds = tm->tm_sec;         /* 0..61 in ANSI C. */  if (years < 1970      || months < 0 || months > 11      || days < 0      || days >= (months == 11? 365 : ydays[months + 1]) - ydays[months]           + (months == 1 && leap(years))      || hours < 0 || hours > 23      || minutes < 0 || minutes > 59      || seconds < 0 || seconds > 61)  return -1;  /* Set `days' to the number of days into the year. */  days += ydays[months] + (months > 1 && leap(years));  tm->tm_yday = days;  /* Now set `days' to the number of days since Jan 1, 1970. */  days = (unsigned)days + 365 * (unsigned)(years - 1970) +         (unsigned)(nleap(years));  tm->tm_wday = ((unsigned)days + 4) % 7; /* Jan 1, 1970 was Thursday. *//*  tm->tm_isdst = 0; */  return (time_t)(86400L * (unsigned long)(unsigned)days +                  3600L * (unsigned long)hours +                  (unsigned long)(60 * minutes + seconds));}#endif /* (!ZIP || !NO_MKTIME) && !USE_TIME_LIB */#ifndef USE_TIME_LIB/* set timezone and daylight to settings found in locale.library */int locale_TZ(void){    struct Library *LocaleBase;    struct Locale *ll;    struct Process *me = (void *) FindTask(NULL);    void *old_window = me->pr_WindowPtr;    BPTR eh;    int z, valid = FALSE;    /* read timezone from locale.library if TZ envvar missing */    me->pr_WindowPtr = (void *) -1;   /* suppress any "Please insert" popups */    if (LocaleBase = OpenLibrary("locale.library", 0)) {        if (ll = OpenLocale(NULL)) {            z = ll->loc_GMTOffset;            if (z == -300) {                if (eh = Lock("ENV:sys/locale.prefs", ACCESS_READ))                    UnLock(eh);                else                    z = 300; /* bug: locale not initialized, default is bogus! */            } else                zone_is_set = TRUE;            timezone = z * 60;            daylight = (z >= 4*60 && z <= 9*60);    /* apply in the Americas */            valid = TRUE;            CloseLocale(ll);        }        CloseLibrary(LocaleBase);    }    me->pr_WindowPtr = old_window;    return valid;}void tzset(void) {    char *p,*TZstring;    int z,valid = FALSE;    if (zone_is_set)        return;    timezone = 0;       /* default is GMT0 which means no offsets */    daylight = 0;       /* from local system time                 */    TZstring = getenv("TZ");              /* read TZ envvar */    if (TZstring && TZstring[0]) {        /* TZ exists and has contents? */        z = 3600;        for (p = TZstring; *p && !isdigit(*p) && *p != '-'; p++) ;        if (*p == '-')            z = -3600, p++;        if (*p) {            timezone = 0;            do {                while (isdigit(*p))                    timezone = timezone * 10 + z * (*p++ - '0'), valid = TRUE;                if (*p == ':') p++;            } while (isdigit(*p) && (z /= 60) > 0);        }        while (isspace(*p)) p++;                      /* probably not needed */        if (valid)            zone_is_set = TRUE, daylight = !!*p;   /* a DST name part exists */    }    if (!valid)        locale_TZ();               /* read locale.library */#ifdef __SASC    /* Some SAS/C library functions, e.g. stat(), call library  */    /* __tzset() themselves. So envvar TZ *must* exist in order */    /* to get the right offset from GMT.                        */    set_TZ(timezone, daylight);#endif /* __SASC */}#  ifdef AZTEC_C    /* SAS/C uses library gmtime(), localtime(), time() */struct tm *gmtime(const time_t *when){    static struct tm tbuf;   /* this function is intrinsically non-reentrant */    static short smods[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};    long days = *when / 86400;    long secs = *when % 86400;    short yell, yday;    tbuf.tm_wday = (days + 4) % 7;                   /* 1/1/70 is a Thursday */    tbuf.tm_year = 70 + 4 * (days / 1461);    yday = days % 1461;    while (yday >= (yell = (tbuf.tm_year & 3 ? 365 : 366)))        yday -= yell, tbuf.tm_year++;    smods[1] = (tbuf.tm_year & 3 ? 28 : 29);    tbuf.tm_mon = 0;    tbuf.tm_yday = yday;    while (yday >= smods[tbuf.tm_mon])        yday -= smods[tbuf.tm_mon++];    tbuf.tm_mday = yday + 1;    tbuf.tm_isdst = 0;    tbuf.tm_sec = secs % 60;    tbuf.tm_min = (secs / 60) % 60;    tbuf.tm_hour = secs / 3600;    tbuf.tm_hsec = 0;                   /* this field exists for Aztec only */    return &tbuf;}struct tm *localtime(const time_t *when){    struct tm *t;    time_t localwhen;    int dst = FALSE, sundays, lastweekday;    tzset();    localwhen = *when - timezone;    t = gmtime(&localwhen);    /* So far we support daylight savings correction by the USA rule only: */    if (daylight && t->tm_mon >= 3 && t->tm_mon <= 9) {        if (t->tm_mon > 3 && t->tm_mon < 9)      /* May Jun Jul Aug Sep: yes */            dst = TRUE;        else {            sundays = (t->tm_mday + 6 - t->tm_wday) / 7;            if (t->tm_wday == 0 && t->tm_hour < 2 && sundays)                sundays--;           /* a Sunday does not count until 2:00am */            if (t->tm_mon == 3 && sundays > 0)      /* first sunday in April */                dst = TRUE;            else if (t->tm_mon == 9) {                lastweekday = (t->tm_wday + 31 - t->tm_mday) % 7;                if (sundays < (37 - lastweekday) / 7)                    dst = TRUE;                    /* last sunday in October */            }        }        if (dst) {            localwhen += 3600;            t = gmtime(&localwhen);                   /* crude but effective */            t->tm_isdst = 1;        }    }    return t;}#    ifdef ZIPtime_t time(time_t *tp){    time_t t;    struct DateStamp ds;    DateStamp(&ds);    t = ds.ds_Tick / TICKS_PER_SECOND + ds.ds_Minute * 60                                      + (ds.ds_Days + 2922) * 86400;    t = mktime(gmtime(&t));    /* gmtime leaves ds in the local timezone, mktime converts it to GMT */    if (tp) *tp = t;    return t;}#    endif /* ZIP */#  endif /* AZTEC_C */#endif /* !USE_TIME_LIB */#endif /* !FUNZIP */#if CRYPT || !defined(FUNZIP)/*  sendpkt.c *  by A. Finkel, P. Lindsay, C. Sheppner *  returns Res1 of the reply packet *//*#include <exec/types.h>#include <exec/memory.h>#include <libraries/dos.h>#include <libraries/dosextens.h>#include <proto/exec.h>#include <proto/dos.h>*/LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);LONG sendpkt(pid,action,args,nargs)struct MsgPort *pid;           /* process identifier (handler message port) */LONG action,                   /* packet type (desired action)              */     *args,                    /* a pointer to argument list                */     nargs;                    /* number of arguments in list               */{    struct MsgPort *replyport, *CreatePort(UBYTE *, long);    void DeletePort(struct MsgPort *);    struct StandardPacket *packet;    LONG count, *pargs, res1;    replyport = CreatePort(NULL,0L);    if( !replyport ) return(0);    packet = (struct StandardPacket *)AllocMem(            (long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);    if( !packet )    {        DeletePort(replyport);        return(0);    }    packet->sp_Msg.mn_Node.ln_Name  = (char *)&(packet->sp_Pkt);    packet->sp_Pkt.dp_Link          = &(packet->sp_Msg);    packet->sp_Pkt.dp_Port          = replyport;    packet->sp_Pkt.dp_Type          = action;    /* copy the args into the packet */    pargs = &(packet->sp_Pkt.dp_Arg1);      /* address of 1st argument */    for( count=0; count<nargs; count++ )        pargs[count] = args[count];    PutMsg(pid,(struct Message *)packet);   /* send packet */    WaitPort(replyport);    GetMsg(replyport);    res1 = packet->sp_Pkt.dp_Res1;    FreeMem((char *)packet,(long)sizeof(*packet));    DeletePort(replyport);    return(res1);} /* sendpkt() */#endif /* CRYPT || !FUNZIP */#if CRYPT || (defined(UNZIP) && !defined(FUNZIP))/* Agetch() reads one raw keystroke -- uses sendpkt() */int Agetch(void){    LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);    struct Task *me = FindTask(NULL);    struct CommandLineInterface *cli = BADDR(((struct Process *) me)->pr_CLI);    BPTR fh = cli->cli_StandardInput;   /* this is immune to < redirection */    void *conp = ((struct FileHandle *) BADDR(fh))->fh_Type;    char longspace[8];    long *flag = (long *) ((ULONG) &longspace[4] & ~3); /* LONGWORD ALIGNED! */    UBYTE c;    *flag = 1;    sendpkt(conp, ACTION_SCREEN_MODE, flag, 1);         /* assume success */    Read(fh, &c, 1);    *flag = 0;    sendpkt(conp, ACTION_SCREEN_MODE, flag, 1);    if (c == 3)                                         /* ^C in input */        Signal(me, SIGBREAKF_CTRL_C);    return c;}#endif /* CRYPT || (UNZIP && !FUNZIP) */

⌨️ 快捷键说明

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