Problem reported by Leonardo Chiquitto in:
http://mm.icann.org/pipermail/tz/2015-May/022276.html
Apparently his zic was built with -DTZDEFAULT=\"/etc/localtime\".
* NEWS: Document this.
* zic.c (verror): Don't dump core if filename is NULL.
(main, infile, mkdirs): Omit unnecessary trailing \n in diagnostic.
(componentcheck, namecheck): Now returns bool. All callers changed.
(componentcheck): Make the diagnostics more understandable.
Don't exit on error, so that the user can see multiple errors.
(dolink, writezone): Don't namecheck here.
(inzsub, inlink): Do it here instead.
This generates better diagnostics, and avoids the bug, since
it doesn't apply namecheck to TZDEFAULT or to TZDEFRULES.
Problem reported by Joseph Myers in:
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00704.html
* localtime.c (detzcode, detzcode64): Don't rely on
undefined behavior with left shift into sign bit.
Port better to non-2's-complement machines.
* private.h (TWOS_COMPLEMENT, MAXVAL, MINVAL): New macros.
* private.h (time_t_min, time_t_max):
* zic.c (min_time, max_time): Use them to avoid undefined behavior.
* zdump.c (atime_shift): New constant.
(absolute_min_time, absolute_max_time):
Use it to avoid undefined behavior.
Its function 'scheck' can be done more efficiently inline.
* Makefile (TZCOBJS): Remove scheck.o.
(NONLIBSRCS): Remove scheck.c.
(scheck.o): Remove.
* private.h (scheck): Remove decl.
* scheck.c: Remove.
* zic.c (gethms, inleap, rulesub): Instead of scheck, use sscanf
directly, with %c appended to the format to detect excess input.
One of its functions, icpyalloc, duplicates the now-standard
function strdup, and we might as well use the standard function.
Its other function, icatalloc, is used only in O(N**2) algorithms
that can be rewritten to be O(N).
* Makefile: Mention HAVE_STRDUP in commentary.
(TZCOBJS): Remove ialloc.o.
(NONLIBSRCS): Remove ialloc.c.
(ialloc.o): Remove.
* ialloc.c: Remove.
* private.h (HAVE_STRDUP): New macro, defaulting to 1.
(icatalloc, icpyalloc): Remove decls.
* zic.c (end): Remove.
(strdup) [!HAVE_STRDUP]: New function.
(memcheck): Arg is no longer a const pointer, since the
result isn't.
(emalloc, erealloc, ecpyalloc): Now functions, not macros.
(ecpyalloc): Use strdup, not icpyalloc.
(ecatalloc): Remove. All callers changed.
(componentcheck): Check that file name components are nonempty;
otherwise, relname might return nonsense.
(relname): New function.
(dolink, itsdir, writezone): Use it.
(dolink, stringrule, stringzone):
Rewrite to avoid O(N**2) algorithm involving 'strcat' and 'end'.
(writezone): Use local, not static, to store fullname,
and free it before returning.
(doabbr, stringoffset): Return strlen of result.
* zic.c (warnings): New static var.
(warning): Set it here.
(size_product, growalloc, main): Translate diagnostic.
(verror): Don't increment errors here.
(error): Set it here.
(close_file): New function.
(usage, dolink, infile, writezone): Use it.
(usage): Fit diagnostic in output lines better.
(main): Prefer 'return X;' to 'exit(X);'.
(main, infile, mkdirs): Use 'warning' for warnings.
Check for stderr output error.
(dolink, mkdirs): Don't assume gettext preserves errno.
Although the cast to void in usage like '(void) printf ("Hello")'
may have been helpful decades ago when Lint Was Your Friend,
nowadays such casts are not helpful. The tz code is currently not
consistent about this: sometimes the casts are present, and
sometimes absent. As they make the code harder to read, let's
remove them.
* asctime.c, date.c, ialloc.c, localtime.c, strftime.c, zdump.c, zic.c:
Don't cast calls to 'void'.
* zic.8, NEWS: Say that "." and ".." file name
components are not allowed in output file names.
* zic.c (componentcheck, namecheck): Do not allow such
file name components.
* zic.c: Use angle brackets for <sys/stat.h>.
(dolink): Don't try to link from a directory, as this can
cause trouble on some systems when superuser.
(dolink, itsdir): Rewrite to avoid use of 'access', which is
problematic when setuid.
(itsdir): If S_ISDIR is defined, use plain 'stat' and S_ISDIR;
that's more reliable. Return -1 if trouble; all callers changed.
(mkdirs): Simplify by using mkdir-itsdir rather than
itsdir-mkdir-itsdir. Don't assume strerror preserves errno.
* zdump.c, zic.c: Don't include <ctype.h>, because the behavior if
its macros is locale-dependent if HAVE_GETTEXT, and we want the C
locale's semantics. Instead, use portable replacements for
ctype.h operations, with the desired semantics. All uses of
isalpha etc. replaced by calls to new functions is_alpha etc. or
by inline code.
(isascii): Remove.
(is_alpha): New function.
* zic.c (doabbr): Simplify by using is_alpha.
(is_space): New function.
* NEWS: Document the above.
* zic.c (componentcheck, namecheck): Warn about all '.'s in
the file name, not merely about "." and ".." file name components.
* zic.8 (DESCRIPTION), NEWS: Document this.
Also, document the longstanding exceptions to POSIX.
Derived from Arthur David Olson's patch in:
http://mm.icann.org/pipermail/tz/2014-June/021052.html
* Theory: Document the exceptional file name components in 'etcetera'
and 'backward' that contain '+' or digits, or are too long.
* zic.8 (DESCRIPTION): Document the change to zic.
* zic.c (component_length_check, namecheck): New functions.
(dolink, writezone): Use them to check that file name components
obey the POSIX rules, and do not contain "." or "..".
* NEWS: Document the above.
Most of this patch is to commentary, to distinguish better among
the similar characters hyphen '-', minus sign '−', en dash '–' (used
for ranges), and em dash '—'. Render ordinary dashes in text as
spaced en dashes, as this gives better-looking results in monospaced
fonts.
* yearistype.sh, zic.c: Reword diagnostics so that they do not use
hyphens as if they were dashes. Since we are sticking to ASCII in
programs, we can't use proper dashes in diagnostics.
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.
This should help forestall flame wars among competing camps of physicists.
(Thanks to James Cloos.)
* NEWS, zic.8 (NOTES): Document this.
* zic.c (BIG_BANG): Use - 2**59 rather than a more-precise estimate.
* zic.c (inleap): Reject leap seconds preceding big_bang_time.
(Thanks to Arthur David Olson.) Also, remove redundant test and cast.
* NEWS: Document this.
This works around Gnome bug 730332
<https://bugzilla.gnome.org/show_bug.cgi?id=730332>.
zic 2014c introduced the idea of generating a transition at the
minimum time value -2**63, to avoid ambiguities about what to do
before the first real transition. Through Glib release 2.40, the
interval_end function of Glib's gtimezone.c subtracts one from
this, to find the end time of the zeroth interval (i.e., the
interval containing all the "early" time stamps); this subtraction
typically overflows and wraps around to 2**63 - 1, which causes
Glib to go off the rails and assume that all time stamps are
"early". For example, Glib computes Sao Paulo time stamps as if
Brazil's circa-1913 rules were still in effect.
(Thanks to Leonardo Chiquitto for reporting the bug.)
Work around the bug by not generating time stamps equal to -2**63.
Come to think of it, time stamps before the Big Bang are physically
suspect anyway, so don't generate time stamps before the Big Bang.
* Makefile (GCC_DEBUG_FLAGS): Add comment re BIG_BANG.
* NEWS, zic.8 (NOTES): Document this.
* zic.c (BIG_BANG): New macro.
(big_bang_time): New constant.
(writezone, outzone, addtt): Compare to big_bang_time, not to
min_time, when deciding whether to output a time stamp.
* zic.c (writezone, outzone): Arrange things so that binary files
include "transition" entries for minimum time values; these
entries eliminate localtime guesswork in handling low-valued time
stamps. The bad news: binary files grow slightly as a result of
these changes. The good news: there are no changes in the output
of "zdump -v" applied to before-and-after versions of all the
binary files generated by a "make install".
These were part of commit fada9b7b05
dated 2013-05-23 12:19:13 -0700.
* zic.c (writezone): Don't set type 0 to that of lowest-valued time.
(writezone, outzone): Don't reserve type 0.
This lets zic handle the time rules of Troll station,
Antarctica. Adapted from a fix by Zefram in:
http://mm.icann.org/pipermail/tz/2014-March/020759.html
* zic.c (timecnt_alloc): New static var.
(attypes): Now a pointer to an array, not a fixed size array.
(writezone, addtt): Don't assume the number of times is less than
TZ_MAX_TIMES.
* NEWS: Document this.
Also, allocate memory faster by growing buffers by a factor of 1.5
each time, rather than simply adding 1 to the size.
* private.h (SIZE_MAX): New macro, for older systems lacking it.
* zic.c (nrules_alloc, nzones_alloc, nlinks_alloc): New static vars.
(memory_exhausted, size_product, growalloc): New functions.
(memcheck, inrule, inzsub, inlink, getfields): Use them.
* zic.c (outzone): Restore diagnostic that was inadvertently
suppressed by the 2013-09-08 change to the 400-years-hack.
This doesn't affect zic's binary output; it affects only the
diagnostics generated by 'zic -v'. The problem evinced itself
with Asia/Tehran, which currently should generate a diagnostic,
but doesn't without this patch.
* NEWS: Document the above.
MinGW problem reported by Theo Veenker in
<http://mm.icann.org/pipermail/tz/2013-September/020378.html>.
The patched code should work even on POSIXish hosts
where 'link' and 'symlink' fail for whatever reason,
e.g., if the destination file system is VFAT.
Also, the patch fixes some bugs when symlinks are used.
* Makefile (CFLAGS): Mention HAVE_LINK in the comment.
(TZDSRCS): Add asctime.o, since MinGW lacks asctime.
(TZDOBJS): Add asctime.c.
* private.h (HAVE_LINK): Default to 1.
* zic.c (link) [!HAVE_LINK]: New macro.
(symlink) [!HAVE_SYMLINK]: New macro.
(dolink): Fix some bugs when 'link' fails but 'symlink' succeeds.
Fall back on copying when both fail.
* NEWS: Document the above.
We don't know of any clients where this makes a difference, but it
is a more-conservative change, as in theory older clients could
reject version-3 format files merely because of the version number.
(ZIC_VERSION_PRE_2013): New macro.
(writezone): New arg 'version'. All callers changed.
(outzone): Output version-2 format files unless the capabilities
of version 3 are used.
Further testing found that it was incompatible with Ubuntu 12.04 glibc
so this feature requires redesign and more testing.
* Makefile (ZFLAGS): Remove comment about name and version info.
Make it an empty var instead.
* tzfile.5, tzfile.h: Remove description of meta-information.
* zic.8: Remove options -n and -o.
* zic.c: Don't include <stddef.h>.
(genoption, genoptions, genname, addgenoption, writevalue): Remove.
(usage, main, writezone): Remove support for -n and -o.
* tzfile.5: Be a bit more careful about wording for integers.
Use binary terminators for the byte strings, not newlines.
Add a size field. Terminate by another NUL. Mention where
future extensions are expected to go.
* zic.c (writezone): Implement this.
(addgenoption): Omit namelen check; no longer needed.
(writevalue): Remove.
* Makefile (ZFLAGS): Add a comment about how to enable meta-info.
* tzfile.5: Describe meta-information.
* zic.8: Document new options -n and -o, which cause zic to
generate meta-info.
* zic.c: Include <stddef.h>, for ptrdiff_t.
(genoption, genoptions, genname): New static vars.
(usage): Summarize new options.
(addgenoption, writevalue): New function.
(main, writezone): Add support for new options.
Derived from Zefram's patch mentioned in
<http://mm.icann.org/pipermail/tz/2013-July/019470.html>.
With the current tz data, this affects only the Asia/Tehran file,
and it doesn't affect zdump output.
(YEAR_BY_YEAR_ZONE): New constant.
(stringzone): Return it when applicable.
(outzone): Search through a couple of extra years when extending.
Extend when we ran past 2037 in the data, too.
Also, improve the documentation and diagnostics in this area.
Suggested by Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2013-September/020064.html>.
* tzfile.5, tzfile.h: Bump tzfile format to version 3.
* zic.8: Document -v better.
* zic.c (ZIC_VERSION): Bump from '2' to '3'.
(stringrule, stringzone, outzone): Report compatibility issues
more carefully, mentioning client dates.
Since we assume C89 now, it's safe to use vfprintf.
(verror): New function, with the old implementation of 'error'
but with a va_list API.
(error, warning): Use it.
(associate, gethms): Pass explicit %s to avoid GCC warning about
possibly unsafe formats.
(inzone, outzone, newabbr): Simplify by using the new error or
warning functions, avoiding the need to allocate and free memory.
* private.h (ATTRIBUTE_FORMAT): New macro.
Problem reported by Zefram in
<http://mm.icann.org/pipermail/tz/2013-September/020059.html>.
* localtime.c (tzparse): Elide simultaneous entries out of and
into DST if DST goes for an hour more than a year (actually, for
more than the DST offset more than a year). Since this
optimization can elide all entries, avoid looping forever looking
for entries that will never arrive. While we're at it, fix
another portability bug where the code assumed wraparound on
signed integer overflow.
* newtzset.3, tzfile.5: Mention that as an extension to POSIX,
if DST covers the entire year plus the DST offset, it's assumed to
be in effect all year. Give an example.
* zic.c (stringrule): Omit the "J" in January and February,
as this can save a byte or two in the output.
(rule_cmp): New function.
(stringzone): Do a better job of constructing the standard-time
abbreviation when there is perpetual DST. Defer to the new
stringrule to construct the times for perpetual DST.
Fix bug noted by Zefram, which caused a stray hour of standard
time to be inserted in an otherwise perpetual DST.
Previously, this code generated "WARST4WARST,J1/0,J365/24"
for the San Luis example; now it generates "WART4WARST,0/0,J365/25".