diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-02-20 02:03:20 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-02-20 02:03:20 +0000 |
commit | 603c6d00f9181f4aa96463083c980218ec2e5594 (patch) | |
tree | 9328bd0f9429a0b05ea4c9e2efc3caee0898dba6 /usr.sbin/cron/misc.c | |
parent | 86744021bc298d5866b29e263475344195783db9 (diff) |
Turn get_gmtoff into a macro for OSes with tm_gmtoff (like OpenBSD).
Save the GMT offset in a global so cron_sleep can use it. This means
the offset can only change in set_time() which is really what we want.
Diffstat (limited to 'usr.sbin/cron/misc.c')
-rw-r--r-- | usr.sbin/cron/misc.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index 7764aeb9fd2..fab3335493b 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.9 2001/02/19 14:33:33 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.10 2001/02/20 02:03:19 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved */ @@ -21,7 +21,7 @@ */ #if !defined(lint) && !defined(LINT) -static char rcsid[] = "$OpenBSD: misc.c,v 1.9 2001/02/19 14:33:33 millert Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.10 2001/02/20 02:03:19 millert Exp $"; #endif /* vix 26jan87 [RCS has the rest of the log] @@ -692,7 +692,7 @@ arpadate(clock) static char ret[64]; /* zone name might be >3 chars */ char *qmark; size_t len; - long gmtoff = get_gmtoff(&t); + long gmtoff = get_gmtoff(&t, tm); int hours = gmtoff / 3600; int minutes = (gmtoff - (hours * 3600)) / 60; @@ -725,36 +725,28 @@ int swap_uids_back() { return (swap_uids()); } #endif /*HAVE_SAVED_UIDS*/ /* Return the offset from GMT in seconds (algorithm taken from sendmail). */ -#ifdef HAVE_TM_GMTOFF -long get_gmtoff(time_t *clock) +#ifndef HAVE_TM_GMTOFF +long get_gmtoff(time_t *clock, struct tm *local) { - struct tm *tm; - - tm = localtime(clock); - return (tm->tm_gmtoff); -} -#else -long get_gmtoff(time_t *clock) -{ - struct tm local; - struct tm *gmt; + struct tm gmt; long offset; - local = *localtime(clock); - gmt = gmtime(clock); + gmt = *gmtime(clock); + if (local == NULL) + local = localtime(clock); - offset = (local.tm_sec - gmt->tm_sec) + - ((local.tm_min - gmt->tm_min) * 60) + - ((local.tm_hour - gmt->tm_hour) * 3600); + offset = (local->tm_sec - gmt.tm_sec) + + ((local->tm_min - gmt.tm_min) * 60) + + ((local->tm_hour - gmt.tm_hour) * 3600); /* Timezone may cause year rollover to happen on a different day. */ - if (local.tm_year < gmt->tm_year) + if (local->tm_year < gmt.tm_year) offset -= 24 * 3600; - else if (local.tm_year > gmt->tm_year) + else if (local->tm_year > gmt.tm_year) offset -= 24 * 3600; - else if (local.tm_yday < gmt->tm_yday) + else if (local->tm_yday < gmt.tm_yday) offset -= 24 * 3600; - else if (local.tm_yday > gmt->tm_yday) + else if (local->tm_yday > gmt.tm_yday) offset += 24 * 3600; return (offset); |