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

📄 time_lib.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 2 页
字号:
}time_t mktime(struct tm *tm){  time_t t;  if(!_TZ) __tzset();  t = mkgmtime(tm);  if(tm->tm_isdst < 0) tm->tm_isdst = checkdst(t);  t += tm->tm_isdst ? __dstoffset : __stdoffset;  return(t);}#endif /* !NO_MKTIME */static long gettime(char **s){  long num,time;  for(num = 0;**s >= '0' && **s <= '9';(*s)++) {    num = 10*num + (**s - '0');  }  time = 3600L * num;  if(**s == ':') {    (*s)++;    for(num = 0;**s >= '0' && **s <= '9';(*s)++) {      num = 10*num + (**s - '0');    }    time += 60 * num;    if(**s == ':') {      (*s)++;      for(num = 0;**s >= '0' && **s <= '9';(*s)++) {        num = 10*num + (**s - '0');      }      time += num;    }  }  return(time);}static void getdstdate(char **s,struct dstdate *dst){  switch(**s) {    case 'J':    case 'j':      (*s)++;      dst->dd_type = JULIAN;      for(dst->dd_day = 0;**s >= '0' && **s <= '9';(*s)++) {        dst->dd_day = 10*dst->dd_day + (**s - '0');      }      break;    case 'M':    case 'm':      (*s)++;      dst->dd_type = MWD;      for(dst->dd_month = 0;**s >= '0' && **s <= '9';(*s)++) {        dst->dd_month = 10*dst->dd_month + (**s - '0');      }      if(**s != '.') return;      (*s)++;      for(dst->dd_week = 0;**s >= '0' && **s <= '9';(*s)++) {        dst->dd_week = 10*dst->dd_week + (**s - '0');      }      if(**s != '.') return;      (*s)++;      for(dst->dd_day = 0;**s >= '0' && **s <= '9';(*s)++) {        dst->dd_day = 10*dst->dd_day + (**s - '0');      }      break;    default:      dst->dd_type = JULIAN0;      for(dst->dd_day = 0;**s >= '0' && **s <= '9';(*s)++) {        dst->dd_day = 10*dst->dd_day + (**s - '0');      }      break;  }  if(**s == '/') {    (*s)++;    dst->dd_secs = gettime(s);  }}void __tzset(void){  char *s,*t;  int minus = 0;  time_t tm;  struct Library *LocaleBase;  struct Locale *loc = NULL;  if (real_timezone_is_set)    return;  real_timezone_is_set = TRUE;  __dststart.dd_secs = __dstend.dd_secs = 7200;  __dststart.dd_type = __dstend.dd_type = MWD;  __dststart.dd_month = 4;  __dststart.dd_week = 1;  __dstend.dd_month = 10;  __dstend.dd_week = 5;  __dststart.dd_day = __dstend.dd_day = 0; /* sunday */  _TZ = NULL;  if (AVAIL_GETVAR) {                /* GetVar() available? */    if(GetVar("TZ",TZ,TZLEN,GVF_GLOBAL_ONLY) > 0)      _TZ = TZ;  } else      _TZ = getenv("TZ");  if (_TZ == NULL || !_TZ[0]) {    static char gmt[MAXTIMEZONELEN] = "EST5EDT";                                        /* US east coast is usual default */    LocaleBase = OpenLibrary("locale.library",0);    if(LocaleBase) {      loc = OpenLocale(0);  /* cannot return null */      if (loc->loc_GMTOffset == -300 || loc->loc_GMTOffset == 300) {        BPTR eh;        if (eh = Lock("ENV:sys/locale.prefs", ACCESS_READ))          UnLock(eh);        else {          real_timezone_is_set = FALSE;          loc->loc_GMTOffset = 300; /* Amigados bug: default when locale is */        }                           /* not initialized can have wrong sign  */      }      sprintf(gmt, "GMT%ld:%02ld", loc->loc_GMTOffset / 60L,              labs(loc->loc_GMTOffset) % 60L);      CloseLocale(loc);      CloseLibrary(LocaleBase);    } else      real_timezone_is_set = FALSE;    _TZ = gmt;  }  for(s = _TZ,t = __tzstn;*s && *s != '+' && *s != '-' && *s != ',' &&      (*s < '0' || *s > '9');s++) {    if(t-__tzstn < MAXTIMEZONELEN-1) *(t++) = *s;  }  *t = '\0';  if(*s == '+') {    s++;  }  else {    if(*s == '-') {      minus = 1;      s++;    }  }  __stdoffset = gettime(&s);  if(minus) {    __stdoffset *= -1;  }  if(*s) {    minus = 0;    for(t = __tzdtn;*s && *s != '+' && *s != '-' && *s != ',' &&        (*s < '0' || *s > '9');s++) {      if(t-__tzdtn < MAXTIMEZONELEN-1) *(t++) = *s;    }    *t = '\0';    if(*s == '+') {      s++;    }    else {      if(*s == '-') {        minus = 1;        s++;      }    }    if(*s && *s != ',') {      __dstoffset = gettime(&s);      if(minus) {        __dstoffset *= -1;      }    }    else {      __dstoffset = __stdoffset - 3600L;    }    if(*s == ',') {      s++;      getdstdate(&s,&__dststart);      if(*s == ',') {        s++;        getdstdate(&s,&__dstend);      }    }  }  else {    __dstoffset = __stdoffset;  }  time2tm(time(&tm));  __daylight = checkdst(tm);  __timezone = __daylight ? __dstoffset : __stdoffset;  __nextdstchange = dst2time(TM.tm_year, __daylight ? &__dstend : &__dststart);  if(tm >= __nextdstchange) {    __nextdstchange = dst2time(TM.tm_year+1,                               __daylight ? &__dstend : &__dststart);  }  __tzname[0] = __tzstn;  __tzname[1] = __tzdtn;  if (loc)         /* store TZ envvar if data read from locale */    set_TZ(__timezone, __dstoffset != __stdoffset);}time_t time(time_t *tm){  static time_t last_check = 0;  static struct _ixgmtoffset {    LONG  Offset;    UBYTE DST;    UBYTE Null;  } ixgmtoffset;  struct DateStamp ds;  time_t now;  DateStamp(&ds);  now = ds.ds_Days * 86400L + ds.ds_Minute * 60L +        ds.ds_Tick / TICKS_PER_SECOND;  if(now - last_check > CHECK) {    last_check = now;    if (AVAIL_GETVAR)    /* GetVar() available? */      if(GetVar("IXGMTOFFSET",(STRPTR)&ixgmtoffset,6,                GVF_BINARY_VAR|GVF_GLOBAL_ONLY) == -1) {        __tzset();        ixgmtoffset.Offset = __timezone;      }    else      if (envvarstr=getenv("IXGMTOFFSET")) {        ixgmtoffset = *((struct _ixgmtoffset *)envvarstr);  /* copy to struct */        __tzset();        ixgmtoffset.Offset = __timezone;      }  }  now += AMIGA2UNIX;  now += ixgmtoffset.Offset;  if(tm) *tm = now;  return(now);}/* Stores data from timezone and daylight to ENV:TZ.                  *//* ENV:TZ is required to exist by some other SAS/C library functions, *//* like stat() or fstat().                                            */void set_TZ(long time_zone, int day_light){  char put_tz[20];  /* string for putenv: "TZ=aaabbb:bb:bbccc" */  int offset;  void *exists;     /* dummy ptr to see if global envvar TZ already exists */  if (AVAIL_GETVAR)     exists = (void *)FindVar("TZ",GVF_GLOBAL_ONLY);  /* OS V36+ */  else     exists = (void *)getenv("TZ");  /* see if there is already an envvar "TZ". If not, create it */  if (exists == NULL) {    /* create TZ string by pieces: */    sprintf(put_tz, "TZ=GMT%+ld", time_zone / 3600L);    if (time_zone % 3600L) {      offset = (int) labs(time_zone % 3600L);      sprintf(put_tz + strlen(put_tz), ":%02d", offset / 60);      if (offset % 60)        sprintf(put_tz + strlen(put_tz), ":%02d", offset % 60);    }    if (day_light)      strcat(put_tz,"DST");    if (AVAIL_GETVAR)       /* store TZ to ENV:TZ. */       SetVar("TZ",&put_tz[3],-1,GVF_GLOBAL_ONLY);     /* OS V36+ */    else       setenv("TZ", &put_tz[3], 1);       /* putenv(put_tz); */  }}

⌨️ 快捷键说明

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