From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- unix/boot/bootlib/ostime.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 unix/boot/bootlib/ostime.c (limited to 'unix/boot/bootlib/ostime.c') diff --git a/unix/boot/bootlib/ostime.c b/unix/boot/bootlib/ostime.c new file mode 100644 index 00000000..8ae97df7 --- /dev/null +++ b/unix/boot/bootlib/ostime.c @@ -0,0 +1,113 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#ifdef SYSV +#include +#else +#include +#include +#endif + +#ifdef MACOSX +#include +#endif + +#define SECONDS_1970_TO_1980 315532800L +static long os_timezone(); + + +/* OS_UTIME -- Convert IRAF time (local standard, epoch 1980) to UNIX time + * (greenwich mean time, epoch 1970). [MACHDEP] + * + * NOTE: If this is difficult to implement on your system, you can probably + * forget about the correction to Greenwich (e.g., 7 hours) and that for + * daylight savings time (1 hour), and file times will come out a bit off + * but it probably won't matter. + */ +long +os_utime (long iraf_time) +{ + struct tm *localtime(); + time_t time_var, lst; +#ifdef AUX + long lstl; +#endif + + lst = (time_t)iraf_time; + + /* Add minutes westward from GMT */ + time_var = lst + os_timezone(); + + /* Correct for daylight savings time, if in effect */ +#ifdef AUX + lstl = (long)lst; + if (localtime(&lstl)->tm_isdst) +#else + if (localtime(&lst)->tm_isdst) +#endif + time_var += 60L * 60L; + + return ((long)time_var + SECONDS_1970_TO_1980); +} + + +/* OS_ITIME -- Convert UNIX time (gmt, epoch 1970) to IRAF time (lst, epoch + * 1980). [MACHDEP] + */ +long +os_itime (long unix_time) +{ + struct tm *localtime(); + time_t time_var, gmt; +#ifdef AUX + long gmtl; +#endif + + gmt = (time_t)unix_time; + + /* Subtract minutes westward from GMT */ + time_var = gmt - os_timezone(); + + /* Correct for daylight savings time, if in effect */ +#ifdef AUX + gmtl = (long)gmt; + if (localtime(&gmtl)->tm_isdst) +#else + if (localtime(&gmt)->tm_isdst) +#endif + time_var -= 60L * 60L; + + return ((long)time_var - SECONDS_1970_TO_1980); +} + + +/* OS_GTIMEZONE -- Get the local timezone, measured in seconds westward + * from Greenwich, ignoring daylight savings time if in effect. + */ +static long +os_timezone() +{ +#ifdef CYGWIN + extern long _timezone; + return (_timezone); +#else +#if defined(SOLARIS) && defined(X86) + extern long timezone; + return (timezone); + +#else +#if defined(SYSV) || defined(MACOSX) + struct tm *tm; + time_t clock; + clock = time(NULL); + tm = gmtime (&clock); + return (-(tm->tm_gmtoff)); +#else + struct timeb time_info; + ftime (&time_info); + return (time_info.timezone * 60); +#endif +#endif +#endif +} -- cgit