aboutsummaryrefslogtreecommitdiff
path: root/contrib/ntp/libntp/mktime.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp/mktime.c')
-rw-r--r--contrib/ntp/libntp/mktime.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/contrib/ntp/libntp/mktime.c b/contrib/ntp/libntp/mktime.c
index 6d944f957793..7f8290f3c3ed 100644
--- a/contrib/ntp/libntp/mktime.c
+++ b/contrib/ntp/libntp/mktime.c
@@ -62,7 +62,7 @@
#include "ntp_machine.h"
-#if !HAVE_MKTIME
+#if !HAVE_MKTIME || !HAVE_TIMEGM
#ifndef DSTMINUTES
#define DSTMINUTES 60
@@ -84,7 +84,7 @@
#define TM_YEAR_BASE 1900
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
-extern time_t time();
+extern time_t time P((time_t *));
static int mon_lengths[2][MONSPERYEAR] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
@@ -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 */