From d8c0ab9bdf6d9ad5116851014a9bc782baa8f313 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 23 Nov 2020 20:42:15 -0800 Subject: [PATCH] Fix detection of timezone offset for FreeBSD. (Refs Interlisp/medley/#65) modified: src/timer.c --- src/timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/timer.c b/src/timer.c index ac321f4..f56dbd4 100644 --- a/src/timer.c +++ b/src/timer.c @@ -317,9 +317,16 @@ static int gettime(int casep) case 8: /* other methods of determining timezone offset are unreliable and/or deprecated */ /* timezone is declared in ; the time mechanisms must be initialized */ + /* Unfortunately, FreeBSD does not support the timezone external variable, nor */ + /* does gettimeofday() seem to produce the correct timezone values. */ tzset(); +#if defined(FREEBSD) + time_t tv = time(NULL); + struct tm *tm = localtime(&tv); + return (tm->tm_gmtoff / -3600); +#else return (timezone / 3600); /* timezone, extern, is #secs diff GMT to local. */ - +#endif default: return (0); } }