Merge from HEAD - tridge's new timegm() that actually works on solaris.
authorAndrew Bartlett <abartlet@samba.org>
Fri, 3 Jan 2003 01:41:44 +0000 (01:41 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 3 Jan 2003 01:41:44 +0000 (01:41 +0000)
Andrew Bartlett
(This used to be commit 353c6b24234444c5430de183c3a4b1318bfce02c)

source3/lib/replace.c

index a826de3560edd0a111e1ed6fa74aafd364e96d56..cd48b8d160fe4f7f249694492c62afb886351c1f 100644 (file)
@@ -427,26 +427,23 @@ char *rep_inet_ntoa(struct in_addr ip)
 
 #ifndef HAVE_TIMEGM
 /*
-  see the timegm man page on linux
+  yes, I know this looks insane, but its really needed. The function in the 
+  Linux timegm() manpage does not work on solaris.
 */
  time_t timegm(struct tm *tm) 
 {
-       time_t ret;
-       char *tz;
-       char *tzvar;
-       
-       tz = getenv("TZ");
-       putenv("TZ=");
-       tzset();
-       ret = mktime(tm);
-       if (tz) {
-               asprintf(&tzvar, "TZ=%s", tz);
-               putenv(tzvar);
-               safe_free(tzvar);
-       } else {
-               putenv("TZ");
-       }
-       tzset();
-       return ret;
+       struct tm tm2, tm3;
+       time_t t;
+
+       tm2 = *tm;
+
+       t = mktime(&tm2);
+       tm3 = *localtime(&t);
+       tm2 = *tm;
+       tm2.tm_isdst = tm3.tm_isdst;
+       t = mktime(&tm2);
+       t -= TimeDiff(t);
+
+       return t;
 }
 #endif