From 6db16d8f6e83b74520b1de7e1acc1f4ec4da1a80 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 21 Oct 2016 17:27:44 -0700 Subject: [PROPOSED PATCH] Enable port to AmigaOS This builds on a patch proposed by Carsten Larsen. * Makefile, NEWS: Document this. * localtime.c, private.h (time): Also supply a substitute if EPOCH_LOCAL or EPOCH_OFFSET. * private.h (EPOCH_LOCAL, EPOCH_OFFSET): New macros, defaulting to 0. --- Makefile | 4 ++++ NEWS | 5 +++++ localtime.c | 23 +++++++++++++++++++++-- private.h | 9 ++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f7553a3..74b950c 100644 --- a/Makefile +++ b/Makefile @@ -129,6 +129,10 @@ LDLIBS= # -DHAVE_SYS_WAIT_H=0 if your compiler lacks a "sys/wait.h" # -DHAVE_TZSET=0 if your system lacks a tzset function # -DHAVE_UNISTD_H=0 if your compiler lacks a "unistd.h" (Microsoft C++ 7?) +# -DEPOCH_LOCAL=1 if the 'time' function returns local time not UT +# -DEPOCH_OFFSET=N if the 'time' function returns a value N greater +# than what POSIX specifies, assuming local time is UT. +# For example, N is 252460800 on AmigaOS. # -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1 # if you do not want run time warnings about formats that may cause # year 2000 grief diff --git a/NEWS b/NEWS index b4b8d47..1084cb2 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,11 @@ Unreleased, experimental changes Europe/San_Marino, and Europe/Vatican. (Thanks to Pierpaolo Bernardi and Brian Inglis.) + Changes to code + + The code should now be buildable on AmigaOS merely by setting the + appropriate Makefile variables. (From a patch by Carsten Larsen.) + Release 2016h - 2016-10-19 23:17:57 -0700 diff --git a/localtime.c b/localtime.c index 6c00c45..5dba623 100644 --- a/localtime.c +++ b/localtime.c @@ -2254,15 +2254,34 @@ posix2time(time_t t) #endif /* defined STD_INSPIRED */ -#ifdef time_tz +#if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0 + +# ifndef USG_COMPAT +# define daylight 0 +# define timezone 0 +# endif +# ifndef ALTZONE +# define altzone 0 +# endif /* Convert from the underlying system's time_t to the ersatz time_tz, - which is called 'time_t' in this file. */ + which is called 'time_t' in this file. Typically, this merely + converts the time's integer width. On some platforms, the system + time is local time not UT, or uses some epoch other than the POSIX + epoch. */ time_t time(time_t *p) { time_t r = sys_time(0); + if (r != (time_t) -1) { + int_fast32_t offset = EPOCH_LOCAL ? (daylight ? timezone : altzone) : 0; + if (increment_overflow32(&offset, -EPOCH_OFFSET) + || increment_overflow_time (&r, offset)) { + errno = EOVERFLOW; + r = -1; + } + } if (p) *p = r; return r; diff --git a/private.h b/private.h index bc38a00..0bd1d00 100644 --- a/private.h +++ b/private.h @@ -320,6 +320,13 @@ typedef unsigned long uintmax_t; ** Workarounds for compilers/systems. */ +#ifndef EPOCH_LOCAL +# define EPOCH_LOCAL 0 +#endif +#ifndef EPOCH_OFFSET +# define EPOCH_OFFSET 0 +#endif + /* ** Compile with -Dtime_tz=T to build the tz package with a private ** time_t type equivalent to T rather than the system-supplied time_t. @@ -327,7 +334,7 @@ typedef unsigned long uintmax_t; ** (e.g., time_t wider than 'long', or unsigned time_t) even on ** typical platforms. */ -#ifdef time_tz +#if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0 # ifdef LOCALTIME_IMPLEMENTATION static time_t sys_time(time_t *x) { return time(x); } # endif -- 2.7.4