time_t wtimegm (struct tm *tm) { time_t ret; char *tz; tz = environment_getVariable("TZ"); environment_setVariable("TZ", ""); tzset(); ret = mktime(tm); if (tz) environment_setVariable("TZ", tz); else environment_deleteVariable("TZ"); tzset(); return ret; }
time_t wtimegm (struct tm *tm) { time_t ret; char *tz; /* Used since the timezone setting needs to be atomic */ wthread_static_mutex_lock(&envLock); tz = environment_getVariable("TZ"); environment_setVariable("TZ", "UTC"); tzset(); ret = mktime(tm); if (tz) environment_setVariable("TZ", tz); else environment_deleteVariable("TZ"); tzset(); wthread_static_mutex_unlock(&envLock); return ret; }
mama_status mamaTimeZone_check (mamaTimeZone timeZone) { if (!timeZone) { return MAMA_STATUS_INVALID_ARG; } else { mamaTimeZoneImpl* impl = (mamaTimeZoneImpl*)timeZone; const char* tzSaved = NULL; time_t tzClock; time_t gmClock; struct tm tzTm; /* get the mutex for the accessing thread stops other threads * from calling this method at the same time as the TZ update * thread. */ wthread_static_mutex_lock (&sCheck_mutex); /* Save the current value of TZ: */ tzSaved = environment_getVariable("TZ"); if (tzSaved && tzSaved[0]) { tzSaved = strdup(tzSaved); } /* Switch TZ to the mTz zone: */ if (impl->mTz[0]) { environment_setVariable("TZ", impl->mTz); } else { environment_deleteVariable("TZ"); } tzset(); /* Get the mTz time: */ time (&tzClock); localtime_r (&tzClock, &tzTm); /* Switch TZ to the UTC: */ environment_setVariable("TZ", "UTC"); tzset(); /* Get the GMT time: */ gmClock = mktime(&tzTm); /* Restore original TZ */ if (tzSaved && tzSaved[0]) { environment_setVariable("TZ", tzSaved); free ((void*)tzSaved); } else { environment_deleteVariable("TZ"); } tzset(); impl->mOffset = difftime (gmClock, tzClock); /* release the mutex on this method */ wthread_static_mutex_unlock (&sCheck_mutex); return MAMA_STATUS_OK; } }