]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
timegm() patch from John Hay <jhay@icomtek.csir.co.za>.
authorHarlan Stenn <stenn@ntp.org>
Sat, 4 May 2002 07:08:37 +0000 (03:08 -0400)
committerHarlan Stenn <stenn@ntp.org>
Sat, 4 May 2002 07:08:37 +0000 (03:08 -0400)
bk: 3cd388f5SrWC3BPSWbRmgVaQF9MjvA

configure.in
libntp/mktime.c
ntpd/ntp_crypto.c

index 1037a3d458ae6fcf6b7af3c7bfe76e5463f1151d..e8ec586a2794e9bb6872d674bc83e67137cce79d 100644 (file)
@@ -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.
index 6d944f957793cd3288c1bcfee2db5f2f307348b5..8181e864aed564294dbbb01f025b630ed4d637be 100644 (file)
@@ -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 */
index 3f6dfb9d2338b079fe609cc3715db4d2fb344a9a..8c45b0e6207019147d8ca092c5b91e5afd7b7f53 100644 (file)
@@ -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);
 }