static struct tm * gmtsub(const time_t * const timep, const long offset, struct tm * const tmp) { struct tm * result; if (!gmt_is_set) { _MUTEX_LOCK(&gmt_mutex); if (!gmt_is_set) { gmtload(gmtptr); gmt_is_set = TRUE; } _MUTEX_UNLOCK(&gmt_mutex); } result = timesub(timep, offset, gmtptr, tmp); #ifdef TM_ZONE /* ** Could get fancy here and deliver something such as ** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero, ** but this is no time for a treasure hunt. */ if (offset != 0) tmp->TM_ZONE = wildabbr; else tmp->TM_ZONE = gmtptr->chars; #endif /* defined TM_ZONE */ return result; }
static void tzset_basic(int rdlocked) { const char * name; name = getenv("TZ"); if (name == NULL) { tzsetwall_basic(rdlocked); return; } if (!rdlocked) _RWLOCK_RDLOCK(&lcl_rwlock); if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) { if (!rdlocked) _RWLOCK_UNLOCK(&lcl_rwlock); return; } _RWLOCK_UNLOCK(&lcl_rwlock); _RWLOCK_WRLOCK(&lcl_rwlock); lcl_is_set = strlen(name) < sizeof lcl_TZname; if (lcl_is_set) strcpy(lcl_TZname, name); if (*name == '\0') { /* ** User wants it fast rather than right. */ lclptr->leapcnt = 0; /* so, we're off a little */ lclptr->timecnt = 0; lclptr->typecnt = 0; lclptr->ttis[0].tt_isdst = 0; lclptr->ttis[0].tt_gmtoff = 0; lclptr->ttis[0].tt_abbrind = 0; strcpy(lclptr->chars, gmt); } else if (tzload(name, lclptr, TRUE) != 0) if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) gmtload(lclptr); settzname(); _RWLOCK_UNLOCK(&lcl_rwlock); if (rdlocked) _RWLOCK_RDLOCK(&lcl_rwlock); }
static void tzsetwall_basic(int rdlocked) { if (!rdlocked) _RWLOCK_RDLOCK(&lcl_rwlock); if (lcl_is_set < 0) { if (!rdlocked) _RWLOCK_UNLOCK(&lcl_rwlock); return; } _RWLOCK_UNLOCK(&lcl_rwlock); _RWLOCK_WRLOCK(&lcl_rwlock); lcl_is_set = -1; if (tzload(NULL, lclptr, TRUE) != 0) gmtload(lclptr); settzname(); _RWLOCK_UNLOCK(&lcl_rwlock); if (rdlocked) _RWLOCK_RDLOCK(&lcl_rwlock); }
/* * gmtsub is to gmtime as localsub is to localtime. */ static struct pg_tm * gmtsub(const pg_time_t *timep, long offset, struct pg_tm * tmp) { struct pg_tm *result; if (!gmt_is_set) { gmt_is_set = TRUE; gmtload(gmtptr); } result = timesub(timep, offset, gmtptr, tmp); /* * Could get fancy here and deliver something such as "UTC+xxxx" or * "UTC-xxxx" if offset is non-zero, but this is no time for a treasure * hunt. */ if (offset != 0) tmp->tm_zone = wildabbr; else tmp->tm_zone = gmtptr->chars; return result; }