mirror of
https://frontier.innolan.net/rainlance/amiga-tz.git
synced 2025-11-22 03:45:23 +00:00
Add support for testing time_t types other than the system's.
This makes it easier to test on (say) Debian, even if we're testing the time_t type on (say) NetBSD. NetBSD uses 64-bit time_t on 32-bit hosts, and this lets us test a NetBSD-style implementation (32-bit 'long', 64-bit time_t) on a 32-bit Debian host. * Makefile: Update comments to talk about TIME_T_FLOATING and time_tz. Sort the comments. * private.h (restrict): Define to empty with older compilers. 'restrict' is now needed, to define gmtime_r and localtime_r in standard ways when time_tz is defined. Make the following changes if time_tz is defined: (sys_time, time): New static functions. The former is the system 'time' function that applies to the system time_t, the latter our function that applies to our time_t. (time_t, ctime, ctime_r, difftime, gmtime, gmtime_r, localtime) (localtime_r, mktime): Rename to tz_time_t, tz_ctime, etc., via macros. Declare the renamed versions. * zdump.8: Document new options -V, -t. * zdump.c: Include private.h if time_tz is defined. (INITIALIZE): Remove; no longer needed. (absolute_min_time, absolute_max_time): Work even if time_t is wider than intmax_t, which can be true with GCC and __int128_t. Use the new TIME_T_FLOATING macro for this. (usage): Document new flags. (main): Support them.
This commit is contained in:
56
private.h
56
private.h
@ -150,6 +150,10 @@ typedef long int_fast64_t;
|
||||
# define ATTRIBUTE_PURE /* empty */
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ < 199901 && !defined restrict
|
||||
# define restrict /* empty */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Workarounds for compilers/systems.
|
||||
*/
|
||||
@ -164,6 +168,58 @@ typedef long int_fast64_t;
|
||||
extern char * asctime_r(struct tm const *, char *);
|
||||
#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.
|
||||
** This debugging feature can test unusual design decisions
|
||||
** (e.g., time_t wider than 'long', or unsigned time_t) even on
|
||||
** typical platforms.
|
||||
*/
|
||||
#ifdef time_tz
|
||||
static time_t sys_time(time_t *x) { return time(x); }
|
||||
|
||||
# undef ctime
|
||||
# define ctime tz_ctime
|
||||
# undef ctime_r
|
||||
# define ctime_r tz_ctime_r
|
||||
# undef difftime
|
||||
# define difftime tz_difftime
|
||||
# undef gmtime
|
||||
# define gmtime tz_gmtime
|
||||
# undef gmtime_r
|
||||
# define gmtime_r tz_gmtime_r
|
||||
# undef localtime
|
||||
# define localtime tz_localtime
|
||||
# undef localtime_r
|
||||
# define localtime_r tz_localtime_r
|
||||
# undef mktime
|
||||
# define mktime tz_mktime
|
||||
# undef time
|
||||
# define time tz_time
|
||||
# undef time_t
|
||||
# define time_t tz_time_t
|
||||
|
||||
typedef time_tz time_t;
|
||||
|
||||
char *ctime(time_t const *);
|
||||
char *ctime_r(time_t const *, char *);
|
||||
double difftime(time_t, time_t);
|
||||
struct tm *gmtime(time_t const *);
|
||||
struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
|
||||
struct tm *localtime(time_t const *);
|
||||
struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
|
||||
time_t mktime(struct tm *);
|
||||
|
||||
static time_t
|
||||
time(time_t *p)
|
||||
{
|
||||
time_t r = sys_time(0);
|
||||
if (p)
|
||||
*p = r;
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Private function declarations.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user