#include <errno.h>
#include <pthread.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <glite/lbu/trio.h>
}
-static time_t tm2time(struct tm *tm) {
- static struct tm tm_last = { tm_year:0, tm_mon:0 };
- static time_t t = (time_t)-1;
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
- char *tz;
-
- pthread_mutex_lock(&lock);
- if (tm->tm_year == tm_last.tm_year && tm->tm_mon == tm_last.tm_mon) {
- t = t + (tm->tm_sec - tm_last.tm_sec)
- + (tm->tm_min - tm_last.tm_min) * 60
- + (tm->tm_hour - tm_last.tm_hour) * 3600
- + (tm->tm_mday - tm_last.tm_mday) * 86400;
- memcpy(&tm_last, tm, sizeof tm_last);
- } else {
- tz = getenv("TZ");
- if (tz) tz = strdup(tz);
- setenv("TZ", "UTC", 1);
- tzset();
-
- t = mktime(tm);
- memcpy(&tm_last, tm, sizeof tm_last);
-
- if (tz) setenv("TZ", tz, 1);
- else unsetenv("TZ");
- free(tz);
- tzset();
- }
- pthread_mutex_unlock(&lock);
-
- return t;
-}
-
-
time_t glite_lbu_StrToTime(const char *str) {
struct tm tm;
tm.tm_year -= 1900;
tm.tm_mon--;
- return tm2time(&tm);
+ return timegm(&tm);
}
tm.tm_mon--;
tm.tm_sec = sec;
- return (sec - tm.tm_sec) + tm2time(&tm);
+ return (sec - tm.tm_sec) + timegm(&tm);
}