From: Harlan Stenn Date: Sat, 4 May 2002 07:08:37 +0000 (-0400) Subject: timegm() patch from John Hay . X-Git-Tag: NTP_4_1_73~149^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c5bd656cbb825e4d9e2673783d22c360ea6ec15;p=thirdparty%2Fntp.git timegm() patch from John Hay . bk: 3cd388f5SrWC3BPSWbRmgVaQF9MjvA --- diff --git a/configure.in b/configure.in index 1037a3d458..e8ec586a27 100644 --- a/configure.in +++ b/configure.in @@ -629,7 +629,7 @@ case "$host" in *) AC_CHECK_FUNCS(mkstemp) ;; esac -AC_REPLACE_FUNCS(mktime) +AC_CHECK_FUNCS(mktime) case "$host" in *-*-aix4*) # Just a stub. Idiots. @@ -684,6 +684,7 @@ esac]) AC_CHECK_FUNCS(setvbuf sigaction) AC_CHECK_FUNCS(sigvec sigset sigsuspend stime strchr sysconf sysctl) AC_REPLACE_FUNCS(snprintf strdup strerror strstr) +AC_CHECK_FUNCS(timegm) case "$host" in *-*-aix4*) # Just stubs. Idiots. diff --git a/libntp/mktime.c b/libntp/mktime.c index 6d944f9577..8181e864ae 100644 --- a/libntp/mktime.c +++ b/libntp/mktime.c @@ -62,7 +62,7 @@ #include "ntp_machine.h" -#if !HAVE_MKTIME +#if !HAVE_MKTIME || !HAVE_TIMEGM #ifndef DSTMINUTES #define DSTMINUTES 60 @@ -179,7 +179,8 @@ tmcomp( static time_t time2( struct tm * tmp, - int * okayp + int * okayp, + int usezn ) { register int dir; @@ -227,7 +228,10 @@ time2( */ t = (t < 0) ? 0 : ((time_t) 1 << bits); for ( ; ; ) { - mytm = *localtime(&t); + if (usezn) + mytm = *localtime(&t); + else + mytm = *gmtime(&t); dir = tmcomp(&mytm, &yourtm); if (dir != 0) { if (bits-- < 0) @@ -245,11 +249,18 @@ time2( return WRONG; } t += saved_seconds; - *tmp = *localtime(&t); + if (usezn) + *tmp = *localtime(&t); + else + *tmp = *gmtime(&t); *okayp = TRUE; return t; } +#else +int mktime_bs; +#endif /* !HAVE_MKTIME || !HAVE_TIMEGM */ +#if !HAVE_MKTIME static time_t time1( struct tm * tmp @@ -260,7 +271,7 @@ time1( if (tmp->tm_isdst > 1) tmp->tm_isdst = 1; - t = time2(tmp, &okay); + t = time2(tmp, &okay, 1); if (okay || tmp->tm_isdst < 0) return t; @@ -274,6 +285,22 @@ mktime( { return time1(tmp); } -#else -int mktime_bs; -#endif +#endif /* !HAVE_MKTIME */ + +#if !HAVE_TIMEGM +time_t +timegm( + struct tm * tmp + ) +{ + register time_t t; + int okay; + + tmp->tm_isdst = 0; + t = time2(tmp, &okay, 0); + if (okay || tmp->tm_isdst < 0) + return t; + + return WRONG; +} +#endif /* !HAVE_TIMEGM */ diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index 3f6dfb9d23..8c45b0e620 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -1531,7 +1531,7 @@ asn2ntp ( tm.tm_wday = 0; tm.tm_yday = 0; tm.tm_isdst = 0; - return (mktime(&tm) + JAN_1970); + return (timegm(&tm) + JAN_1970); }