2009-05-17 14:28:27 -04:00
|
|
|
/*
|
|
|
|
|
** This file is in the public domain, so clarified as of
|
|
|
|
|
** 2009-05-17 by Arthur David Olson.
|
|
|
|
|
*/
|
|
|
|
|
|
Switch from SCCS to git.
Remove the SCCS keyword '%W%' from all files.
Mostly this just remove comments.
Remove trailing white space, too.
* Makefile (TZCODE_VERSION): New macro.
(version.h): New rule.
(tzselect): Interpolate TZCODE_VERSION.
(clean): Remove version.h.
(zdump.o, zic.o): Depend on version.h.
* asctime.c, date.c, difftime.c, ialloc.c, localtime.c, scheck.c:
* strftime.c, zdump.c, zic.c: Remove elsieid.
* private.h: Remove privatehid.
* tzfile.h: Remove tzfilehid.
* tzselect.h (TZCODE_VERSION): Rename from VERSION.
* zdump.c, zic.c: Include "version.h",
and use TZCODE_VERSION instead of elsieid.
2012-07-18 17:30:38 -07:00
|
|
|
#include "version.h"
|
1986-01-16 11:00:21 -05:00
|
|
|
|
1989-02-23 09:01:38 -05:00
|
|
|
/*
|
1989-03-22 19:56:23 -05:00
|
|
|
** This code has been made independent of the rest of the time
|
1989-02-23 09:01:38 -05:00
|
|
|
** conversion package to increase confidence in the verification it provides.
|
|
|
|
|
** You can use this code to help in verifying other implementations.
|
2014-08-24 14:54:30 -07:00
|
|
|
** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
|
1989-02-23 09:01:38 -05:00
|
|
|
*/
|
|
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
#ifndef NETBSD_INSPIRED
|
|
|
|
|
# define NETBSD_INSPIRED 1
|
|
|
|
|
#endif
|
2014-08-24 14:54:30 -07:00
|
|
|
#ifndef USE_LTZ
|
|
|
|
|
# define USE_LTZ 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if USE_LTZ
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
# include "private.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-19 18:16:15 -07:00
|
|
|
/* Enable tm_gmtoff and tm_zone on GNUish systems. */
|
|
|
|
|
#define _GNU_SOURCE 1
|
Port C macro defaults to Solaris and Irix.
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
2014-08-25 13:35:42 -07:00
|
|
|
/* Enable strtoimax on Solaris 10. */
|
|
|
|
|
#define __EXTENSIONS__ 1
|
2014-08-19 18:16:15 -07:00
|
|
|
|
1995-01-03 11:08:23 -05:00
|
|
|
#include "stdio.h" /* for stdout, stderr, perror */
|
1989-03-22 19:56:23 -05:00
|
|
|
#include "string.h" /* for strcpy */
|
|
|
|
|
#include "sys/types.h" /* for time_t */
|
|
|
|
|
#include "time.h" /* for struct tm */
|
1995-01-03 11:34:03 -05:00
|
|
|
#include "stdlib.h" /* for exit, malloc, atoi */
|
More C modernization.
* Makefile (typecheck): Add -D__time_t_defined to CFLAGS,
for glibc 2.15.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Omit 'register', as it adds no value these days. See Christos Zoulas in
<http://mm.icann.org/pipermail/tz/2012-October/018376.html>.
* date.c (netsettime) [TSP_SETDATE]: Add forward decl.
Don't rely on implicit int. Now static. Use NULL, not 0.
* zdump.c: Include "limits.h".
(absolute_min_time, absolute_max_time): Compute at compile-time,
as the run-time tests relied on undefined behavior.
(checkabsolutes): Rename from setabsolutes. Just check, since
there's nothing to set now. All uses changed.
2012-10-26 00:48:01 -07:00
|
|
|
#include "limits.h" /* for CHAR_BIT, LLONG_MAX */
|
2014-08-18 23:18:58 -07:00
|
|
|
#include <errno.h>
|
1995-01-03 11:08:23 -05:00
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
/*
|
|
|
|
|
** Substitutes for pre-C99 compilers.
|
|
|
|
|
** Much of this section of code is stolen from private.h.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_STDINT_H
|
|
|
|
|
# define HAVE_STDINT_H \
|
2014-03-26 18:16:48 -07:00
|
|
|
(199901 <= __STDC_VERSION__ \
|
|
|
|
|
|| 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
|
|
|
|
|
|| __CYGWIN__)
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#endif
|
|
|
|
|
#if HAVE_STDINT_H
|
|
|
|
|
# include "stdint.h"
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAVE_INTTYPES_H
|
|
|
|
|
# define HAVE_INTTYPES_H HAVE_STDINT_H
|
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_INTTYPES_H
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef INT_FAST32_MAX
|
|
|
|
|
# if INT_MAX >> 31 == 0
|
|
|
|
|
typedef long int_fast32_t;
|
|
|
|
|
# else
|
|
|
|
|
typedef int int_fast32_t;
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
Port C macro defaults to Solaris and Irix.
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
2014-08-25 13:35:42 -07:00
|
|
|
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
|
|
|
|
|
#if !defined LLONG_MAX && defined __LONG_LONG_MAX__
|
|
|
|
|
# define LLONG_MAX __LONG_LONG_MAX__
|
|
|
|
|
#endif
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#ifndef INTMAX_MAX
|
Port C macro defaults to Solaris and Irix.
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
2014-08-25 13:35:42 -07:00
|
|
|
# ifdef LLONG_MAX
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
typedef long long intmax_t;
|
2013-10-20 16:20:23 -07:00
|
|
|
# define strtoimax strtoll
|
Port C macro defaults to Solaris and Irix.
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
2014-08-25 13:35:42 -07:00
|
|
|
# define INTMAX_MAX LLONG_MAX
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# else
|
|
|
|
|
typedef long intmax_t;
|
2013-10-20 16:20:23 -07:00
|
|
|
# define strtoimax strtol
|
2013-08-15 00:29:21 -07:00
|
|
|
# define INTMAX_MAX LONG_MAX
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
Port C macro defaults to Solaris and Irix.
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
2014-08-25 13:35:42 -07:00
|
|
|
#ifndef PRIdMAX
|
|
|
|
|
# if INTMAX_MAX == LLONG_MAX
|
|
|
|
|
# define PRIdMAX "lld"
|
|
|
|
|
# else
|
|
|
|
|
# define PRIdMAX "ld"
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-19 18:16:15 -07:00
|
|
|
/* Infer TM_ZONE on systems where this information is known, but suppress
|
|
|
|
|
guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
|
|
|
|
|
#if (defined __GLIBC__ \
|
|
|
|
|
|| defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
|
|
|
|
|
|| (defined __APPLE__ && defined __MACH__))
|
|
|
|
|
# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
|
|
|
|
|
# define TM_GMTOFF tm_gmtoff
|
|
|
|
|
# endif
|
|
|
|
|
# if !defined TM_ZONE && !defined NO_TM_ZONE
|
|
|
|
|
# define TM_ZONE tm_zone
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-23 19:39:02 -07:00
|
|
|
#ifndef HAVE_LOCALTIME_R
|
|
|
|
|
# define HAVE_LOCALTIME_R 1
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
#ifndef HAVE_LOCALTIME_RZ
|
Port C macro defaults to Solaris and Irix.
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
2014-08-25 13:35:42 -07:00
|
|
|
# ifdef TM_ZONE
|
|
|
|
|
# define HAVE_LOCALTIME_RZ (NETBSD_INSPIRED && USE_LTZ)
|
|
|
|
|
# else
|
|
|
|
|
# define HAVE_LOCALTIME_RZ 0
|
|
|
|
|
# endif
|
2014-08-24 23:46:36 -07:00
|
|
|
#endif
|
|
|
|
|
|
2014-08-23 19:39:02 -07:00
|
|
|
#ifndef HAVE_TZSET
|
|
|
|
|
# define HAVE_TZSET 1
|
|
|
|
|
#endif
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
|
2004-11-18 13:04:19 -05:00
|
|
|
#ifndef ZDUMP_LO_YEAR
|
2004-11-22 10:46:46 -05:00
|
|
|
#define ZDUMP_LO_YEAR (-500)
|
2004-11-18 13:04:19 -05:00
|
|
|
#endif /* !defined ZDUMP_LO_YEAR */
|
|
|
|
|
|
|
|
|
|
#ifndef ZDUMP_HI_YEAR
|
2004-11-22 10:46:46 -05:00
|
|
|
#define ZDUMP_HI_YEAR 2500
|
2004-11-18 13:04:19 -05:00
|
|
|
#endif /* !defined ZDUMP_HI_YEAR */
|
|
|
|
|
|
1989-03-22 19:56:23 -05:00
|
|
|
#ifndef MAX_STRING_LENGTH
|
|
|
|
|
#define MAX_STRING_LENGTH 1024
|
|
|
|
|
#endif /* !defined MAX_STRING_LENGTH */
|
1986-01-16 11:00:21 -05:00
|
|
|
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
#if __STDC_VERSION__ < 199901
|
|
|
|
|
# define true 1
|
|
|
|
|
# define false 0
|
|
|
|
|
# define bool int
|
|
|
|
|
#else
|
|
|
|
|
# include <stdbool.h>
|
|
|
|
|
#endif
|
1989-03-22 19:56:23 -05:00
|
|
|
|
|
|
|
|
#ifndef EXIT_SUCCESS
|
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
|
#endif /* !defined EXIT_SUCCESS */
|
|
|
|
|
|
|
|
|
|
#ifndef EXIT_FAILURE
|
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
|
#endif /* !defined EXIT_FAILURE */
|
1986-03-04 10:38:47 -05:00
|
|
|
|
1989-02-23 09:01:38 -05:00
|
|
|
#ifndef SECSPERMIN
|
|
|
|
|
#define SECSPERMIN 60
|
|
|
|
|
#endif /* !defined SECSPERMIN */
|
|
|
|
|
|
1993-08-28 12:13:24 -04:00
|
|
|
#ifndef MINSPERHOUR
|
|
|
|
|
#define MINSPERHOUR 60
|
|
|
|
|
#endif /* !defined MINSPERHOUR */
|
|
|
|
|
|
1989-02-23 09:01:38 -05:00
|
|
|
#ifndef SECSPERHOUR
|
1993-08-28 12:13:24 -04:00
|
|
|
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
|
1989-02-23 09:01:38 -05:00
|
|
|
#endif /* !defined SECSPERHOUR */
|
|
|
|
|
|
|
|
|
|
#ifndef HOURSPERDAY
|
|
|
|
|
#define HOURSPERDAY 24
|
|
|
|
|
#endif /* !defined HOURSPERDAY */
|
|
|
|
|
|
|
|
|
|
#ifndef EPOCH_YEAR
|
|
|
|
|
#define EPOCH_YEAR 1970
|
|
|
|
|
#endif /* !defined EPOCH_YEAR */
|
|
|
|
|
|
1993-08-28 12:13:24 -04:00
|
|
|
#ifndef TM_YEAR_BASE
|
|
|
|
|
#define TM_YEAR_BASE 1900
|
|
|
|
|
#endif /* !defined TM_YEAR_BASE */
|
|
|
|
|
|
1989-02-23 09:01:38 -05:00
|
|
|
#ifndef DAYSPERNYEAR
|
|
|
|
|
#define DAYSPERNYEAR 365
|
|
|
|
|
#endif /* !defined DAYSPERNYEAR */
|
|
|
|
|
|
1993-08-28 12:23:51 -04:00
|
|
|
#ifndef isleap
|
2004-10-05 10:17:24 -04:00
|
|
|
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
|
1993-08-28 12:23:51 -04:00
|
|
|
#endif /* !defined isleap */
|
|
|
|
|
|
2004-10-05 10:17:24 -04:00
|
|
|
#ifndef isleap_sum
|
|
|
|
|
/*
|
2004-10-11 15:10:08 -04:00
|
|
|
** See tzfile.h for details on isleap_sum.
|
2004-10-05 10:17:24 -04:00
|
|
|
*/
|
2004-10-11 15:10:08 -04:00
|
|
|
#define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
|
2004-10-05 10:17:24 -04:00
|
|
|
#endif /* !defined isleap_sum */
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
|
2004-11-18 13:04:19 -05:00
|
|
|
#define SECSPERNYEAR (SECSPERDAY * DAYSPERNYEAR)
|
|
|
|
|
#define SECSPERLYEAR (SECSPERNYEAR + SECSPERDAY)
|
2013-08-15 00:29:21 -07:00
|
|
|
#define SECSPER400YEARS (SECSPERNYEAR * (intmax_t) (300 + 3) \
|
|
|
|
|
+ SECSPERLYEAR * (intmax_t) (100 - 3))
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
** True if SECSPER400YEARS is known to be representable as an
|
|
|
|
|
** intmax_t. It's OK that SECSPER400YEARS_FITS can in theory be false
|
|
|
|
|
** even if SECSPER400YEARS is representable, because when that happens
|
|
|
|
|
** the code merely runs a bit more slowly, and this slowness doesn't
|
|
|
|
|
** occur on any practical platform.
|
|
|
|
|
*/
|
|
|
|
|
enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 };
|
2004-11-18 13:04:19 -05:00
|
|
|
|
2007-12-03 09:42:13 -05:00
|
|
|
#ifndef HAVE_GETTEXT
|
|
|
|
|
#define HAVE_GETTEXT 0
|
|
|
|
|
#endif
|
2004-08-09 19:44:19 -04:00
|
|
|
#if HAVE_GETTEXT
|
1996-02-21 15:47:24 -05:00
|
|
|
#include "locale.h" /* for setlocale */
|
|
|
|
|
#include "libintl.h"
|
2004-08-09 19:44:19 -04:00
|
|
|
#endif /* HAVE_GETTEXT */
|
1996-02-21 15:47:24 -05:00
|
|
|
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
|
|
|
|
|
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
|
|
|
|
|
#else
|
|
|
|
|
# define ATTRIBUTE_PURE /* empty */
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-02-19 19:28:54 -05:00
|
|
|
/*
|
|
|
|
|
** For the benefit of GNU folk...
|
Don't abuse "`" to mean open quote.
This was appropriate before Unicode, where "`" and "'" often balanced
in visual output, but that's been obsolete for a while.
Overall, single-quote 'like this' instead of `like this', and
double-quote "like this" or (in typeset output) “like this”
instead of ``like this''. While we're at it, fix some glitches
with hyphens versus minus versus en dash versus em dash.
* Makefile ($(MANTXTS)): Use UTF-8 locale to produce *.txt output.
* checktab.awk, tzselect.ksh:
Quote 'like this' in diagnostics, instead of `like this'.
* date.1, newctime.3, newtzset.3, time2posix.3, zic.8 (q, lq, rq):
New macros. Use them for better double-quoting in output.
* workman.sh: Tell Perl that its stdin and stdout are UTF-8.
* NEWS: Document this.
2014-06-15 13:27:37 -07:00
|
|
|
** '_(MSGID)' uses the current locale's message library string for MSGID.
|
1996-02-21 15:47:24 -05:00
|
|
|
** The default is to use gettext if available, and use MSGID otherwise.
|
1996-02-19 19:28:54 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _
|
2004-08-09 19:44:19 -04:00
|
|
|
#if HAVE_GETTEXT
|
1996-02-21 15:47:24 -05:00
|
|
|
#define _(msgid) gettext(msgid)
|
2004-08-09 19:44:19 -04:00
|
|
|
#else /* !HAVE_GETTEXT */
|
1996-02-21 15:47:24 -05:00
|
|
|
#define _(msgid) msgid
|
2004-08-09 19:44:19 -04:00
|
|
|
#endif /* !HAVE_GETTEXT */
|
1996-02-19 19:28:54 -05:00
|
|
|
#endif /* !defined _ */
|
|
|
|
|
|
2014-06-26 15:19:00 -07:00
|
|
|
#if !defined TZ_DOMAIN && defined HAVE_GETTEXT
|
2014-06-18 23:25:57 -07:00
|
|
|
# define TZ_DOMAIN "tz"
|
|
|
|
|
#endif
|
1996-02-21 15:47:24 -05:00
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
#if ! HAVE_LOCALTIME_RZ
|
|
|
|
|
# undef timezone_t
|
|
|
|
|
# define timezone_t char **
|
|
|
|
|
#endif
|
|
|
|
|
|
1988-02-18 09:02:16 -05:00
|
|
|
extern char ** environ;
|
2007-11-08 09:21:57 -05:00
|
|
|
extern int getopt(int argc, char * const argv[],
|
|
|
|
|
const char * options);
|
1988-02-18 09:02:16 -05:00
|
|
|
extern char * optarg;
|
|
|
|
|
extern int optind;
|
1989-03-22 19:56:23 -05:00
|
|
|
extern char * tzname[2];
|
1989-02-23 09:01:38 -05: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.
2013-05-27 14:01:55 -07:00
|
|
|
/* The minimum and maximum finite time values. */
|
More C modernization.
* Makefile (typecheck): Add -D__time_t_defined to CFLAGS,
for glibc 2.15.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Omit 'register', as it adds no value these days. See Christos Zoulas in
<http://mm.icann.org/pipermail/tz/2012-October/018376.html>.
* date.c (netsettime) [TSP_SETDATE]: Add forward decl.
Don't rely on implicit int. Now static. Use NULL, not 0.
* zdump.c: Include "limits.h".
(absolute_min_time, absolute_max_time): Compute at compile-time,
as the run-time tests relied on undefined behavior.
(checkabsolutes): Rename from setabsolutes. Just check, since
there's nothing to set now. All uses changed.
2012-10-26 00:48:01 -07:00
|
|
|
static time_t const absolute_min_time =
|
Remove attempt to support floating-point time_t.
It wasn't tested and probably never worked, no platform used it,
and the latest POSIX no longer allows it.
* Makefile (typecheck): Don't check time_t being 'double'.
* Theory: Document the change.
* difftime.c (difftime):
* localtime.c (differ_by_repeat, tzload, timesub, time2sub):
* private.h (time_t_min, time_t_max):
* zdump.c (absolute_min_time, absolute_max_time, tformat):
Don't try to support floating-point time_t.
* localtime.c, private.h, zdump.c: Don't include float.h.
* localtime.c (truncate_time, double_to_time):
* private.h (TYPE_INTEGRAL):
* zdump.c (checkabsolutes):
Remove; no longer needed. All uses removed.
* zdump.8 (LIMITATIONS): Remove discussion of floating-point time_t.
2013-08-12 01:41:34 -07:00
|
|
|
((time_t) -1 < 0
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
|
More C modernization.
* Makefile (typecheck): Add -D__time_t_defined to CFLAGS,
for glibc 2.15.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Omit 'register', as it adds no value these days. See Christos Zoulas in
<http://mm.icann.org/pipermail/tz/2012-October/018376.html>.
* date.c (netsettime) [TSP_SETDATE]: Add forward decl.
Don't rely on implicit int. Now static. Use NULL, not 0.
* zdump.c: Include "limits.h".
(absolute_min_time, absolute_max_time): Compute at compile-time,
as the run-time tests relied on undefined behavior.
(checkabsolutes): Rename from setabsolutes. Just check, since
there's nothing to set now. All uses changed.
2012-10-26 00:48:01 -07:00
|
|
|
: 0);
|
|
|
|
|
static time_t const absolute_max_time =
|
Remove attempt to support floating-point time_t.
It wasn't tested and probably never worked, no platform used it,
and the latest POSIX no longer allows it.
* Makefile (typecheck): Don't check time_t being 'double'.
* Theory: Document the change.
* difftime.c (difftime):
* localtime.c (differ_by_repeat, tzload, timesub, time2sub):
* private.h (time_t_min, time_t_max):
* zdump.c (absolute_min_time, absolute_max_time, tformat):
Don't try to support floating-point time_t.
* localtime.c, private.h, zdump.c: Don't include float.h.
* localtime.c (truncate_time, double_to_time):
* private.h (TYPE_INTEGRAL):
* zdump.c (checkabsolutes):
Remove; no longer needed. All uses removed.
* zdump.8 (LIMITATIONS): Remove discussion of floating-point time_t.
2013-08-12 01:41:34 -07:00
|
|
|
((time_t) -1 < 0
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
|
|
|
|
|
: -1);
|
2014-08-21 14:07:55 -07:00
|
|
|
static int longest;
|
1989-03-17 20:26:01 -05:00
|
|
|
static char * progname;
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
static bool warned;
|
|
|
|
|
static bool errout;
|
2004-11-18 13:04:19 -05:00
|
|
|
|
2014-08-23 15:24:33 -07:00
|
|
|
static char const *abbr(struct tm const *);
|
2014-08-15 23:45:46 -07:00
|
|
|
static intmax_t delta(struct tm *, struct tm *) ATTRIBUTE_PURE;
|
|
|
|
|
static void dumptime(struct tm const *);
|
2014-08-24 23:46:36 -07:00
|
|
|
static time_t hunt(timezone_t, char *, time_t, time_t);
|
|
|
|
|
static void show(timezone_t, char *, time_t, bool);
|
2014-08-15 23:45:46 -07:00
|
|
|
static const char *tformat(void);
|
|
|
|
|
static time_t yeartot(intmax_t) ATTRIBUTE_PURE;
|
1986-08-28 11:09:07 -04:00
|
|
|
|
2014-06-26 14:41:07 -07:00
|
|
|
/* Is A an alphabetic character in the C locale? */
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
static bool
|
2014-06-26 14:41:07 -07:00
|
|
|
is_alpha(char a)
|
|
|
|
|
{
|
|
|
|
|
switch (a) {
|
|
|
|
|
default:
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
return false;
|
2014-06-26 14:41:07 -07:00
|
|
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
|
|
|
|
|
case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
|
|
|
|
|
case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
|
|
|
|
|
case 'V': case 'W': case 'X': case 'Y': case 'Z':
|
|
|
|
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
|
|
|
|
|
case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
|
|
|
|
|
case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
|
|
|
|
|
case 'v': case 'w': case 'x': case 'y': case 'z':
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
return true;
|
2014-06-26 14:41:07 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 14:07:55 -07:00
|
|
|
/* Return A + B, exiting if the result would overflow. */
|
|
|
|
|
static size_t
|
|
|
|
|
sumsize(size_t a, size_t b)
|
|
|
|
|
{
|
|
|
|
|
size_t sum = a + b;
|
|
|
|
|
if (sum < a) {
|
|
|
|
|
fprintf(stderr, "%s: size overflow\n", progname);
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 19:39:02 -07:00
|
|
|
#if ! HAVE_TZSET
|
|
|
|
|
# undef tzset
|
|
|
|
|
# define tzset zdump_tzset
|
|
|
|
|
static void tzset(void) { }
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-09-21 16:45:04 -07:00
|
|
|
/* Assume gmtime_r works if localtime_r does.
|
|
|
|
|
A replacement localtime_r is defined below if needed. */
|
|
|
|
|
#if ! HAVE_LOCALTIME_R
|
|
|
|
|
|
|
|
|
|
# undef gmtime_r
|
|
|
|
|
# define gmtime_r zdump_gmtime_r
|
|
|
|
|
|
|
|
|
|
static struct tm *
|
|
|
|
|
gmtime_r(time_t *tp, struct tm *tmp)
|
|
|
|
|
{
|
|
|
|
|
struct tm *r = gmtime(tp);
|
|
|
|
|
if (r) {
|
|
|
|
|
*tmp = *r;
|
|
|
|
|
r = tmp;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-09-10 23:27:27 -07:00
|
|
|
/* Platforms with TM_ZONE don't need tzname, so they can use the
|
|
|
|
|
faster localtime_rz or localtime_r if available. */
|
2014-08-24 23:46:36 -07:00
|
|
|
|
2014-09-21 16:45:04 -07:00
|
|
|
#if defined TM_ZONE && HAVE_LOCALTIME_RZ
|
|
|
|
|
# define USE_LOCALTIME_RZ true
|
|
|
|
|
#else
|
|
|
|
|
# define USE_LOCALTIME_RZ false
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ! USE_LOCALTIME_RZ
|
2014-09-10 23:27:27 -07:00
|
|
|
|
|
|
|
|
# if !defined TM_ZONE || ! HAVE_LOCALTIME_R || ! HAVE_TZSET
|
2014-08-24 23:46:36 -07:00
|
|
|
# undef localtime_r
|
|
|
|
|
# define localtime_r zdump_localtime_r
|
|
|
|
|
static struct tm *
|
|
|
|
|
localtime_r(time_t *tp, struct tm *tmp)
|
|
|
|
|
{
|
|
|
|
|
struct tm *r = localtime(tp);
|
|
|
|
|
if (r) {
|
|
|
|
|
*tmp = *r;
|
|
|
|
|
r = tmp;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
# undef localtime_rz
|
|
|
|
|
# define localtime_rz zdump_localtime_rz
|
|
|
|
|
static struct tm *
|
|
|
|
|
localtime_rz(timezone_t rz, time_t *tp, struct tm *tmp)
|
|
|
|
|
{
|
|
|
|
|
return localtime_r(tp, tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ifdef TYPECHECK
|
|
|
|
|
# undef mktime_z
|
|
|
|
|
# define mktime_z zdump_mktime_z
|
|
|
|
|
static time_t
|
|
|
|
|
mktime_z(timezone_t tz, struct tm *tmp)
|
|
|
|
|
{
|
|
|
|
|
return mktime(tmp);
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
# undef tzalloc
|
|
|
|
|
# undef tzfree
|
|
|
|
|
# define tzalloc zdump_tzalloc
|
|
|
|
|
# define tzfree zdump_tzfree
|
|
|
|
|
|
|
|
|
|
static timezone_t
|
|
|
|
|
tzalloc(char const *val)
|
2014-08-21 14:07:55 -07:00
|
|
|
{
|
|
|
|
|
static char **fakeenv;
|
|
|
|
|
char **env = fakeenv;
|
|
|
|
|
char *env0;
|
|
|
|
|
if (! env) {
|
|
|
|
|
char **e = environ;
|
|
|
|
|
int to;
|
|
|
|
|
|
|
|
|
|
while (*e++)
|
|
|
|
|
continue;
|
|
|
|
|
env = malloc(sumsize(sizeof *environ,
|
|
|
|
|
(e - environ) * sizeof *environ));
|
|
|
|
|
if (! env) {
|
|
|
|
|
perror(progname);
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
to = 1;
|
|
|
|
|
for (e = environ; (env[to] = *e); e++)
|
|
|
|
|
to += strncmp(*e, "TZ=", 3) != 0;
|
|
|
|
|
}
|
|
|
|
|
env0 = malloc(sumsize(sizeof "TZ=", strlen(val)));
|
|
|
|
|
if (! env0) {
|
|
|
|
|
perror(progname);
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
env[0] = strcat(strcpy(env0, "TZ="), val);
|
|
|
|
|
environ = fakeenv = env;
|
2014-08-23 19:39:02 -07:00
|
|
|
tzset();
|
2014-08-24 23:46:36 -07:00
|
|
|
return env;
|
2014-08-21 14:07:55 -07:00
|
|
|
}
|
|
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
static void
|
|
|
|
|
tzfree(timezone_t env)
|
2014-08-23 19:39:02 -07:00
|
|
|
{
|
2014-08-24 23:46:36 -07:00
|
|
|
environ = env + 1;
|
|
|
|
|
free(env[0]);
|
2014-08-23 19:39:02 -07:00
|
|
|
}
|
2014-09-21 16:45:04 -07:00
|
|
|
#endif /* ! USE_LOCALTIME_RZ */
|
|
|
|
|
|
|
|
|
|
/* A UTC time zone, and its initializer. */
|
|
|
|
|
static timezone_t gmtz;
|
|
|
|
|
static void
|
|
|
|
|
gmtzinit(void)
|
|
|
|
|
{
|
|
|
|
|
if (USE_LOCALTIME_RZ) {
|
|
|
|
|
static char const utc[] = "UTC0";
|
|
|
|
|
gmtz = tzalloc(utc);
|
|
|
|
|
if (!gmtz) {
|
|
|
|
|
perror(utc);
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert *TP to UTC, storing the broken-down time into *TMP.
|
|
|
|
|
Return TMP if successful, NULL otherwise. This is like gmtime_r(TP, TMP),
|
|
|
|
|
except typically faster if USE_LOCALTIME_RZ. */
|
|
|
|
|
static struct tm *
|
|
|
|
|
my_gmtime_r(time_t *tp, struct tm *tmp)
|
|
|
|
|
{
|
|
|
|
|
return USE_LOCALTIME_RZ ? localtime_rz(gmtz, tp, tmp) : gmtime_r(tp, tmp);
|
|
|
|
|
}
|
2014-08-23 19:39:02 -07:00
|
|
|
|
2005-01-11 11:53:34 -05:00
|
|
|
#ifndef TYPECHECK
|
2014-08-24 23:46:36 -07:00
|
|
|
# define my_localtime_rz localtime_rz
|
2005-01-11 11:53:34 -05:00
|
|
|
#else /* !defined TYPECHECK */
|
2014-08-24 23:46:36 -07:00
|
|
|
|
2005-01-11 11:53:34 -05:00
|
|
|
static struct tm *
|
2014-08-24 23:46:36 -07:00
|
|
|
my_localtime_rz(timezone_t tz, time_t *tp, struct tm *tmp)
|
2005-01-11 11:53:34 -05:00
|
|
|
{
|
2014-08-24 23:46:36 -07:00
|
|
|
tmp = localtime_rz(tz, tp, tmp);
|
2014-08-23 19:39:02 -07:00
|
|
|
if (tmp) {
|
2005-01-11 11:53:34 -05:00
|
|
|
struct tm tm;
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register time_t t;
|
2005-01-11 11:53:34 -05:00
|
|
|
|
|
|
|
|
tm = *tmp;
|
2014-08-24 23:46:36 -07:00
|
|
|
t = mktime_z(tz, &tm);
|
2013-08-15 14:31:51 -07:00
|
|
|
if (t != *tp) {
|
2014-08-18 19:10:48 -07:00
|
|
|
fflush(stdout);
|
|
|
|
|
fprintf(stderr, "\n%s: ", progname);
|
|
|
|
|
fprintf(stderr, tformat(), *tp);
|
|
|
|
|
fprintf(stderr, " ->");
|
|
|
|
|
fprintf(stderr, " year=%d", tmp->tm_year);
|
|
|
|
|
fprintf(stderr, " mon=%d", tmp->tm_mon);
|
|
|
|
|
fprintf(stderr, " mday=%d", tmp->tm_mday);
|
|
|
|
|
fprintf(stderr, " hour=%d", tmp->tm_hour);
|
|
|
|
|
fprintf(stderr, " min=%d", tmp->tm_min);
|
|
|
|
|
fprintf(stderr, " sec=%d", tmp->tm_sec);
|
|
|
|
|
fprintf(stderr, " isdst=%d", tmp->tm_isdst);
|
|
|
|
|
fprintf(stderr, " -> ");
|
|
|
|
|
fprintf(stderr, tformat(), t);
|
|
|
|
|
fprintf(stderr, "\n");
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
errout = true;
|
2005-01-11 11:53:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
#endif /* !defined TYPECHECK */
|
|
|
|
|
|
2005-05-26 12:48:56 -04:00
|
|
|
static void
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
abbrok(const char *const abbrp, const char *const zone)
|
2005-05-26 12:48:56 -04:00
|
|
|
{
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register const char * cp;
|
|
|
|
|
register const char * wp;
|
2005-05-26 12:48:56 -04:00
|
|
|
|
|
|
|
|
if (warned)
|
|
|
|
|
return;
|
2005-11-21 11:03:30 -05:00
|
|
|
cp = abbrp;
|
2005-05-26 12:48:56 -04:00
|
|
|
wp = NULL;
|
2014-06-26 14:41:07 -07:00
|
|
|
while (is_alpha(*cp))
|
2005-05-26 12:48:56 -04:00
|
|
|
++cp;
|
2005-11-21 11:03:30 -05:00
|
|
|
if (cp - abbrp == 0)
|
2005-12-27 09:05:26 -05:00
|
|
|
wp = _("lacks alphabetic at start");
|
2005-12-22 10:20:44 -05:00
|
|
|
else if (cp - abbrp < 3)
|
2005-12-27 09:05:26 -05:00
|
|
|
wp = _("has fewer than 3 alphabetics");
|
2005-12-22 10:20:44 -05:00
|
|
|
else if (cp - abbrp > 6)
|
2005-12-27 09:05:26 -05:00
|
|
|
wp = _("has more than 6 alphabetics");
|
2005-05-26 12:48:56 -04:00
|
|
|
if (wp == NULL && (*cp == '+' || *cp == '-')) {
|
|
|
|
|
++cp;
|
2014-06-26 14:41:07 -07:00
|
|
|
if ('0' <= *cp && *cp <= '9')
|
|
|
|
|
if (*cp++ == '1' && '0' <= *cp && *cp <= '4')
|
|
|
|
|
cp++;
|
2005-12-22 10:20:44 -05:00
|
|
|
if (*cp != '\0')
|
2005-12-27 09:05:26 -05:00
|
|
|
wp = _("differs from POSIX standard");
|
2005-05-26 12:48:56 -04:00
|
|
|
}
|
|
|
|
|
if (wp == NULL)
|
|
|
|
|
return;
|
2014-08-18 19:10:48 -07:00
|
|
|
fflush(stdout);
|
|
|
|
|
fprintf(stderr,
|
2005-11-21 10:48:21 -05:00
|
|
|
_("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
|
2005-12-27 09:05:26 -05:00
|
|
|
progname, zone, abbrp, wp);
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
warned = errout = true;
|
2014-08-18 23:18:58 -07:00
|
|
|
}
|
|
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
/* Return a time zone abbreviation. If the abbreviation needs to be
|
|
|
|
|
saved, use *BUF (of size *BUFALLOC) to save it, and return the
|
|
|
|
|
abbreviation in the possibly-reallocated *BUF. Otherwise, just
|
|
|
|
|
return the abbreviation. Get the abbreviation from TMP.
|
2014-08-21 14:36:10 -07:00
|
|
|
Exit on memory allocation failure. */
|
2014-08-24 23:46:36 -07:00
|
|
|
static char const *
|
2014-08-21 14:36:10 -07:00
|
|
|
saveabbr(char **buf, size_t *bufalloc, struct tm const *tmp)
|
|
|
|
|
{
|
|
|
|
|
char const *ab = abbr(tmp);
|
2014-08-24 23:46:36 -07:00
|
|
|
if (HAVE_LOCALTIME_RZ)
|
|
|
|
|
return ab;
|
|
|
|
|
else {
|
|
|
|
|
size_t ablen = strlen(ab);
|
|
|
|
|
if (*bufalloc <= ablen) {
|
|
|
|
|
free(*buf);
|
2014-08-21 14:36:10 -07:00
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
/* Make the new buffer at least twice as long as the old,
|
|
|
|
|
to avoid O(N**2) behavior on repeated calls. */
|
|
|
|
|
*bufalloc = sumsize(*bufalloc, ablen + 1);
|
2014-08-21 14:36:10 -07:00
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
*buf = malloc(*bufalloc);
|
|
|
|
|
if (! *buf) {
|
|
|
|
|
perror(progname);
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2014-08-21 14:36:10 -07:00
|
|
|
}
|
2014-08-24 23:46:36 -07:00
|
|
|
return strcpy(*buf, ab);
|
2014-08-21 14:36:10 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-18 23:18:58 -07:00
|
|
|
static void
|
|
|
|
|
close_file(FILE *stream)
|
|
|
|
|
{
|
|
|
|
|
char const *e = (ferror(stream) ? _("I/O error")
|
|
|
|
|
: fclose(stream) != 0 ? strerror(errno) : NULL);
|
|
|
|
|
if (e) {
|
2014-08-18 23:24:44 -07:00
|
|
|
fprintf(stderr, "%s: %s\n", progname, e);
|
2014-08-18 23:18:58 -07:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2005-05-26 12:48:56 -04:00
|
|
|
}
|
|
|
|
|
|
2009-01-14 10:54:45 -05:00
|
|
|
static void
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
usage(FILE * const stream, const int status)
|
2009-01-14 10:54:45 -05:00
|
|
|
{
|
2014-08-18 19:10:48 -07:00
|
|
|
fprintf(stream,
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
_("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Report bugs to %s.\n"),
|
2012-11-12 21:52:35 -08:00
|
|
|
progname, progname, REPORT_BUGS_TO);
|
2014-08-18 23:18:58 -07:00
|
|
|
if (status == EXIT_SUCCESS)
|
|
|
|
|
close_file(stream);
|
2009-01-14 10:54:45 -05:00
|
|
|
exit(status);
|
|
|
|
|
}
|
|
|
|
|
|
1989-01-28 20:47:53 -05:00
|
|
|
int
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
main(int argc, char *argv[])
|
1986-01-16 11:00:21 -05:00
|
|
|
{
|
2014-08-23 18:10:54 -07:00
|
|
|
/* These are static so that they're initially zero. */
|
2014-08-21 14:36:10 -07:00
|
|
|
static char * abbrev;
|
|
|
|
|
static size_t abbrevsize;
|
2014-08-23 18:10:54 -07:00
|
|
|
static struct tm newtm;
|
|
|
|
|
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register int i;
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
register bool vflag;
|
|
|
|
|
register bool Vflag;
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register char * cutarg;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
register char * cuttimes;
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register time_t cutlotime;
|
|
|
|
|
register time_t cuthitime;
|
|
|
|
|
time_t now;
|
|
|
|
|
time_t t;
|
|
|
|
|
time_t newt;
|
|
|
|
|
struct tm tm;
|
|
|
|
|
register struct tm * tmp;
|
|
|
|
|
register struct tm * newtmp;
|
1986-01-16 11:00:21 -05: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.
2013-05-27 14:01:55 -07:00
|
|
|
cutlotime = absolute_min_time;
|
|
|
|
|
cuthitime = absolute_max_time;
|
2004-08-09 19:44:19 -04:00
|
|
|
#if HAVE_GETTEXT
|
2014-08-18 19:10:48 -07:00
|
|
|
setlocale(LC_ALL, "");
|
1996-02-21 15:47:24 -05:00
|
|
|
#ifdef TZ_DOMAINDIR
|
2014-08-18 19:10:48 -07:00
|
|
|
bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
|
2004-08-09 19:44:19 -04:00
|
|
|
#endif /* defined TEXTDOMAINDIR */
|
2014-08-18 19:10:48 -07:00
|
|
|
textdomain(TZ_DOMAIN);
|
2004-08-09 19:44:19 -04:00
|
|
|
#endif /* HAVE_GETTEXT */
|
1989-03-17 20:26:01 -05:00
|
|
|
progname = argv[0];
|
2003-07-29 13:10:05 -04:00
|
|
|
for (i = 1; i < argc; ++i)
|
|
|
|
|
if (strcmp(argv[i], "--version") == 0) {
|
2014-08-18 19:10:48 -07:00
|
|
|
printf("zdump %s%s\n", PKGVERSION, TZVERSION);
|
2014-08-18 23:18:58 -07:00
|
|
|
return EXIT_SUCCESS;
|
2009-01-14 10:54:45 -05:00
|
|
|
} else if (strcmp(argv[i], "--help") == 0) {
|
2009-10-27 10:42:45 -04:00
|
|
|
usage(stdout, EXIT_SUCCESS);
|
2003-07-29 13:10:05 -04:00
|
|
|
}
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
vflag = Vflag = false;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
cutarg = cuttimes = NULL;
|
|
|
|
|
for (;;)
|
|
|
|
|
switch (getopt(argc, argv, "c:t:vV")) {
|
|
|
|
|
case 'c': cutarg = optarg; break;
|
|
|
|
|
case 't': cuttimes = optarg; break;
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
case 'v': vflag = true; break;
|
|
|
|
|
case 'V': Vflag = true; break;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
case -1:
|
|
|
|
|
if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0))
|
|
|
|
|
goto arg_processing_done;
|
|
|
|
|
/* Fall through. */
|
|
|
|
|
default:
|
|
|
|
|
usage(stderr, EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
arg_processing_done:;
|
1993-08-28 12:23:51 -04: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.
2013-05-27 14:01:55 -07:00
|
|
|
if (vflag | Vflag) {
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
intmax_t lo;
|
|
|
|
|
intmax_t hi;
|
2013-10-20 16:20:23 -07:00
|
|
|
char *loend, *hiend;
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
register intmax_t cutloyear = ZDUMP_LO_YEAR;
|
|
|
|
|
register intmax_t cuthiyear = ZDUMP_HI_YEAR;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
if (cutarg != NULL) {
|
2013-10-20 16:20:23 -07:00
|
|
|
lo = strtoimax(cutarg, &loend, 10);
|
|
|
|
|
if (cutarg != loend && !*loend) {
|
|
|
|
|
hi = lo;
|
|
|
|
|
cuthiyear = hi;
|
|
|
|
|
} else if (cutarg != loend && *loend == ','
|
|
|
|
|
&& (hi = strtoimax(loend + 1, &hiend, 10),
|
|
|
|
|
loend + 1 != hiend && !*hiend)) {
|
|
|
|
|
cutloyear = lo;
|
2004-11-18 13:04:19 -05:00
|
|
|
cuthiyear = hi;
|
|
|
|
|
} else {
|
2014-08-18 19:10:48 -07:00
|
|
|
fprintf(stderr, _("%s: wild -c argument %s\n"),
|
2004-11-18 13:04:19 -05:00
|
|
|
progname, cutarg);
|
2014-08-18 23:18:58 -07:00
|
|
|
return EXIT_FAILURE;
|
2004-11-18 13:04:19 -05:00
|
|
|
}
|
2004-11-18 12:21:02 -05: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.
2013-05-27 14:01:55 -07:00
|
|
|
if (cutarg != NULL || cuttimes == NULL) {
|
|
|
|
|
cutlotime = yeartot(cutloyear);
|
|
|
|
|
cuthitime = yeartot(cuthiyear);
|
|
|
|
|
}
|
|
|
|
|
if (cuttimes != NULL) {
|
2013-10-20 16:20:23 -07:00
|
|
|
lo = strtoimax(cuttimes, &loend, 10);
|
|
|
|
|
if (cuttimes != loend && !*loend) {
|
|
|
|
|
hi = lo;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
if (hi < cuthitime) {
|
|
|
|
|
if (hi < absolute_min_time)
|
|
|
|
|
hi = absolute_min_time;
|
|
|
|
|
cuthitime = hi;
|
|
|
|
|
}
|
2013-10-20 16:20:23 -07:00
|
|
|
} else if (cuttimes != loend && *loend == ','
|
|
|
|
|
&& (hi = strtoimax(loend + 1, &hiend, 10),
|
|
|
|
|
loend + 1 != hiend && !*hiend)) {
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
if (cutlotime < lo) {
|
|
|
|
|
if (absolute_max_time < lo)
|
|
|
|
|
lo = absolute_max_time;
|
|
|
|
|
cutlotime = lo;
|
|
|
|
|
}
|
|
|
|
|
if (hi < cuthitime) {
|
|
|
|
|
if (hi < absolute_min_time)
|
|
|
|
|
hi = absolute_min_time;
|
|
|
|
|
cuthitime = hi;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-08-18 19:10:48 -07:00
|
|
|
fprintf(stderr,
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
_("%s: wild -t argument %s\n"),
|
|
|
|
|
progname, cuttimes);
|
2014-08-18 23:18:58 -07:00
|
|
|
return EXIT_FAILURE;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
1993-08-28 12:23:51 -04:00
|
|
|
}
|
2014-09-21 16:45:04 -07:00
|
|
|
gmtzinit();
|
2014-08-18 19:10:48 -07:00
|
|
|
now = time(NULL);
|
1986-03-03 23:15:08 -05:00
|
|
|
longest = 0;
|
2014-08-21 14:07:55 -07:00
|
|
|
for (i = optind; i < argc; i++) {
|
|
|
|
|
size_t arglen = strlen(argv[i]);
|
|
|
|
|
if (longest < arglen)
|
|
|
|
|
longest = arglen < INT_MAX ? arglen : INT_MAX;
|
1994-12-09 00:05:36 -05:00
|
|
|
}
|
2014-08-21 14:07:55 -07:00
|
|
|
|
1994-12-09 00:05:36 -05:00
|
|
|
for (i = optind; i < argc; ++i) {
|
2014-08-24 23:46:36 -07:00
|
|
|
timezone_t tz = tzalloc(argv[i]);
|
|
|
|
|
char const *ab;
|
|
|
|
|
if (!tz) {
|
2014-08-26 12:49:39 -07:00
|
|
|
perror(argv[i]);
|
2014-08-24 23:46:36 -07:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
if (! (vflag | Vflag)) {
|
2014-08-24 23:46:36 -07:00
|
|
|
show(tz, argv[i], now, false);
|
|
|
|
|
tzfree(tz);
|
1986-01-16 11:00:21 -05:00
|
|
|
continue;
|
1996-05-02 15:23:55 -04:00
|
|
|
}
|
Use bool for boolean.
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
2014-08-20 08:13:31 -07:00
|
|
|
warned = false;
|
2004-11-18 13:04:19 -05:00
|
|
|
t = absolute_min_time;
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
if (!Vflag) {
|
2014-08-24 23:46:36 -07:00
|
|
|
show(tz, argv[i], t, true);
|
2013-08-16 21:53:37 -07:00
|
|
|
t += SECSPERDAY;
|
2014-08-24 23:46:36 -07:00
|
|
|
show(tz, argv[i], t, true);
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
}
|
2004-11-22 10:46:46 -05:00
|
|
|
if (t < cutlotime)
|
|
|
|
|
t = cutlotime;
|
2014-08-24 23:46:36 -07:00
|
|
|
tmp = my_localtime_rz(tz, &t, &tm);
|
2014-08-23 19:39:02 -07:00
|
|
|
if (tmp)
|
2014-08-24 23:46:36 -07:00
|
|
|
ab = saveabbr(&abbrev, &abbrevsize, &tm);
|
2014-09-06 16:34:00 -07:00
|
|
|
while (t < cuthitime) {
|
|
|
|
|
newt = ((t < absolute_max_time - SECSPERDAY / 2
|
|
|
|
|
&& t + SECSPERDAY / 2 < cuthitime)
|
2013-08-16 21:53:37 -07:00
|
|
|
? t + SECSPERDAY / 2
|
2014-09-06 16:34:00 -07:00
|
|
|
: cuthitime);
|
2014-08-24 23:46:36 -07:00
|
|
|
newtmp = localtime_rz(tz, &newt, &newtm);
|
2005-01-31 14:06:05 -05:00
|
|
|
if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) :
|
2004-11-22 11:23:52 -05:00
|
|
|
(delta(&newtm, &tm) != (newt - t) ||
|
1989-03-17 20:26:01 -05:00
|
|
|
newtm.tm_isdst != tm.tm_isdst ||
|
2014-08-24 23:46:36 -07:00
|
|
|
strcmp(abbr(&newtm), ab) != 0)) {
|
|
|
|
|
newt = hunt(tz, argv[i], t, newt);
|
|
|
|
|
newtmp = localtime_rz(tz, &newt, &newtm);
|
2014-08-23 19:39:02 -07:00
|
|
|
if (newtmp)
|
2014-08-24 23:46:36 -07:00
|
|
|
ab = saveabbr(&abbrev, &abbrevsize,
|
|
|
|
|
&newtm);
|
1989-03-17 20:26:01 -05:00
|
|
|
}
|
1989-01-28 20:47:53 -05:00
|
|
|
t = newt;
|
|
|
|
|
tm = newtm;
|
2004-11-22 11:23:52 -05:00
|
|
|
tmp = newtmp;
|
1986-01-16 11:00:21 -05: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.
2013-05-27 14:01:55 -07:00
|
|
|
if (!Vflag) {
|
|
|
|
|
t = absolute_max_time;
|
2013-08-16 21:53:37 -07:00
|
|
|
t -= SECSPERDAY;
|
2014-08-24 23:46:36 -07:00
|
|
|
show(tz, argv[i], t, true);
|
2013-08-16 21:53:37 -07:00
|
|
|
t += SECSPERDAY;
|
2014-08-24 23:46:36 -07:00
|
|
|
show(tz, argv[i], t, true);
|
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.
2013-05-27 14:01:55 -07:00
|
|
|
}
|
2014-08-24 23:46:36 -07:00
|
|
|
tzfree(tz);
|
1986-01-16 11:00:21 -05:00
|
|
|
}
|
2014-08-18 23:18:58 -07:00
|
|
|
close_file(stdout);
|
|
|
|
|
if (errout && (ferror(stderr) || fclose(stderr) != 0))
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
return EXIT_SUCCESS;
|
1989-01-28 20:47:53 -05:00
|
|
|
}
|
|
|
|
|
|
2004-11-18 12:21:02 -05:00
|
|
|
static time_t
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
yeartot(const intmax_t y)
|
2004-11-18 12:21:02 -05:00
|
|
|
{
|
2013-08-15 00:29:21 -07:00
|
|
|
register intmax_t myy, seconds, years;
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
register time_t t;
|
2004-11-18 12:21:02 -05:00
|
|
|
|
|
|
|
|
myy = EPOCH_YEAR;
|
2004-11-18 13:04:19 -05:00
|
|
|
t = 0;
|
2013-08-15 00:29:21 -07:00
|
|
|
while (myy < y) {
|
|
|
|
|
if (SECSPER400YEARS_FITS && 400 <= y - myy) {
|
|
|
|
|
intmax_t diff400 = (y - myy) / 400;
|
|
|
|
|
if (INTMAX_MAX / SECSPER400YEARS < diff400)
|
|
|
|
|
return absolute_max_time;
|
|
|
|
|
seconds = diff400 * SECSPER400YEARS;
|
|
|
|
|
years = diff400 * 400;
|
|
|
|
|
} else {
|
2004-11-18 13:04:19 -05:00
|
|
|
seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR;
|
2013-08-15 00:29:21 -07:00
|
|
|
years = 1;
|
2004-11-18 12:21:02 -05:00
|
|
|
}
|
2013-08-15 00:29:21 -07:00
|
|
|
myy += years;
|
|
|
|
|
if (t > absolute_max_time - seconds)
|
|
|
|
|
return absolute_max_time;
|
|
|
|
|
t += seconds;
|
|
|
|
|
}
|
|
|
|
|
while (y < myy) {
|
|
|
|
|
if (SECSPER400YEARS_FITS && y + 400 <= myy && myy < 0) {
|
|
|
|
|
intmax_t diff400 = (myy - y) / 400;
|
|
|
|
|
if (INTMAX_MAX / SECSPER400YEARS < diff400)
|
|
|
|
|
return absolute_min_time;
|
|
|
|
|
seconds = diff400 * SECSPER400YEARS;
|
|
|
|
|
years = diff400 * 400;
|
|
|
|
|
} else {
|
|
|
|
|
seconds = isleap(myy - 1) ? SECSPERLYEAR : SECSPERNYEAR;
|
|
|
|
|
years = 1;
|
|
|
|
|
}
|
|
|
|
|
myy -= years;
|
|
|
|
|
if (t < absolute_min_time + seconds)
|
|
|
|
|
return absolute_min_time;
|
|
|
|
|
t -= seconds;
|
2004-11-18 12:21:02 -05:00
|
|
|
}
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
1993-10-15 12:25:50 -04:00
|
|
|
static time_t
|
2014-08-24 23:46:36 -07:00
|
|
|
hunt(timezone_t tz, char *name, time_t lot, time_t hit)
|
1989-01-28 20:47:53 -05:00
|
|
|
{
|
2014-08-21 14:36:10 -07:00
|
|
|
static char * loab;
|
|
|
|
|
static size_t loabsize;
|
2014-08-24 23:46:36 -07:00
|
|
|
char const * ab;
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
time_t t;
|
|
|
|
|
struct tm lotm;
|
|
|
|
|
register struct tm * lotmp;
|
|
|
|
|
struct tm tm;
|
|
|
|
|
register struct tm * tmp;
|
1989-01-28 20:47:53 -05:00
|
|
|
|
2014-08-24 23:46:36 -07:00
|
|
|
lotmp = my_localtime_rz(tz, &lot, &lotm);
|
2014-08-23 19:39:02 -07:00
|
|
|
if (lotmp)
|
2014-08-24 23:46:36 -07:00
|
|
|
ab = saveabbr(&loab, &loabsize, &lotm);
|
2004-11-29 12:47:51 -05:00
|
|
|
for ( ; ; ) {
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
time_t diff = hit - lot;
|
2004-11-29 12:47:51 -05:00
|
|
|
if (diff < 2)
|
|
|
|
|
break;
|
|
|
|
|
t = lot;
|
|
|
|
|
t += diff / 2;
|
1989-01-28 20:47:53 -05:00
|
|
|
if (t <= lot)
|
|
|
|
|
++t;
|
|
|
|
|
else if (t >= hit)
|
|
|
|
|
--t;
|
2014-08-24 23:46:36 -07:00
|
|
|
tmp = my_localtime_rz(tz, &t, &tm);
|
2004-11-29 12:47:51 -05:00
|
|
|
if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) :
|
|
|
|
|
(delta(&tm, &lotm) == (t - lot) &&
|
1989-03-17 20:26:01 -05:00
|
|
|
tm.tm_isdst == lotm.tm_isdst &&
|
2014-08-24 23:46:36 -07:00
|
|
|
strcmp(abbr(&tm), ab) == 0)) {
|
1989-02-27 09:26:06 -05:00
|
|
|
lot = t;
|
|
|
|
|
lotm = tm;
|
2004-11-29 12:47:51 -05:00
|
|
|
lotmp = tmp;
|
1989-01-28 20:47:53 -05:00
|
|
|
} else hit = t;
|
|
|
|
|
}
|
2014-08-24 23:46:36 -07:00
|
|
|
show(tz, name, lot, true);
|
|
|
|
|
show(tz, name, hit, true);
|
1993-10-15 12:25:50 -04:00
|
|
|
return hit;
|
1989-01-28 20:47:53 -05:00
|
|
|
}
|
|
|
|
|
|
1993-09-05 21:20:54 -04:00
|
|
|
/*
|
2005-11-28 14:56:51 -05:00
|
|
|
** Thanks to Paul Eggert for logic used in delta.
|
1993-09-05 21:20:54 -04:00
|
|
|
*/
|
|
|
|
|
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
static intmax_t
|
Assume C89.
* Makefile (GCC_DEBUG_FLAGS): Modernize for GCC 4.6.3 x86.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, wildinput, nondigit, oops, display)
(timeout, sametm, netsettime):
* difftime.c (difftime):
* ialloc.c (icatalloc, icpyalloc):
* localtime.c (detzcode, detzcode64, differ_by_repeat)
(tzload, typesequiv, getzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, gmtload, tzsetwall, tzset)
(localsub, localtime, localtime_r, gmtsub, gmtime, gmtime_r)
(offtime, leaps_thru_end_of, timesub, ctime, ctime_r)
(increment_overflow, long_increment_overflow)
(normalize_overflow, long_normalize_overflow, tmcomp, time2sub)
(time2, time1, mktime, timelocal, timegm, timeoff, gtime)
(leapcorr, time2posix, posix2time):
* scheck.c (scheck):
* strftime.c (strftime, _fmt, _conv, _add, _yconv, _loc):
* zdump.c (my_localtime, abbrok, usage, main, yeartot)
(delta, abbr, dumptime):
* zic.c (memcheck, eats, eat, error, warning, main)
(dolink, itsdir, rcomp, associate, infile, gethms, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert)
(convert64, puttzcode, puttzcode64, atcomp, is32, writezone, DO)
(doabbr, updateminmax, stringoffset, stringrule, stringzone)
(outzone, addtt, addtype, leapadd, yearistype, lowerit, ciequal)
(itsabbr, byword, getfields, oadd, tadd, rpytime, newabbr)
(mkdirs, eitol):
Assume C89 or better. Mostly this consists of using function
prototypes. In a few places, prototypes are required for
portability to hosts where time_t does not promote to itself and
where a preceding prototype does not override a definition. But
while we're at it we might as well be consistent: it's safe to
assume at-least-C89 these days.
* ialloc.c (nonzero, imalloc, icalloc, irealloc, ifree, icfree):
Remove; no longer needed now that we assume C89 or better.
All callers changed to use malloc, calloc, realloc, free.
* localtime.c (getzname, getqzname, leaps_thru_end_of, transtime):
* zdump.c (delta, yeartot):
* zic.c (eitol):
Now pure.
* private.h, zdump.c (ATTRIBUTE_PURE): New macro.
* private.h (icalloc, imalloc, irealloc, icfree, ifree): Remove decls.
* zic.c: Remove no-longer-necessary forward decls.
(max_time, min_time): Now const.
(setboundaries): Remove.
2012-10-12 07:53:12 -07:00
|
|
|
delta(struct tm * newp, struct tm *oldp)
|
1989-01-28 20:47:53 -05:00
|
|
|
{
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
register intmax_t result;
|
|
|
|
|
register int tmy;
|
1989-01-28 20:47:53 -05:00
|
|
|
|
1993-08-28 12:23:51 -04:00
|
|
|
if (newp->tm_year < oldp->tm_year)
|
|
|
|
|
return -delta(oldp, newp);
|
|
|
|
|
result = 0;
|
|
|
|
|
for (tmy = oldp->tm_year; tmy < newp->tm_year; ++tmy)
|
2004-10-05 10:17:24 -04:00
|
|
|
result += DAYSPERNYEAR + isleap_sum(tmy, TM_YEAR_BASE);
|
1993-08-28 12:13:24 -04:00
|
|
|
result += newp->tm_yday - oldp->tm_yday;
|
|
|
|
|
result *= HOURSPERDAY;
|
|
|
|
|
result += newp->tm_hour - oldp->tm_hour;
|
|
|
|
|
result *= MINSPERHOUR;
|
|
|
|
|
result += newp->tm_min - oldp->tm_min;
|
|
|
|
|
result *= SECSPERMIN;
|
|
|
|
|
result += newp->tm_sec - oldp->tm_sec;
|
|
|
|
|
return result;
|
1986-01-16 11:00:21 -05:00
|
|
|
}
|
1986-03-02 22:03:39 -05:00
|
|
|
|
2014-10-04 17:38:05 -07:00
|
|
|
#ifndef TM_GMTOFF
|
2014-09-21 20:54:54 -07:00
|
|
|
/* Return A->tm_yday, adjusted to compare it fairly to B->tm_yday.
|
2014-10-04 17:38:05 -07:00
|
|
|
Assume A and B differ by at most one year. */
|
2014-09-21 20:54:54 -07:00
|
|
|
static int
|
|
|
|
|
adjusted_yday(struct tm const *a, struct tm const *b)
|
|
|
|
|
{
|
|
|
|
|
int yday = a->tm_yday;
|
|
|
|
|
if (b->tm_year < a->tm_year)
|
|
|
|
|
yday += 365 + isleap_sum(b->tm_year, TM_YEAR_BASE);
|
|
|
|
|
return yday;
|
|
|
|
|
}
|
2014-10-04 17:38:05 -07:00
|
|
|
#endif
|
2014-09-21 20:54:54 -07:00
|
|
|
|
|
|
|
|
/* If A is the broken-down local time and B the broken-down UTC for
|
|
|
|
|
the same instant, return A's UTC offset in seconds, where positive
|
|
|
|
|
offsets are east of Greenwich. On failure, return LONG_MIN. */
|
|
|
|
|
static long
|
|
|
|
|
gmtoff(struct tm const *a, struct tm const *b)
|
|
|
|
|
{
|
|
|
|
|
#ifdef TM_GMTOFF
|
|
|
|
|
return a->TM_GMTOFF;
|
|
|
|
|
#else
|
|
|
|
|
if (! b)
|
|
|
|
|
return LONG_MIN;
|
|
|
|
|
else {
|
|
|
|
|
int ayday = adjusted_yday(a, b);
|
|
|
|
|
int byday = adjusted_yday(b, a);
|
|
|
|
|
int days = ayday - byday;
|
|
|
|
|
long hours = a->tm_hour - b->tm_hour + 24 * days;
|
|
|
|
|
long minutes = a->tm_min - b->tm_min + 60 * hours;
|
|
|
|
|
long seconds = a->tm_sec - b->tm_sec + 60 * minutes;
|
|
|
|
|
return seconds;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
1988-02-18 09:02:16 -05:00
|
|
|
static void
|
2014-08-24 23:46:36 -07:00
|
|
|
show(timezone_t tz, char *zone, time_t t, bool v)
|
1986-03-02 22:03:39 -05:00
|
|
|
{
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register struct tm * tmp;
|
2014-09-21 20:54:54 -07:00
|
|
|
register struct tm * gmtmp;
|
|
|
|
|
struct tm tm, gmtm;
|
1986-08-28 11:09:07 -04:00
|
|
|
|
2014-08-21 14:07:55 -07:00
|
|
|
printf("%-*s ", longest, zone);
|
2004-08-05 10:48:37 -04:00
|
|
|
if (v) {
|
2014-09-21 20:54:54 -07:00
|
|
|
gmtmp = my_gmtime_r(&t, &gmtm);
|
|
|
|
|
if (gmtmp == NULL) {
|
2014-08-18 19:10:48 -07:00
|
|
|
printf(tformat(), t);
|
2004-11-22 11:23:52 -05:00
|
|
|
} else {
|
2014-09-21 20:54:54 -07:00
|
|
|
dumptime(gmtmp);
|
2014-08-18 19:10:48 -07:00
|
|
|
printf(" UT");
|
2004-11-22 11:23:52 -05:00
|
|
|
}
|
2014-08-18 19:10:48 -07:00
|
|
|
printf(" = ");
|
2004-08-05 10:48:37 -04:00
|
|
|
}
|
2014-08-24 23:46:36 -07:00
|
|
|
tmp = my_localtime_rz(tz, &t, &tm);
|
2004-08-05 10:48:37 -04:00
|
|
|
dumptime(tmp);
|
2004-11-22 11:23:52 -05:00
|
|
|
if (tmp != NULL) {
|
|
|
|
|
if (*abbr(tmp) != '\0')
|
2014-08-18 19:10:48 -07:00
|
|
|
printf(" %s", abbr(tmp));
|
2004-11-22 11:23:52 -05:00
|
|
|
if (v) {
|
2014-09-21 20:54:54 -07:00
|
|
|
long off = gmtoff(tmp, gmtmp);
|
2014-08-18 19:10:48 -07:00
|
|
|
printf(" isdst=%d", tmp->tm_isdst);
|
2014-09-21 20:54:54 -07:00
|
|
|
if (off != LONG_MIN)
|
|
|
|
|
printf(" gmtoff=%ld", off);
|
2004-11-22 11:23:52 -05:00
|
|
|
}
|
1987-02-14 14:26:58 -05:00
|
|
|
}
|
2014-08-18 19:10:48 -07:00
|
|
|
printf("\n");
|
2005-05-26 12:48:56 -04:00
|
|
|
if (tmp != NULL && *abbr(tmp) != '\0')
|
|
|
|
|
abbrok(abbr(tmp), zone);
|
1986-03-02 22:03:39 -05:00
|
|
|
}
|
1989-03-17 20:26:01 -05:00
|
|
|
|
2014-08-23 15:24:33 -07:00
|
|
|
static char const *
|
2014-08-21 14:36:10 -07:00
|
|
|
abbr(struct tm const *tmp)
|
1989-03-17 20:26:01 -05:00
|
|
|
{
|
2014-08-23 15:24:33 -07:00
|
|
|
#ifdef TM_ZONE
|
|
|
|
|
return tmp->TM_ZONE;
|
|
|
|
|
#else
|
2014-09-21 22:00:16 -07:00
|
|
|
return (0 <= tmp->tm_isdst && tzname[0 < tmp->tm_isdst]
|
|
|
|
|
? tzname[0 < tmp->tm_isdst]
|
2014-08-23 15:24:33 -07:00
|
|
|
: "");
|
|
|
|
|
#endif
|
1989-03-17 20:26:01 -05:00
|
|
|
}
|
2004-08-05 10:48:37 -04:00
|
|
|
|
2004-12-30 08:46:00 -05:00
|
|
|
/*
|
|
|
|
|
** The code below can fail on certain theoretical systems;
|
|
|
|
|
** it works on all known real-world systems as of 2004-12-30.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static const char *
|
2007-12-03 09:42:13 -05:00
|
|
|
tformat(void)
|
2004-12-24 07:45:38 -05:00
|
|
|
{
|
|
|
|
|
if (0 > (time_t) -1) { /* signed */
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
if (sizeof (time_t) == sizeof (intmax_t))
|
|
|
|
|
return "%"PRIdMAX;
|
2004-12-24 07:45:38 -05:00
|
|
|
if (sizeof (time_t) > sizeof (long))
|
|
|
|
|
return "%lld";
|
2004-12-30 08:46:00 -05:00
|
|
|
if (sizeof (time_t) > sizeof (int))
|
2004-12-24 07:45:38 -05:00
|
|
|
return "%ld";
|
|
|
|
|
return "%d";
|
|
|
|
|
}
|
Port to NetBSD, where, e.g., 'time_t' is wider than 'long'.
I audited the code and fixed as many width-asssumptions as I could
find, including several places where the code assumed that 'time_t'
was no wider than 'long'; this assumption is not true on 32-bit
NetBSD platforms. This caught every problem that is already fixed
in the NetBSD zic.c, and caught quite a few more.
* Makefile: Add comments re HAVE_DOS_FILE_NAMES and HAVE_INTTYPES_H.
* date.c (checkfinal, netsettime): Don't use 'long' where 'int' will do.
* difftime.c (difftime): Mark with ATTRIBUTE_CONST.
Use uintmax_t, not unsigned long, for the widest unsigned integer type.
Use long double, not double, if time_t is wider than uintmax_t;
this can in theory help on nonstandard platforms, such as GCC
with 64-bit uintmax_t and 128-bit __int128_t.
* localtime.c (struct ttinfo.tt_gmtoff, struct rule.r_time)
(detzcode, getsecs, getoffset, gmtsub, localsub, increment_overflow32)
(normalize_overflow32, time1, time2, timesub, transtime, tzparse)
(time2sub, timeoff, gtime):
* tzfile.h (SECSPERDAY):
* zdump.c (SECSPERDAY):
* zic.c (convert, puttzcode):
Use int_fast32_t, not long, when all we care is that values up to
2**31 can be stored. This doesn't fix any bugs, but it allows
more opportunity for compiler optimization.
(struct lsinfo.ls_corr, timesub, leapcorr):
Use int_fast64_t, not long, when values up to 2**63 can be stored.
(timesub): Make it clearer when we are truncating 0.5 to 0.
(increment_overflow32): Rename from long_increment_overflow.
All uses changed.
(normalize_overflow32): Rename from long_normalize_overflow.
All uses changed.
* private.h (HAVE_INTTYPES_H, ATTRIBUTE_CONST): New macros.
Include <inttypes.h> if HAVE_INTTYPES_H.
(INT_FAST64_MIN, INT_FAST64_MAX, SCNdFAST64, int_fast32_t, PRIdMAX)
(uintmax_t, PRIuMAX, _Noreturn):
Define to reasonable values if it's an older compiler.
* scheck.c (scheck): Add support for arbitrary formats, such as
those that SCNdFAST64 can expand to, at the price of no longer
supporting weird conversion specs like "%[%]".
* strftime.c (_fmt): Use intmax_t and uintmax_t to format time_t,
not long and unsigned long.
* zdump.c (int_fast32_t, intmax_t, PRIdMAX, SCNdMAX):
Define for pre-C99 compilers, like private.h does.
(delta, yeartot, main): Use intmax_t, not long.
(hunt): Use time_t, not long, since the diff must be nonnegative.
(tformat): Allow for time_t wider than long.
* zic.c (ZIC_MIN, ZIC_MAX, SCNdZIC): New macros.
(OFFSET_STRLEN_MAXIMUM, RULE_STRLEN_MAXIMUM): Remove.
(struct rule): Make r_loyear, r_hiyear, r_tod, r_stdoff, z_gmtoff,
z_stdoff zic_t, not long.
(addtype, gethms, oadd, rpytime, tadd, gmtoffs, corr, inleap)
(stringoffset, stringrule, outzone, addtype, adjleap, rpytime)
(LDAYSPERWEEK):
Use zic_t, not long.
(leapminyear, leapmaxyear, min_year, max_year, rulesub, updateminmax)
(outzone, rpytime):
Use zic_t, not int.
(usage): Now _Noreturn.
(main): Use S_IWGRP, not 'unix', to determine whether to call umask.
(writezone): Omit unnecessary cast.
(mkdirs): Use HAVE_DOS_FILE_NAMES, not 'unix', to determine
whether to parse DOS file anmes.
(eitol): Remove; no longer needed.
2013-05-27 21:26:18 -07:00
|
|
|
#ifdef PRIuMAX
|
|
|
|
|
if (sizeof (time_t) == sizeof (uintmax_t))
|
|
|
|
|
return "%"PRIuMAX;
|
|
|
|
|
#endif
|
2004-12-24 07:45:38 -05:00
|
|
|
if (sizeof (time_t) > sizeof (unsigned long))
|
|
|
|
|
return "%llu";
|
2004-12-30 08:46:00 -05:00
|
|
|
if (sizeof (time_t) > sizeof (unsigned int))
|
2004-12-24 07:45:38 -05:00
|
|
|
return "%lu";
|
|
|
|
|
return "%u";
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-05 10:48:37 -04:00
|
|
|
static void
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
dumptime(register const struct tm *timeptr)
|
2004-08-05 10:48:37 -04:00
|
|
|
{
|
|
|
|
|
static const char wday_name[][3] = {
|
|
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
|
|
|
};
|
|
|
|
|
static const char mon_name[][3] = {
|
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
|
|
|
};
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register const char * wn;
|
|
|
|
|
register const char * mn;
|
|
|
|
|
register int lead;
|
|
|
|
|
register int trail;
|
2004-08-05 10:48:37 -04:00
|
|
|
|
2004-11-22 11:23:52 -05:00
|
|
|
if (timeptr == NULL) {
|
2014-08-18 19:10:48 -07:00
|
|
|
printf("NULL");
|
2004-11-22 11:23:52 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2004-08-11 12:06:12 -04:00
|
|
|
/*
|
2014-09-21 16:45:04 -07:00
|
|
|
** The packaged localtime_rz and gmtime_r never put out-of-range
|
2004-08-11 12:06:12 -04:00
|
|
|
** values in tm_wday or tm_mon, but since this code might be compiled
|
|
|
|
|
** with other (perhaps experimental) versions, paranoia is in order.
|
|
|
|
|
*/
|
2004-08-09 19:50:18 -04:00
|
|
|
if (timeptr->tm_wday < 0 || timeptr->tm_wday >=
|
|
|
|
|
(int) (sizeof wday_name / sizeof wday_name[0]))
|
|
|
|
|
wn = "???";
|
|
|
|
|
else wn = wday_name[timeptr->tm_wday];
|
|
|
|
|
if (timeptr->tm_mon < 0 || timeptr->tm_mon >=
|
|
|
|
|
(int) (sizeof mon_name / sizeof mon_name[0]))
|
|
|
|
|
mn = "???";
|
|
|
|
|
else mn = mon_name[timeptr->tm_mon];
|
2014-08-18 19:10:48 -07:00
|
|
|
printf("%.3s %.3s%3d %.2d:%.2d:%.2d ",
|
2004-08-05 10:48:37 -04:00
|
|
|
wn, mn,
|
|
|
|
|
timeptr->tm_mday, timeptr->tm_hour,
|
2004-10-14 13:00:48 -04:00
|
|
|
timeptr->tm_min, timeptr->tm_sec);
|
2004-10-14 13:57:18 -04:00
|
|
|
#define DIVISOR 10
|
2004-10-14 13:00:48 -04:00
|
|
|
trail = timeptr->tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR;
|
2004-10-18 11:37:53 -04:00
|
|
|
lead = timeptr->tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR +
|
|
|
|
|
trail / DIVISOR;
|
|
|
|
|
trail %= DIVISOR;
|
|
|
|
|
if (trail < 0 && lead > 0) {
|
2004-10-14 13:00:48 -04:00
|
|
|
trail += DIVISOR;
|
|
|
|
|
--lead;
|
2004-10-18 11:37:53 -04:00
|
|
|
} else if (lead < 0 && trail > 0) {
|
2004-10-14 13:00:48 -04:00
|
|
|
trail -= DIVISOR;
|
|
|
|
|
++lead;
|
|
|
|
|
}
|
|
|
|
|
if (lead == 0)
|
2014-08-18 19:10:48 -07:00
|
|
|
printf("%d", trail);
|
|
|
|
|
else printf("%d%d", lead, ((trail < 0) ? -trail : trail));
|
2004-08-05 10:48:37 -04:00
|
|
|
}
|