Module Name:    src
Committed By:   christos
Date:           Sat Mar 11 18:23:14 UTC 2017

Modified Files:
        src/lib/libc/time: CONTRIBUTING Makefile NEWS README Theory asctime.c
            localtime.c private.h strftime.3 strftime.c tz-art.htm tz-link.htm
            version zdump.8 zdump.c zic.c

Log Message:
merge 2017a


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/time/CONTRIBUTING
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/time/Makefile
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/time/NEWS
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/time/README
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/time/Theory
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/time/asctime.c
cvs rdiff -u -r1.105 -r1.106 src/lib/libc/time/localtime.c
cvs rdiff -u -r1.49 -r1.50 src/lib/libc/time/private.h
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/time/strftime.3
cvs rdiff -u -r1.38 -r1.39 src/lib/libc/time/strftime.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/time/tz-art.htm \
    src/lib/libc/time/zdump.8
cvs rdiff -u -r1.29 -r1.30 src/lib/libc/time/tz-link.htm
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/time/version
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/time/zdump.c
cvs rdiff -u -r1.67 -r1.68 src/lib/libc/time/zic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/time/CONTRIBUTING
diff -u src/lib/libc/time/CONTRIBUTING:1.1 src/lib/libc/time/CONTRIBUTING:1.2
--- src/lib/libc/time/CONTRIBUTING:1.1	Tue Mar 15 11:16:01 2016
+++ src/lib/libc/time/CONTRIBUTING	Sat Mar 11 13:23:14 2017
@@ -18,10 +18,10 @@ data should contain commentary citing re
 justification.
 
 Please submit changes against either the latest release in
-<ftp://ftp.iana.org/tz/> or the master branch of the experimental
-Git repository.  If you use Git the following workflow may be helpful:
+<ftp://ftp.iana.org/tz/> or the master branch of the development
+repository.  If you use Git the following workflow may be helpful:
 
-  * Copy the experimental repository.
+  * Copy the development repository.
 
       git clone https://github.com/eggert/tz.git
       cd tz

Index: src/lib/libc/time/Makefile
diff -u src/lib/libc/time/Makefile:1.36 src/lib/libc/time/Makefile:1.37
--- src/lib/libc/time/Makefile:1.36	Fri Nov  4 15:41:53 2016
+++ src/lib/libc/time/Makefile	Sat Mar 11 13:23:14 2017
@@ -72,11 +72,11 @@ MANDIR=		$(TOPDIR)/man
 
 LIBDIR=		$(TOPDIR)/lib
 
-# If you always want time values interpreted as "seconds since the epoch
-# (not counting leap seconds)", use
+# If you want only POSIX time, with time values interpreted as
+# seconds since the epoch (not counting leap seconds), use
 #	REDO=		posix_only
-# below.  If you always want right time values interpreted as "seconds since
-# the epoch" (counting leap seconds)", use
+# below.  If you want want only "right" time, with values interpreted
+# as seconds since the epoch (counting leap seconds), use
 #	REDO=		right_only
 # below.  If you want both sets of data available, with leap seconds not
 # counted normally, use
@@ -85,7 +85,10 @@ LIBDIR=		$(TOPDIR)/lib
 # normally, use
 #	REDO=		right_posix
 # below.  POSIX mandates that leap seconds not be counted; for compatibility
-# with it, use "posix_only" or "posix_right".
+# with it, use "posix_only" or "posix_right".  Use POSIX time on systems with
+# leap smearing; this can work better than unsmeared "right" time with
+# applications that are not leap second aware, and is closer to unsmeared
+# "right" time than unsmeared POSIX time is (e.g., 0.5 vs 1.0 s max error).
 
 REDO=		posix_right
 
@@ -166,7 +169,7 @@ GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-co
 	-Wshadow -Wstrict-prototypes -Wsuggest-attribute=const \
 	-Wsuggest-attribute=format -Wsuggest-attribute=noreturn \
 	-Wsuggest-attribute=pure -Wtrampolines \
-	-Wunused -Wwrite-strings \
+	-Wundef -Wunused -Wwrite-strings \
 	-Wno-address -Wno-format-nonliteral -Wno-sign-compare \
 	-Wno-type-limits -Wno-unused-parameter
 #
@@ -543,7 +546,8 @@ force_tzs:	$(TZS_NEW)
 		cp $(TZS_NEW) $(TZS)
 
 libtz.a:	$(LIBOBJS)
-		$(AR) ru $@ $(LIBOBJS)
+		rm -f $@
+		$(AR) -rc $@ $(LIBOBJS)
 		$(RANLIB) $@
 
 date:		$(DATEOBJS)

Index: src/lib/libc/time/NEWS
diff -u src/lib/libc/time/NEWS:1.19 src/lib/libc/time/NEWS:1.20
--- src/lib/libc/time/NEWS:1.19	Fri Nov  4 15:41:53 2016
+++ src/lib/libc/time/NEWS	Sat Mar 11 13:23:14 2017
@@ -1,5 +1,154 @@
 News for the tz database
 
+Release 2017a - 2017-02-28 00:05:36 -0800
+
+  Briefly: Southern Chile moves from -04/-03 to -03, and Mongolia
+  discontinues DST.
+
+  Changes to future time stamps
+
+    Mongolia no longer observes DST.  (Thanks to Ganbold Tsagaankhuu.)
+
+    Chile's Region of Magallanes moves from -04/-03 to -03 year-round.
+    Its clocks diverge from America/Santiago starting 2017-05-13 at
+    23:00, hiving off a new zone America/Punta_Arenas.  Although the
+    Chilean government says this change expires in May 2019, for now
+    assume it's permanent.  (Thanks to Juan Correa and Deborah
+    Goldsmith.)  This also affects Antarctica/Palmer.
+
+  Changes to past time stamps
+
+    Fix many entries for historical time stamps for Europe/Madrid
+    before 1979, to agree with tables compiled by Pere Planesas of the
+    National Astronomical Observatory of Spain.  As a side effect,
+    this changes some time stamps for Africa/Ceuta before 1929, which
+    are probably guesswork anyway.  (Thanks to Steve Allen and
+    Pierpaolo Bernardi for the heads-ups, and to Michael Deckers for
+    correcting the 1901 transition.)
+
+    Ecuador observed DST from 1992-11-28 to 1993-02-05.
+    (Thanks to Alois Treindl.)
+
+    Asia/Atyrau and Asia/Oral were at +03 (not +04) before 1930-06-21.
+    (Thanks to Stepan Golosunov.)
+
+  Changes to past and future time zone abbreviations
+
+    Switch to numeric time zone abbreviations for South America, as
+    part of the ongoing project of removing invented abbreviations.
+    This avoids the need to invent an abbreviation for the new Chilean
+    new zone.  Similarly, switch from invented to numeric time zone
+    abbreviations for Afghanistan, American Samoa, the Azores,
+    Bangladesh, Bhutan, the British Indian Ocean Territory, Brunei,
+    Cape Verde, Chatham Is, Christmas I, Cocos (Keeling) Is, Cook Is,
+    Dubai, East Timor, Eucla, Fiji, French Polynesia, Greenland,
+    Indochina, Iran, Iraq, Kiribati, Lord Howe, Macquarie, Malaysia,
+    the Maldives, Marshall Is, Mauritius, Micronesia, Mongolia,
+    Myanmar, Nauru, Nepal, New Caledonia, Niue, Norfolk I, Palau,
+    Papua New Guinea, the Philippines, Pitcairn, Qatar, Réunion, St
+    Pierre & Miquelon, Samoa, Saudi Arabia, Seychelles, Singapore,
+    Solomon Is, Tokelau, Tuvalu, Wake, Vanuatu, Wallis & Futuna, and
+    Xinjiang; for 20-minute daylight saving time in Ghana before 1943;
+    for half-hour daylight saving time in Belize before 1944 and in
+    the Dominican Republic before 1975; and for Canary Islands before
+    1946, for Guinea-Bissau before 1975, for Iceland before 1969, for
+    Indian Summer Time before 1942, for Indonesia before around 1964,
+    for Kenya before 1960, for Liberia before 1973, for Madeira before
+    1967, for Namibia before 1943, for the Netherlands in 1937-9, for
+    Pakistan before 1971, for Western Sahara before 1977, and for
+    Zaporozhye in 1880-1924.
+
+    For Alaska time from 1900 through 1967, instead of "CAT" use the
+    abbreviation "AST", the abbreviation commonly used at the time
+    (Atlantic Standard Time had not been standardized yet).  Use "AWT"
+    and "APT" instead of the invented abbreviations "CAWT" and "CAPT".
+
+    Use "CST" and "CDT" instead of invented abbreviations for Macau
+    before 1999 and Taiwan before 1938, and use "JST" instead of the
+    invented abbreviation "JCST" for Japan and Korea before 1938.
+
+  Change to database entry category
+
+    Move the Pacific/Johnston link from 'australasia' to 'backward',
+    since Johnston is now uninhabited.
+
+  Changes to code
+
+    zic no longer mishandles some transitions in January 2038 when it
+    attempts to work around Qt bug 53071.  This fixes a bug affecting
+    Pacific/Tongatapu that was introduced in zic 2016e.  localtime.c
+    now contains a workaround, useful when loading a file generated by
+    a buggy zic.  (Problem and localtime.c fix reported by Bradley
+    White.)
+
+    zdump -i now outputs non-hour numeric time zone abbreviations
+    without a colon, e.g., "+0530" rather than "+05:30".  This agrees
+    with zic %z and with common practice, and simplifies auditing of
+    zdump output.
+
+    zdump is now buildable again with -DUSE_LTZ=0.
+    (Problem reported by Joseph Myers.)
+
+    zdump.c now always includes private.h, to avoid code duplication
+    with private.h.  (Problem reported by Kees Dekker.)
+
+    localtime.c no longer mishandles early or late timestamps
+    when TZ is set to a POSIX-style string that specifies DST.
+    (Problem reported by Kees Dekker.)
+
+    date and strftime now cause %z to generate "-0000" instead of
+    "+0000" when the UT offset is zero and the time zone abbreviation
+    begins with "-".
+
+  Changes to documentation and commentary
+
+    The 'Theory' file now better documents choice of historical time
+    zone abbreviations.  (Problems reported by Michael Deckers.)
+
+    tz-link.htm now covers leap smearing, which is popular in clouds.
+
+
+Release 2016j - 2016-11-22 23:17:13 -0800
+
+  Briefly: Saratov, Russia moves from +03 to +04 on 2016-12-04.
+
+  Changes to future time stamps
+
+    Saratov, Russia switches from +03 to +04 on 2016-12-04 at 02:00.
+    This hives off a new zone Europe/Saratov from Europe/Volgograd.
+    (Thanks to Yuri Konotopov and Stepan Golosunov.)
+
+  Changes to past time stamps
+
+    The new zone Asia/Atyrau for Atyraū Region, Kazakhstan, is like
+    Asia/Aqtau except it switched from +05/+06 to +04/+05 in spring
+    1999, not fall 1994.  (Thanks to Stepan Golosunov.)
+
+  Changes to past time zone abbreviations
+
+    Asia/Gaza and Asia/Hebron now use "EEST", not "EET", to denote
+    summer time before 1948.  The old use of "EET" was a typo.
+
+  Changes to code
+
+    zic no longer mishandles file systems that lack hard links, fixing
+    bugs introduced in 2016g.  (Problems reported by Tom Lane.)
+    Also, when the destination already contains symbolic links, zic
+    should now work better on systems where the 'link' system call
+    does not follow symbolic links.
+
+  Changes to documentation and commentary
+
+    tz-link.htm now documents the relationship between release version
+    numbers and development-repository commit tags.  (Suggested by
+    Paul Koning.)
+
+    The 'Theory' file now documents UT.
+
+    iso3166.tab now accents "Curaçao", and commentary now mentions
+    the names "Cabo Verde" and "Czechia".  (Thanks to Jiří Boháč.)
+
+
 Release 2016i - 2016-11-01 23:19:52 -0700
 
   Briefly: Cyprus split into two time zones on 2016-10-30, and Tonga
@@ -212,7 +361,7 @@ Release 2016g - 2016-09-13 08:56:38 -070
     23 commits and some working-file changes have been made since
     release 2016g, the version number is now something like
     '2016g-23-g50556e3-dirty' instead of the misleading '2016g'.
-    Official releases uses the same version number format as before,
+    Tagged releases use the same version number format as before,
     e.g., '2016g'.  To support the more-accurate version number, its
     specification has moved from a line in the Makefile to a new
     source file 'version'.
@@ -870,16 +1019,16 @@ Release 2014i - 2014-10-21 22:04:57 -070
     been fixed.  (Thanks to Christos Zoulas for reporting most of
     these problems and for suggesting fixes.)
 
-    If USG_COMPAT is defined and the requested time stamp is standard time,
+    If USG_COMPAT is defined and the requested timestamp is standard time,
     the tz library's localtime and mktime functions now set the extern
-    variable timezone to a value appropriate for that time stamp; and
+    variable timezone to a value appropriate for that timestamp; and
     similarly for ALTZONE, daylight saving time, and the altzone variable.
     This change is a companion to the tzname change in 2014h, and is
     designed to make timezone and altzone more compatible with tzname.
 
     The tz library's functions now set errno to EOVERFLOW if they fail
     because the result cannot be represented.  ctime and ctime_r now
-    return NULL and set errno when a time stamp is out of range, rather
+    return NULL and set errno when a timestamp is out of range, rather
     than having undefined behavior.
 
     Some bugs associated with the new 2014g functions have been fixed.
@@ -896,7 +1045,7 @@ Release 2014i - 2014-10-21 22:04:57 -070
 
 Release 2014h - 2014-09-25 18:59:03 -0700
 
-  Changes affecting past time stamps
+  Changes affecting past timestamps
 
     America/Jamaica's 1974 spring-forward transition was Jan. 6, not Apr. 28.
 
@@ -904,8 +1053,8 @@ Release 2014h - 2014-09-25 18:59:03 -070
     not 1920-01-06.  The old entry was based on a misinterpretation of Shanks.
 
     Some more zones have been turned into links, when they differed
-    from existing zones only for older time stamps.  As usual,
-    these changes affect UTC offsets in pre-1970 time stamps only.
+    from existing zones only for older timestamps.  As usual,
+    these changes affect UTC offsets in pre-1970 timestamps only.
     Their old contents have been moved to the 'backzone' file.
     The affected zones are: Africa/Blantyre, Africa/Bujumbura,
     Africa/Gaborone, Africa/Harare, Africa/Kigali, Africa/Lubumbashi,
@@ -917,7 +1066,7 @@ Release 2014h - 2014-09-25 18:59:03 -070
     not merely on platforms defining TM_GMTOFF.
 
     The tz library's localtime and mktime functions now set tzname to a value
-    appropriate for the requested time stamp, and zdump now uses this
+    appropriate for the requested timestamp, and zdump now uses this
     on platforms not defining TM_ZONE, fixing a 2014g regression.
     (Thanks to Tim Parenti for reporting the problem.)
 
@@ -957,13 +1106,13 @@ Release 2014h - 2014-09-25 18:59:03 -070
 
 Release 2014g - 2014-08-28 12:31:23 -0700
 
-  Changes affecting future time stamps
+  Changes affecting future timestamps
 
     Turks & Caicos is switching from US eastern time to UT -04
     year-round, modeled as a switch on 2014-11-02 at 02:00.
     [As noted in 2014j, this switch was later delayed.]
 
-  Changes affecting past time stamps
+  Changes affecting past timestamps
 
     Time in Russia or the USSR before 1926 or so has been corrected by
     a few seconds in the following zones: Asia/Irkutsk,
@@ -973,7 +1122,7 @@ Release 2014g - 2014-08-28 12:31:23 -070
     Vladimir Karpinsky.)
 
     The Portuguese decree of 1911-05-26 took effect on 1912-01-01.
-    This affects 1911 time stamps in Africa/Bissau, Africa/Luanda,
+    This affects 1911 timestamps in Africa/Bissau, Africa/Luanda,
     Atlantic/Azores, and Atlantic/Madeira.  Also, Lisbon's pre-1912
     GMT offset was -0:36:45 (rounded from -0:36:44.68), not -0:36:32.
     (Thanks to Stephen Colebourne for pointing to the decree.)
@@ -981,7 +1130,7 @@ Release 2014g - 2014-08-28 12:31:23 -070
     Asia/Dhaka ended DST on 2009-12-31 at 24:00, not 23:59.
 
     A new file 'backzone' contains data which may appeal to
-    connoisseurs of old time stamps, although it is out of scope for
+    connoisseurs of old timestamps, although it is out of scope for
     the tz database, is often poorly sourced, and contains some data
     that is known to be incorrect.  The new file is not recommended
     for ordinary use and its entries are not installed by default.
@@ -989,8 +1138,8 @@ Release 2014g - 2014-08-28 12:31:23 -070
     Isle of Man entries.)
 
     Some more zones have been turned into links, when they differed
-    from existing zones only for older time stamps.  As usual,
-    these changes affect UTC offsets in pre-1970 time stamps only.
+    from existing zones only for older timestamps.  As usual,
+    these changes affect UTC offsets in pre-1970 timestamps only.
     Their old contents have been moved to the 'backzone' file.
     The affected zones are: Africa/Bangui, Africa/Brazzaville,
     Africa/Douala, Africa/Kinshasa, Africa/Libreville, Africa/Luanda,
@@ -1041,7 +1190,7 @@ Release 2014g - 2014-08-28 12:31:23 -070
     but does not cause other problems such as traps.
 
     If TM_GMTOFF is defined and UNINIT_TRAP is 0, mktime is now
-    more likely to guess right for ambiguous time stamps near
+    more likely to guess right for ambiguous timestamps near
     transitions where tm_isdst does not change.
 
     If HAVE_STRFTIME_L is defined to 1, the tz library now defines
@@ -1114,7 +1263,7 @@ Release 2014g - 2014-08-28 12:31:23 -070
 
 Release 2014f - 2014-08-05 17:42:36 -0700
 
-  Changes affecting future time stamps
+  Changes affecting future timestamps
 
     Russia will subtract an hour from most of its time zones on 2014-10-26
     at 02:00 local time.  (Thanks to Alexander Krivenyshev.)
@@ -1165,20 +1314,20 @@ Release 2014f - 2014-08-05 17:42:36 -070
     These abbreviations are now used for time in Korea, Taiwan,
     and Sakhalin while controlled by Japan.
 
-  Changes affecting past time stamps
+  Changes affecting past timestamps
 
     China's five zones have been simplified to two, since the post-1970
     differences in the other three seem to have been imaginary.  The
     zones Asia/Harbin, Asia/Chongqing, and Asia/Kashgar have been
     removed; backwards-compatibility links still work, albeit with
-    different behaviors for time stamps before May 1980.  Asia/Urumqi's
+    different behaviors for timestamps before May 1980.  Asia/Urumqi's
     1980 transition to UT +08 has been removed, so that it is now at
     +06 and not +08.  (Thanks to Luther Ma and to Alois Treindl;
     Treindl sent helpful translations of two papers by Guo Qingsheng.)
 
     Some zones have been turned into links, when they differed from existing
     zones only for older UTC offsets where data entries were likely invented.
-    These changes affect UTC offsets in pre-1970 time stamps only.  This is
+    These changes affect UTC offsets in pre-1970 timestamps only.  This is
     similar to the change in release 2013e, except this time for western
     Africa.  The affected zones are: Africa/Bamako, Africa/Banjul,
     Africa/Conakry, Africa/Dakar, Africa/Freetown, Africa/Lome,
@@ -1323,7 +1472,7 @@ Release 2014f - 2014-08-05 17:42:36 -070
 
 Release 2014e - 2014-06-12 21:53:52 -0700
 
-  Changes affecting near-future time stamps
+  Changes affecting near-future timestamps
 
     Egypt's 2014 Ramadan-based transitions are June 26 and July 31 at 24:00.
     (Thanks to Imed Chihi.)  Guess that from 2015 on Egypt will temporarily
@@ -1335,7 +1484,7 @@ Release 2014e - 2014-06-12 21:53:52 -070
     temporarily switch to standard time at 03:00 the last Saturday before
     Ramadan, and back to DST at 02:00 the first Saturday after Ramadan.
 
-  Changes affecting past time stamps
+  Changes affecting past timestamps
 
     The abbreviation "MSM" (Moscow Midsummer Time) is now used instead of
     "MSD" for Moscow's double daylight time in summer 1921.  Also, a typo
@@ -1353,7 +1502,7 @@ Release 2014d - 2014-05-27 21:34:40 -070
 
   Changes affecting code
 
-    zic no longer generates files containing time stamps before the Big Bang.
+    zic no longer generates files containing timestamps before the Big Bang.
     This works around GNOME bug 730332
     <https://bugzilla.gnome.org/show_bug.cgi?id=730332>.
     (Thanks to Leonardo Chiquitto for reporting the bug, and to
@@ -1366,7 +1515,7 @@ Release 2014d - 2014-05-27 21:34:40 -070
 
 Release 2014c - 2014-05-13 07:44:13 -0700
 
-  Changes affecting near-future time stamps
+  Changes affecting near-future timestamps
 
     Egypt observes DST starting 2014-05-15 at 24:00.
     (Thanks to Ahmad El-Dardiry and Gunther Vermier.)
@@ -1380,7 +1529,7 @@ Release 2014c - 2014-05-13 07:44:13 -070
   Changes affecting code
 
     zic now generates transitions for minimum time values, eliminating guesswork
-    when handling low-valued time stamps.  (Thanks to Arthur David Olson.)
+    when handling low-valued timestamps.  (Thanks to Arthur David Olson.)
 
     Port to Cygwin sans glibc.  (Thanks to Arthur David Olson.)
 
@@ -1391,7 +1540,7 @@ Release 2014c - 2014-05-13 07:44:13 -070
 
 Release 2014b - 2014-03-24 21:28:50 -0700
 
-  Changes affecting near-future time stamps
+  Changes affecting near-future timestamps
 
     Crimea switches to Moscow time on 2014-03-30 at 02:00 local time.
     (Thanks to Alexander Krivenyshev.)  Move its zone.tab entry from UA to RU.
@@ -1430,12 +1579,12 @@ Release 2014b - 2014-03-24 21:28:50 -070
 
 Release 2014a - 2014-03-07 23:30:29 -0800
 
-  Changes affecting near-future time stamps
+  Changes affecting near-future timestamps
 
     Turkey begins DST on 2014-03-31, not 03-30.  (Thanks to Faruk Pasin for
     the heads-up, and to Tim Parenti for simplifying the update.)
 
-  Changes affecting past time stamps
+  Changes affecting past timestamps
 
     Fiji ended DST on 2014-01-19 at 02:00, not the previously-scheduled 03:00.
     (Thanks to Steffen Thorsen.)
@@ -1499,13 +1648,13 @@ Release 2014a - 2014-03-07 23:30:29 -080
 
 Release 2013i - 2013-12-17 07:25:23 -0800
 
-  Changes affecting near-future time stamps:
+  Changes affecting near-future timestamps:
 
     Jordan switches back to standard time at 00:00 on December 20, 2013.
     The 2006-2011 transition schedule is planned to resume in 2014.
     (Thanks to Steffen Thorsen.)
 
-  Changes affecting past time stamps:
+  Changes affecting past timestamps:
 
     In 2004, Cuba began DST on March 28, not April 4.
     (Thanks to Steffen Thorsen.)
@@ -1529,7 +1678,7 @@ Release 2013i - 2013-12-17 07:25:23 -080
 
 Release 2013h - 2013-10-25 15:32:32 -0700
 
-  Changes affecting current and future time stamps:
+  Changes affecting current and future timestamps:
 
     Libya has switched its UT offset back to +02 without DST, instead
     of +01 with DST.  (Thanks to Even Scharning.)
@@ -1537,7 +1686,7 @@ Release 2013h - 2013-10-25 15:32:32 -070
     Western Sahara (Africa/El_Aaiun) uses Morocco's DST rules.
     (Thanks to Gwillim Law.)
 
-  Changes affecting future time stamps:
+  Changes affecting future timestamps:
 
     Acre and (we guess) western Amazonas will switch from UT -04 to -05
     on 2013-11-10.  This affects America/Rio_Branco and America/Eirunepe.
@@ -1588,7 +1737,7 @@ Release 2013h - 2013-10-25 15:32:32 -070
 
 Release 2013g - 2013-09-30 21:08:26 -0700
 
-  Changes affecting current and near-future time stamps
+  Changes affecting current and near-future timestamps
 
     Morocco now observes DST from the last Sunday in March to the last
     Sunday in October, not April to September respectively.  (Thanks
@@ -1621,7 +1770,7 @@ Release 2013g - 2013-09-30 21:08:26 -070
 
 Release 2013f - 2013-09-24 23:37:36 -0700
 
-  Changes affecting near-future time stamps
+  Changes affecting near-future timestamps
 
     Tocantins will very likely not observe DST starting this spring.
     (Thanks to Steffen Thorsen.)
@@ -1668,7 +1817,7 @@ Release 2013f - 2013-09-24 23:37:36 -070
 
 Release 2013e - 2013-09-19 23:50:04 -0700
 
-  Changes affecting near-future time stamps
+  Changes affecting near-future timestamps
 
     This year Fiji will start DST on October 27, not October 20.
     (Thanks to David Wheeler for the heads-up.)  For now, guess that
@@ -1686,13 +1835,13 @@ Release 2013e - 2013-09-19 23:50:04 -070
     Use ART (UT -03, standard time), rather than WARST (also -03, but
     daylight saving time) for San Luis, Argentina since 2009.
 
-  Changes affecting Godthåb time stamps after 2037 if version mismatch
+  Changes affecting Godthåb timestamps after 2037 if version mismatch
 
     Allow POSIX-like TZ strings where the transition time's hour can
     range from -167 through 167, instead of the POSIX-required 0
     through 24.  E.g., TZ='FJT-12FJST,M10.3.1/146,M1.3.4/75' for the
     new Fiji rules.  This is a more-compact way to represent
-    far-future time stamps for America/Godthab, America/Santiago,
+    far-future timestamps for America/Godthab, America/Santiago,
     Antarctica/Palmer, Asia/Gaza, Asia/Hebron, Asia/Jerusalem,
     Pacific/Easter, and Pacific/Fiji.  Other zones are unaffected by
     this change.  (Derived from a suggestion by Arthur David Olson.)
@@ -1710,12 +1859,12 @@ Release 2013e - 2013-09-19 23:50:04 -070
     embedded TZ-format string, and the tz file format version number
     has therefore been increased from 2 to 3 as a precaution.
     Version-2-based client code should continue to work as before for
-    all time stamps before 2038.  Existing version-2-based client code
+    all timestamps before 2038.  Existing version-2-based client code
     (tzcode, GNU/Linux, Solaris) has been tested on version-3-format
-    files, and typically works in practice even for time stamps after
+    files, and typically works in practice even for timestamps after
     2037; the only known exception is America/Godthab.
 
-  Changes affecting time stamps before 1970
+  Changes affecting timestamps before 1970
 
     Pacific/Johnston is now a link to Pacific/Honolulu.  This corrects
     some errors before 1947.
@@ -1723,7 +1872,7 @@ Release 2013e - 2013-09-19 23:50:04 -070
     Some zones have been turned into links, when they differ from existing
     zones only in older data entries that were likely invented or that
     differ only in LMT or transitions from LMT.  These changes affect
-    only time stamps before 1943.  The affected zones are:
+    only timestamps before 1943.  The affected zones are:
     Africa/Juba, America/Anguilla, America/Aruba, America/Dominica,
     America/Grenada, America/Guadeloupe, America/Marigot,
     America/Montserrat, America/St_Barthelemy, America/St_Kitts,
@@ -1733,11 +1882,11 @@ Release 2013e - 2013-09-19 23:50:04 -070
     link is better for WWII-era times.)
 
     Change Kingston Mean Time from -5:07:12 to -5:07:11.  This affects
-    America/Cayman, America/Jamaica and America/Grand_Turk time stamps
+    America/Cayman, America/Jamaica and America/Grand_Turk timestamps
     from 1890 to 1912.
 
     Change the UT offset of Bern Mean Time from 0:29:44 to 0:29:46.
-    This affects Europe/Zurich time stamps from 1853 to 1894.  (Thanks
+    This affects Europe/Zurich timestamps from 1853 to 1894.  (Thanks
     to Alois Treindl).
 
     Change the date of the circa-1850 Zurich transition from 1849-09-12
@@ -1755,7 +1904,7 @@ Release 2013e - 2013-09-19 23:50:04 -070
     data can't be summarized using a TZ string, and uses a 402-year
     window rather than a 400-year window.  For the current data, this
     affects only the Asia/Tehran file.  It does not affect any of the
-    time stamps that this file represents, so zdump outputs the same
+    timestamps that this file represents, so zdump outputs the same
     information as before.  (Thanks to Andrew Main (Zefram).)
 
     The 'date' command has a new '-r' option, which lets you specify
@@ -1787,7 +1936,7 @@ Release 2013e - 2013-09-19 23:50:04 -070
   Changes affecting the zdump utility
 
     zdump now outputs "UT" when referring to Universal Time, not "UTC".
-    "UTC" does not make sense for time stamps that predate the introduction
+    "UTC" does not make sense for timestamps that predate the introduction
     of UTC, whereas "UT", a more-generic term, does.  (Thanks to Steve Allen
     for clarifying UT vs UTC.)
 
@@ -1798,7 +1947,7 @@ Release 2013e - 2013-09-19 23:50:04 -070
 
     Remove from zone.tab the names America/Montreal, America/Shiprock,
     and Antarctica/South_Pole, as they are equivalent to existing
-    same-country-code zones for post-1970 time stamps.  The data entries for
+    same-country-code zones for post-1970 timestamps.  The data entries for
     these names are unchanged, so the names continue to work as before.
 
   Changes affecting code internals
@@ -1858,7 +2007,7 @@ Release 2013e - 2013-09-19 23:50:04 -070
 
       There is a new section about the accuracy of the tz database,
       describing the many ways that errors can creep in, and
-      explaining why so many of the pre-1970 time stamps are wrong or
+      explaining why so many of the pre-1970 timestamps are wrong or
       misleading (thanks to Steve Allen, Lester Caine, and Garrett
       Wollman for discussions that contributed to this).
 
@@ -1893,7 +2042,7 @@ Release 2013e - 2013-09-19 23:50:04 -070
 
 Release 2013d - 2013-07-05 07:38:01 -0700
 
-  Changes affecting future time stamps:
+  Changes affecting future timestamps:
 
     Morocco's midsummer transitions this year are July 7 and August 10,
     not July 9 and August 8.  (Thanks to Andrew Paprocki.)
@@ -1901,7 +2050,7 @@ Release 2013d - 2013-07-05 07:38:01 -070
     Israel now falls back on the last Sunday of October.
     (Thanks to Ephraim Silverberg.)
 
-  Changes affecting past time stamps:
+  Changes affecting past timestamps:
 
     Specify Jerusalem's location more precisely; this changes the pre-1880
     times by 2 s.
@@ -1939,7 +2088,7 @@ Release 2013d - 2013-07-05 07:38:01 -070
 
 Release 2013c - 2013-04-19 16:17:40 -0700
 
-  Changes affecting current and future time stamps:
+  Changes affecting current and future timestamps:
 
     Palestine observed DST starting March 29, 2013.  (Thanks to
     Steffen Thorsen.)  From 2013 on, Gaza and Hebron both observe DST,
@@ -1950,7 +2099,7 @@ Release 2013c - 2013-04-19 16:17:40 -070
     by moving the end of DST to the 4th Sunday in March every year.
     (Thanks to Carlos Raúl Perasso.)
 
-  Changes affecting past time stamps:
+  Changes affecting past timestamps:
 
     Fix some historical data for Palestine to agree with that of
     timeanddate.com, as follows:
@@ -1984,10 +2133,10 @@ Release 2013c - 2013-04-19 16:17:40 -070
 
 Release 2013b - 2013-03-10 22:33:40 -0700
 
-  Changes affecting current and future time stamps:
+  Changes affecting current and future timestamps:
 
     Haiti uses US daylight-saving rules this year, and presumably future years.
-    This changes time stamps starting today.  (Thanks to Steffen Thorsen.)
+    This changes timestamps starting today.  (Thanks to Steffen Thorsen.)
 
     Paraguay will end DST on March 24 this year.
     (Thanks to Steffen Thorsen.)  For now, assume it's just this year.
@@ -2011,7 +2160,7 @@ Release 2013a - 2013-02-27 09:20:35 -080
     The zone offset at the end of version-2-format zone files is now
     allowed to be 24:00, as per POSIX.1-2008.  (Thanks to Arthur David Olson.)
 
-  Changes affecting current and future time stamps:
+  Changes affecting current and future timestamps:
 
     Chile's 2013 rules, and we guess rules for 2014 and later, will be
     the same as 2012, namely Apr Sun>=23 03:00 UTC to Sep Sun>=2 04:00 UTC.
@@ -2020,7 +2169,7 @@ Release 2013a - 2013-02-27 09:20:35 -080
     New Zones Asia/Khandyga, Asia/Ust-Nera, Europe/Busingen.
     (Thanks to Tobias Conradi and Arthur David Olson.)
 
-  Many changes affect historical time stamps before 1940.
+  Many changes affect historical timestamps before 1940.
   These were deduced from: Milne J. Civil time. Geogr J. 1899
   Feb;13(2):173-94 <http://www.jstor.org/stable/1774359>.
 
@@ -2152,7 +2301,7 @@ Release 2012e - 2012-08-02 20:44:55 -070
 
 Release code2012c-data2012d - 2012-07-19 16:35:33 -0700
 
-  Changes for Morocco's time stamps, which take effect in a couple of
+  Changes for Morocco's timestamps, which take effect in a couple of
   hours, along with infrastructure changes to accommodate how the tz
   code and data are released on IANA.
 
@@ -2296,12 +2445,12 @@ Release 2011e - 2011-03-31 16:04:38 -040
 
 Release 2011d - 2011-03-14 09:18:01 -0400
 
-  changes that impact present-day time stamps in Cuba, Samoa, and Turkey
+  changes that impact present-day timestamps in Cuba, Samoa, and Turkey
 
 
 Release 2011c - 2011-03-07 09:30:09 -0500
 
-  These do affect current time stamps in Chile and Annette Island, Canada.
+  These do affect current timestamps in Chile and Annette Island, Canada.
 
 
 Release 2011b - 2011-02-07 08:44:50 -0500
@@ -3766,7 +3915,7 @@ few (e.g., code2012c-data2012d) have tar
 numbers.  Recent releases also come in an experimental format
 consisting of a single tarball tzdb-R.tar.lz with extra data.
 
-Release time stamps are taken from the release's commit (for newer,
+Release timestamps are taken from the release's commit (for newer,
 Git-based releases), from the newest file in the tarball (for older
 releases, where this info is available) or from the email announcing
 the release (if all else fails; these are marked with a time zone of

Index: src/lib/libc/time/README
diff -u src/lib/libc/time/README:1.11 src/lib/libc/time/README:1.12
--- src/lib/libc/time/README:1.11	Fri Oct  7 11:29:42 2016
+++ src/lib/libc/time/README	Sat Mar 11 13:23:14 2017
@@ -10,24 +10,9 @@ locations around the globe.  It is updat
 changes made by political bodies to time zone boundaries, UTC offsets,
 and daylight-saving rules.
 
-Here is a recipe for acquiring, building, installing, and testing the
-tz distribution on a GNU/Linux or similar host.
-
-To acquire the distribution, run the following shell commands:
-
-	mkdir tz
-	cd tz
-	wget --retr-symlinks 'ftp://ftp.iana.org/tz/tz*-latest.tar.gz'
-	gzip -dc tzcode-latest.tar.gz | tar -xf -
-	gzip -dc tzdata-latest.tar.gz | tar -xf -
-
-Alternatively, the following shell commands acquire the same
-distribution, with extra data useful for regression testing:
-
-	wget --retr-symlinks 'ftp://ftp.iana.org/tz/tzdb-latest.tar.lz'
-	lzip -dc tzdb-latest.tar.lz | tar -xf -
-
-Be sure to read the comments in "Makefile" and make any changes needed
+See <https://www.iana.org/time-zones/repository/tz-link.html> or the
+file tz-link.htm for how to acquire the code and data.  Once acquired,
+read the comments in the file 'Makefile' and make any changes needed
 to make things right for your system, especially if you are using some
 platform other than GNU/Linux.  Then run the following commands,
 substituting your desired installation directory for "$HOME/tzdir":
@@ -60,10 +45,6 @@ Thanks in particular to Arthur David Ols
 maintainer, to whom the time zone community owes the greatest debt of all.
 None of them are responsible for remaining errors.
 
-Look in <ftp://ftp.iana.org/tz/releases/> for updated versions of these files.
-
-Please send comments or information to t...@iana.org.
-
 -----
 
 This file is in the public domain, so clarified as of 2009-05-17 by

Index: src/lib/libc/time/Theory
diff -u src/lib/libc/time/Theory:1.22 src/lib/libc/time/Theory:1.23
--- src/lib/libc/time/Theory:1.22	Thu Oct 20 13:41:34 2016
+++ src/lib/libc/time/Theory	Sat Mar 11 13:23:14 2017
@@ -8,6 +8,7 @@ Theory and pragmatics of the tz code and
 	Time zone abbreviations
 	Accuracy of the tz database
 	Time and date functions
+	Interface stability
 	Calendrical issues
 	Time and time zones on Mars
 
@@ -39,7 +40,7 @@ international standard for UNIX-like sys
 current edition of POSIX is:
 
   The Open Group Base Specifications Issue 7
-  IEEE Std 1003.1, 2013 Edition
+  IEEE Std 1003.1-2008, 2016 Edition
   <http://pubs.opengroup.org/onlinepubs/9699919799/>
 
 
@@ -208,6 +209,19 @@ in decreasing order of importance:
 	If there is no common English abbreviation, use numeric offsets like
 		-05 and +0830 that are generated by zic's %z notation.
 
+	Use current abbreviations for older timestamps to avoid confusion.
+		For example, in 1910 a common English abbreviation for UT +01
+		in central Europe was 'MEZ' (short for both "Middle European
+		Zone" and for "Mitteleuropäische Zeit" in German).  Nowadays
+		'CET' ("Central European Time") is more common in English, and
+		the database uses 'CET' even for circa-1910 timestamps as this
+		is less confusing for modern users and avoids the need for
+		determining when 'CET' supplanted 'MEZ' in common usage.
+
+	Use a consistent style in a zone's history.  For example, if a zone's
+		history tends to use numeric abbreviations and a particular
+		entry could go either way, use a numeric abbreviation.
+
     [The remaining guidelines predate the introduction of %z.
     They are problematic as they mean tz data entries invent
     notation rather than record it.  These guidelines are now
@@ -225,7 +239,7 @@ in decreasing order of importance:
 			for double summer time append 'DST'; etc.
 		Otherwise, take the first three letters of an English place
 			name identifying each zone and append 'T', 'ST', etc.
-			as before; e.g. 'VLAST' for VLAdivostok Summer Time.
+			as before; e.g. 'CHAST' for CHAtham Summer Time.
 
 	Use UT (with time zone abbreviation '-00') for locations while
 		uninhabited.  The leading '-' is a flag that the time
@@ -342,17 +356,29 @@ Errors in the tz database arise from man
    non-hour-based system at night.
 
  * Early clocks were less reliable, and data entries do not represent
-   this unreliability.
+   clock error.
 
- * As for leap seconds, civil time was not based on atomic time before
-   1972, and we don't know the history of earth's rotation accurately
-   enough to map SI seconds to historical solar time to more than
-   about one-hour accuracy.  See: Morrison LV, Stephenson FR.
-   Historical values of the Earth's clock error Delta T and the
-   calculation of eclipses. J Hist Astron. 2004;35:327-36
-   <http://adsabs.harvard.edu/full/2004JHA....35..327M>;
-   Historical values of the Earth's clock error. J Hist Astron. 2005;36:339
-   <http://adsabs.harvard.edu/full/2005JHA....36..339M>.
+ * The tz database assumes Universal Time (UT) as an origin, even
+   though UT is not standardized for older time stamps.  In the tz
+   database commentary, UT denotes a family of time standards that
+   includes Coordinated Universal Time (UTC) along with other variants
+   such as UT1 and GMT, with days starting at midnight.  Although UT
+   equals UTC for modern time stamps, UTC was not defined until 1960,
+   so commentary uses the more-general abbreviation UT for time stamps
+   that might predate 1960.  Since UT, UT1, etc. disagree slightly,
+   and since pre-1972 UTC seconds varied in length, interpretation of
+   older time stamps can be problematic when subsecond accuracy is
+   needed.
+
+ * Civil time was not based on atomic time before 1972, and we don't
+   know the history of earth's rotation accurately enough to map SI
+   seconds to historical solar time to more than about one-hour
+   accuracy.  See: Stephenson FR, Morrison LV, Hohenkerk CY.
+   Measurement of the Earth's rotation: 720 BC to AD 2015.
+   Proc Royal Soc A. 2016 Dec 7;472:20160404.
+   http://dx.doi.org/10.1098/rspa.2016.0404
+   Also see: Espenak F. Uncertainty in Delta T (ΔT).
+   http://eclipse.gsfc.nasa.gov/SEhelp/uncertainty2004.html
 
  * The relationship between POSIX time (that is, UTC but ignoring leap
    seconds) and UTC is not agreed upon after 1972.  Although the POSIX
@@ -601,10 +627,14 @@ The tz code and data supply the followin
 
  * The format of the country code file, documented in iso3166.tab.
 
-When these interfaces are changed, an effort is made to preserve
-backward compatibility.  For example, tz data files typically do not
-rely on recently-added zic features, so that users can run older zic
-versions to process newer data files.
+ * The version number of the code and data, as the first line of
+   the text file 'version' in each release.
+
+Interface changes in a release attempt to preserve compatibility with
+recent releases.  For example, tz data files typically do not rely on
+recently-added zic features, so that users can run older zic versions
+to process newer data files.  The tz-link.htm file describes how
+releases are tagged and distributed.
 
 Interfaces not listed above are less stable.  For example, users
 should not rely on particular UT offsets or abbreviations for time

Index: src/lib/libc/time/asctime.c
diff -u src/lib/libc/time/asctime.c:1.20 src/lib/libc/time/asctime.c:1.21
--- src/lib/libc/time/asctime.c:1.20	Thu Oct 23 14:45:58 2014
+++ src/lib/libc/time/asctime.c	Sat Mar 11 13:23:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: asctime.c,v 1.20 2014/10/23 18:45:58 christos Exp $	*/
+/*	$NetBSD: asctime.c,v 1.21 2017/03/11 18:23:14 christos Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -16,7 +16,7 @@
 #if 0
 static char	elsieid[] = "@(#)asctime.c	8.5";
 #else
-__RCSID("$NetBSD: asctime.c,v 1.20 2014/10/23 18:45:58 christos Exp $");
+__RCSID("$NetBSD: asctime.c,v 1.21 2017/03/11 18:23:14 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -24,7 +24,6 @@ __RCSID("$NetBSD: asctime.c,v 1.20 2014/
 
 #include "namespace.h"
 #include "private.h"
-#include "tzfile.h"
 
 #ifdef __weak_alias
 __weak_alias(asctime_r,_asctime_r)

Index: src/lib/libc/time/localtime.c
diff -u src/lib/libc/time/localtime.c:1.105 src/lib/libc/time/localtime.c:1.106
--- src/lib/libc/time/localtime.c:1.105	Fri Nov  4 15:41:53 2016
+++ src/lib/libc/time/localtime.c	Sat Mar 11 13:23:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.105 2016/11/04 19:41:53 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.106 2017/03/11 18:23:14 christos Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -10,7 +10,7 @@
 #if 0
 static char	elsieid[] = "@(#)localtime.c	8.17";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.105 2016/11/04 19:41:53 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.106 2017/03/11 18:23:14 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -27,7 +27,7 @@ __RCSID("$NetBSD: localtime.c,v 1.105 20
 #include "private.h"
 
 #include "tzfile.h"
-#include "fcntl.h"
+#include <fcntl.h>
 #include "reentrant.h"
 
 #if NETBSD_INSPIRED
@@ -621,12 +621,12 @@ tzloadbody(char const *name, struct stat
 			    && ts->typecnt == 2) {
 
 			  /* Attempt to reuse existing abbreviations.
-			     Without this, America/Anchorage would stop
-			     working after 2037 when TZ_MAX_CHARS is 50, as
-			     sp->charcnt equals 42 (for LMT CAT CAWT CAPT AHST
+			     Without this, America/Anchorage would be right on
+			     the edge after 2037 when TZ_MAX_CHARS is 50, as
+			     sp->charcnt equals 40 (for LMT AST AWT APT AHST
 			     AHDT YST AKDT AKST) and ts->charcnt equals 10
 			     (for AKST AKDT).  Reusing means sp->charcnt can
-			     stay 42 in this example.  */
+			     stay 40 in this example.  */
 			  int gotabbr = 0;
 			  int charcnt = sp->charcnt;
 			  for (i = 0; i < 2; i++) {
@@ -650,6 +650,15 @@ tzloadbody(char const *name, struct stat
 			  }
 			  if (gotabbr == 2) {
 			    sp->charcnt = charcnt;
+
+			    /* Ignore any trailing, no-op transitions generated
+			       by zic as they don't help here and can run afoul
+			       of bugs in zic 2016j or earlier.  */
+			    while (1 < sp->timecnt
+				   && (sp->types[sp->timecnt - 1]
+				       == sp->types[sp->timecnt - 2]))
+			      sp->timecnt--;
+
 			    for (i = 0; i < ts->timecnt; i++)
 			      if (sp->ats[sp->timecnt - 1] < ts->ats[i])
 				break;
@@ -1126,6 +1135,8 @@ tzparse(const char *name, struct state *
 			int		yearlim;
 			int		timecnt;
 			time_t		janfirst;
+			int_fast32_t janoffset = 0;
+			int yearbeg;
 
 			++name;
 			if ((name = getrule(name, &start)) == NULL)
@@ -1146,8 +1157,20 @@ tzparse(const char *name, struct state *
 			sp->defaulttype = 0;
 			timecnt = 0;
 			janfirst = 0;
-			yearlim = EPOCH_YEAR + YEARSPERREPEAT;
-			for (year = EPOCH_YEAR; year < yearlim; year++) {
+			yearbeg = EPOCH_YEAR;
+
+			do {
+			  int_fast32_t yearsecs
+			    = year_lengths[isleap(yearbeg - 1)] * SECSPERDAY;
+			  yearbeg--;
+			  if (increment_overflow_time(&janfirst, -yearsecs)) {
+			    janoffset = -yearsecs;
+			    break;
+			  }
+			} while (EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg);
+
+			yearlim = yearbeg + YEARSPERREPEAT + 1;
+			for (year = yearbeg; year < yearlim; year++) {
 				int_fast32_t
 				  starttime = transtime(year, &start, stdoffset),
 				  endtime = transtime(year, &end, dstoffset);
@@ -1167,24 +1190,32 @@ tzparse(const char *name, struct state *
 					       + (stdoffset - dstoffset))))) {
 					if (TZ_MAX_TIMES - 2 < timecnt)
 						break;
-					yearlim = year + YEARSPERREPEAT + 1;
 					sp->ats[timecnt] = janfirst;
-					if (increment_overflow_time
-					    (&sp->ats[timecnt], starttime))
-						break;
-					sp->types[timecnt++] = reversed;
+					if (! increment_overflow_time
+					    (&sp->ats[timecnt],
+					     janoffset + starttime))
+					  sp->types[timecnt++] = reversed;
+					else if (janoffset)
+					  sp->defaulttype = reversed;
 					sp->ats[timecnt] = janfirst;
-					if (increment_overflow_time
-					    (&sp->ats[timecnt], endtime))
-						break;
-					sp->types[timecnt++] = !reversed;
+					if (! increment_overflow_time
+					    (&sp->ats[timecnt],
+					     janoffset + endtime)) {
+					  sp->types[timecnt++] = !reversed;
+					  yearlim = year + YEARSPERREPEAT + 1;
+					} else if (janoffset)
+					  sp->defaulttype = !reversed;
 				}
-				if (increment_overflow_time(&janfirst, yearsecs))
+				if (increment_overflow_time
+				    (&janfirst, janoffset + yearsecs))
 					break;
+				janoffset = 0;
 			}
 			sp->timecnt = timecnt;
-			if (!timecnt)
+			if (! timecnt)
 				sp->typecnt = 1;	/* Perpetual DST.  */
+			else if (YEARSPERREPEAT < year - yearbeg)
+				sp->goback = sp->goahead = true;
 		} else {
 			int_fast32_t	theirstdoffset;
 			int_fast32_t	theirdstoffset;

Index: src/lib/libc/time/private.h
diff -u src/lib/libc/time/private.h:1.49 src/lib/libc/time/private.h:1.50
--- src/lib/libc/time/private.h:1.49	Fri Nov  4 21:08:58 2016
+++ src/lib/libc/time/private.h	Sat Mar 11 13:23:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: private.h,v 1.49 2016/11/05 01:08:58 christos Exp $	*/
+/*	$NetBSD: private.h,v 1.50 2017/03/11 18:23:14 christos Exp $	*/
 
 #ifndef PRIVATE_H
 #define PRIVATE_H
@@ -120,13 +120,13 @@
 #include "time.h"
 #endif
 
-#include "sys/types.h"	/* for time_t */
-#include "stdio.h"
-#include "string.h"
-#include "limits.h"	/* for CHAR_BIT et al. */
-#include "stdlib.h"
+#include <sys/types.h>	/* for time_t */
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>	/* for CHAR_BIT et al. */
+#include <stdlib.h>
 
-#include "errno.h"
+#include <errno.h>
 
 #ifndef ENAMETOOLONG
 # define ENAMETOOLONG EINVAL
@@ -139,7 +139,7 @@
 #endif
 
 #if HAVE_GETTEXT
-#include "libintl.h"
+#include <libintl.h>
 #endif /* HAVE_GETTEXT */
 
 #if HAVE_SYS_WAIT_H
@@ -154,7 +154,7 @@
 #endif /* !defined WEXITSTATUS */
 
 #if HAVE_UNISTD_H
-#include "unistd.h"	/* for F_OK, R_OK, and other POSIX goodness */
+#include <unistd.h>	/* for F_OK, R_OK, and other POSIX goodness */
 #endif /* HAVE_UNISTD_H */
 
 #ifndef HAVE_STRFTIME_L
@@ -189,7 +189,7 @@
 #endif /* !defined HAVE_STDINT_H */
 
 #if HAVE_STDINT_H
-#include "stdint.h"
+#include <stdint.h>
 #endif /* !HAVE_STDINT_H */
 
 #ifndef HAVE_INTTYPES_H
@@ -518,14 +518,8 @@ time_t time2posix_z(timezone_t __restric
 # include <stdbool.h>
 #endif
 
-#ifndef TYPE_BIT
 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
-#endif /* !defined TYPE_BIT */
-
-#ifndef TYPE_SIGNED
 #define TYPE_SIGNED(type) (/*CONSTCOND*/((type) -1) < 0)
-#endif /* !defined TYPE_SIGNED */
-
 #define TWOS_COMPLEMENT(t) (/*CONSTCOND*/(t) ~ (t) 0 < 0)
 
 /* Max and min values of the integer type T, of which only the bottom
@@ -562,7 +556,6 @@ static time_t const time_t_max = MAXVAL(
 #endif
 #endif
 
-#ifndef INT_STRLEN_MAXIMUM
 /*
 ** 302 / 1000 is log10(2.0) rounded up.
 ** Subtract one for the sign bit if the type is signed;
@@ -572,7 +565,6 @@ static time_t const time_t_max = MAXVAL(
 #define INT_STRLEN_MAXIMUM(type) \
 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
 	1 + TYPE_SIGNED(type))
-#endif /* !defined INT_STRLEN_MAXIMUM */
 
 /*
 ** INITIALIZE(x)
@@ -594,13 +586,11 @@ static time_t const time_t_max = MAXVAL(
 ** The default is to use gettext if available, and use MSGID otherwise.
 */
 
-#ifndef _
 #if HAVE_GETTEXT
 #define _(msgid) gettext(msgid)
 #else /* !HAVE_GETTEXT */
 #define _(msgid) msgid
 #endif /* !HAVE_GETTEXT */
-#endif /* !defined _ */
 
 #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
 # define TZ_DOMAIN "tz"
@@ -613,24 +603,70 @@ char *asctime_r(struct tm const *, char 
 char *ctime_r(time_t const *, char *);
 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
 
-#ifndef YEARSPERREPEAT
+/* Handy macros that are independent of tzfile implementation.  */
+
 #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
-#endif /* !defined YEARSPERREPEAT */
+
+#define SECSPERMIN	60
+#define MINSPERHOUR	60
+#define HOURSPERDAY	24
+#define DAYSPERWEEK	7
+#define DAYSPERNYEAR	365
+#define DAYSPERLYEAR	366
+#define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
+#define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
+#define MONSPERYEAR	12
+
+#define TM_SUNDAY	0
+#define TM_MONDAY	1
+#define TM_TUESDAY	2
+#define TM_WEDNESDAY	3
+#define TM_THURSDAY	4
+#define TM_FRIDAY	5
+#define TM_SATURDAY	6
+
+#define TM_JANUARY	0
+#define TM_FEBRUARY	1
+#define TM_MARCH	2
+#define TM_APRIL	3
+#define TM_MAY		4
+#define TM_JUNE		5
+#define TM_JULY		6
+#define TM_AUGUST	7
+#define TM_SEPTEMBER	8
+#define TM_OCTOBER	9
+#define TM_NOVEMBER	10
+#define TM_DECEMBER	11
+
+#define TM_YEAR_BASE	1900
+
+#define EPOCH_YEAR	1970
+#define EPOCH_WDAY	TM_THURSDAY
+
+#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+
+/*
+** Since everything in isleap is modulo 400 (or a factor of 400), we know that
+**	isleap(y) == isleap(y % 400)
+** and so
+**	isleap(a + b) == isleap((a + b) % 400)
+** or
+**	isleap(a + b) == isleap(a % 400 + b % 400)
+** This is true even if % means modulo rather than Fortran remainder
+** (which is allowed by C89 but not C99).
+** We use this to avoid addition overflow problems.
+*/
+
+#define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
+
 
 /*
 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
 */
 
-#ifndef AVGSECSPERYEAR
 #define AVGSECSPERYEAR		31556952L
-#endif /* !defined AVGSECSPERYEAR */
-
-#ifndef SECSPERREPEAT
-#define SECSPERREPEAT		((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
-#endif /* !defined SECSPERREPEAT */
-
-#ifndef SECSPERREPEAT_BITS
+#define SECSPERREPEAT \
+  ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
 #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
-#endif /* !defined SECSPERREPEAT_BITS */
 
 #endif /* !defined PRIVATE_H */

Index: src/lib/libc/time/strftime.3
diff -u src/lib/libc/time/strftime.3:1.32 src/lib/libc/time/strftime.3:1.33
--- src/lib/libc/time/strftime.3:1.32	Sat Dec 24 00:33:51 2016
+++ src/lib/libc/time/strftime.3	Sat Mar 11 13:23:14 2017
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)strftime.3	5.12 (Berkeley) 6/29/91
-.\"	$NetBSD: strftime.3,v 1.32 2016/12/24 05:33:51 abhinav Exp $
+.\"	$NetBSD: strftime.3,v 1.33 2017/03/11 18:23:14 christos Exp $
 .\"
-.Dd December 21, 2016
+.Dd March 11, 2017
 .Dt STRFTIME 3
 .Os
 .Sh NAME
@@ -194,7 +194,11 @@ is replaced by the offset from the Prime
 +HHMM or -HHMM (ISO 8601) as appropriate, with positive values representing
 locations east of Greenwich, or by the empty string if this is
 not determinable.
-.Dq Li [-]hhmm .
+The numeric time zone [-]0000 is used when the time is Universal Time
+but local time is indeterminate; by convention this is used for
+locations while uninhabited, and corresponds to a zero offset when the
+time zone abbreviation begins with
+.Dq Li [-] .
 .It Cm %%
 is replaced by
 .Ql % .

Index: src/lib/libc/time/strftime.c
diff -u src/lib/libc/time/strftime.c:1.38 src/lib/libc/time/strftime.c:1.39
--- src/lib/libc/time/strftime.c:1.38	Thu Oct 20 13:41:34 2016
+++ src/lib/libc/time/strftime.c	Sat Mar 11 13:23:14 2017
@@ -1,6 +1,6 @@
-/*	$NetBSD: strftime.c,v 1.38 2016/10/20 17:41:34 christos Exp $	*/
+/*	$NetBSD: strftime.c,v 1.39 2017/03/11 18:23:14 christos Exp $	*/
 
-/* Convert a broken-down time stamp to a string.  */
+/* Convert a broken-down timestamp to a string.  */
 
 /* Copyright 1989 The Regents of the University of California.
    All rights reserved.
@@ -35,7 +35,7 @@
 static char	elsieid[] = "@(#)strftime.c	7.64";
 static char	elsieid[] = "@(#)strftime.c	8.3";
 #else
-__RCSID("$NetBSD: strftime.c,v 1.38 2016/10/20 17:41:34 christos Exp $");
+__RCSID("$NetBSD: strftime.c,v 1.39 2017/03/11 18:23:14 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -65,9 +65,8 @@ __RCSID("$NetBSD: strftime.c,v 1.38 2016
 #undef TM_GMTOFF
 #endif
 
-#include "tzfile.h"
-#include "fcntl.h"
-#include "locale.h"
+#include <fcntl.h>
+#include <locale.h>
 
 #ifdef __weak_alias
 __weak_alias(strftime_l, _strftime_l)
@@ -498,6 +497,7 @@ label:
 				{
 				long		diff;
 				char const *	sign;
+				bool negative;
 
 				if (t->tm_isdst < 0)
 					continue;
@@ -566,7 +566,17 @@ label:
 				}
 #  endif
 # endif
-				if (diff < 0) {
+				negative = diff < 0;
+				if (diff == 0) {
+#ifdef TM_ZONE
+				  negative = t->TM_ZONE[0] == '-';
+#else
+				  negative
+				    = (t->tm_isdst < 0
+				       || tzname[t->tm_isdst != 0][0] == '-');
+#endif
+				}
+				if (negative) {
 					sign = "-";
 					diff = -diff;
 				} else	sign = "+";

Index: src/lib/libc/time/tz-art.htm
diff -u src/lib/libc/time/tz-art.htm:1.15 src/lib/libc/time/tz-art.htm:1.16
--- src/lib/libc/time/tz-art.htm:1.15	Fri Nov  4 15:41:53 2016
+++ src/lib/libc/time/tz-art.htm	Sat Mar 11 13:23:14 2017
@@ -157,14 +157,14 @@ savings days. Lousy farmers."
 "Tracks", <em>The Good Wife</em>, season 7, episode 12,
 CBS, 2016-01-17.
 The applicability of a contract hinges on the
-time zone associated with a video time stamp.
+time zone associated with a video timestamp.
 </li>
 </ul>
 <h2>Books, plays, and magazines</h2>
 <ul>
 <li>
 Jules Verne, <em>Around the World in Eighty Days</em>
-(<em>Le tour du monde en quatre-vingts jours</em>).
+(<em>Le tour du monde en quatre-vingts jours</em>), 1873.
 Wall-clock time plays a central role in the plot.
 European readers of the 1870s clearly held the U.S. press in
 deep contempt; the protagonists cross the U.S. without once
@@ -375,6 +375,18 @@ great-great-grandson of DST inventor Wil
 line is "Lights go out and I can't be saved".</td></tr>
 <tr><td>&nbsp;</td></tr>
 
+<tr><td>Artist</td><td>Jaime Guevara</td></tr>
+<tr><td>Song</td><td><a
+href="https://www.youtube.com/watch?v=ZfN4Fe_A50U";>Qu&eacute;
+hora es</a></td></tr>
+<tr><td>Date</td><td>1993</td></tr>
+<tr><td>Total Time</td><td>3:04</td></tr>
+<tr><td>Notes</td><td>The song protested "Sixto Hour" in Ecuador
+(1992&ndash;3). Its lyrics include "Amanec&iacute;a en mitad de la noche, los
+guaguas iban a clase sin sol" ("It was dawning in the middle of the
+night, the buses went to class without sun").
+<tr><td>&nbsp;</td></tr>
+
 <tr><td>Artist</td><td>Irving Kahal and Harry Richman</td></tr>
 <tr><td>Song</td><td>There Ought to be a Moonlight Saving Time</td></tr>
 <tr><td>Copyright Date</td><td>1931</td>
@@ -436,14 +448,21 @@ Supernaw.</td></tr>
 <ul>
 <li>
 The webcomic <em>xkcd</em> has the strip
-"<a href='http://xkcd.com/673/'>The Sun</a>" (2009-12-09) and the panels
-"<a href='http://xkcd.com/1017/'>Backward in Time</a>" (2012-02-14),
-"<a href='http://xkcd.com/1061/'>EST</a>" (2012-05-28),
-"<a href='http://xkcd.com/1179/'>ISO 8601</a>" (2013-02-27),
-"<a href='http://xkcd.com/1335/'>Now</a>" (2014-02-26), and
-"<a href='http://xkcd.com/1655/'>Doomsday Clock</a>" (2016-03-14).
+"<a href='https://xkcd.com/673/'>The Sun</a>" (2009-12-09) and the panels
+"<a href='https://xkcd.com/1017/'>Backward in Time</a>" (2012-02-14),
+"<a href='https://xkcd.com/1061/'>EST</a>" (2012-05-28),
+"<a href='https://xkcd.com/1179/'>ISO 8601</a>" (2013-02-27),
+"<a href='https://xkcd.com/1335/'>Now</a>" (2014-02-26),
+"<a href='https://xkcd.com/1655/'>Doomsday Clock</a>" (2016-03-14), and
+"<a href='https://xkcd.com/1799/'>Bad Map Projection: Time Zones</a>"
+(2017-02-15).
 The related book <em>What If?</em> has an entry
-"<a href='http://what-if.xkcd.com/26/'>Leap Seconds</a>" (2012-12-31).
+"<a href='https://what-if.xkcd.com/26/'>Leap Seconds</a>" (2012-12-31).
+</li>
+<li>
+Pig kills time in <a
+href="http://www.gocomics.com/pearlsbeforeswine/2016/11/06";><em>Pearls
+Before Swine</em> (2016-11-06)</a>.
 </li>
 <li>
 The syndicated comic strip <em>Dilbert</em> featured an
Index: src/lib/libc/time/zdump.8
diff -u src/lib/libc/time/zdump.8:1.15 src/lib/libc/time/zdump.8:1.16
--- src/lib/libc/time/zdump.8:1.15	Fri Oct  7 11:29:42 2016
+++ src/lib/libc/time/zdump.8	Sat Mar 11 13:23:14 2017
@@ -1,5 +1,5 @@
-.\"	$NetBSD: zdump.8,v 1.15 2016/10/07 15:29:42 christos Exp $
-.Dd October 6, 2016
+.\"	$NetBSD: zdump.8,v 1.16 2017/03/11 18:23:14 christos Exp $
+.Dd March 11, 2017
 .Dt ZDUMP 8
 .Os
 .Sh NAME
@@ -107,7 +107,7 @@ Fields are separated by single tabs.
 Dates are in
 .Dv yyyy-mm-dd
 format and times are in 24-hour
-.Dv hh:mm:ss
+.Dv hhmmss
 format where
 .Dv hh \*[Lt] 24 .
 Times are in local time immediately after the transition.
@@ -121,7 +121,8 @@ An isdst flag is omitted for standard ti
 is a decimal integer that is unsigned and positive (typically 1) for
 daylight saving time and negative for unknown.
 .Pp
-In times and UT offsets, the seconds are omitted if they are zero, and
+In times and in UT offsets with absolute value less than 100 hours,
+the seconds are omitted if they are zero, and
 the minutes are also omitted if they are also zero.
 Positive UT offsets are east of Greenwich.  The UT offset \&-00 denotes a UT
 placeholder in areas where the actual offset is unspecified; by

Index: src/lib/libc/time/tz-link.htm
diff -u src/lib/libc/time/tz-link.htm:1.29 src/lib/libc/time/tz-link.htm:1.30
--- src/lib/libc/time/tz-link.htm:1.29	Fri Nov  4 15:41:53 2016
+++ src/lib/libc/time/tz-link.htm	Sat Mar 11 13:23:14 2017
@@ -10,11 +10,11 @@
  content="Sources for time zone and daylight saving time data">
 <meta name="DC.Creator" content="Eggert, Paul">
 <meta name="DC.Contributor" content="Olson, Arthur David">
-<meta name="DC.Date" content="2016-11-01">
+<meta name="DC.Date" content="2017-02-23">
 <meta name="DC.Description"
  content="Sources of information about time zones and daylight saving time">
 <meta name="DC.Identifier"
- content="http://www.iana.org/time-zones/repository/tz-link.htm";>
+ content="https://www.iana.org/time-zones/repository/tz-link.htm";>
 <meta name="Keywords"
  content="database,daylight saving,DST,time zone,timezone,tz,zoneinfo">
 </head>
@@ -65,10 +65,9 @@ title="Advanced Interactive eXecutive">A
 <a href="https://en.wikipedia.org/wiki/BlackBerry_10";>BlackBerry 10</a>,
 <a href="http://www.apple.com/ios/";><abbr
 title="iPhone OS">iOS</abbr></a>,
-<a href="http://www.apple.com/macos/";><abbr
-title="Mac Operating System">macOS</abbr></a>,
+<a href="http://www.apple.com/macos/";>macOS</a>,
 <a href="https://www.microsoft.com/en-us/windows";>Microsoft Windows</a>,
-<a href="http://www.hp.com/go/openvms/";>Open<abbr
+<a href="https://www.hpe.com/info/openvms";>Open<abbr
 title="Virtual Memory System">VMS</abbr></a>,
 <a href="https://www.oracle.com/database/index.html";>Oracle Database</a>, and
 <a href="https://www.oracle.com/solaris";>Oracle Solaris</a>.</p>
@@ -113,20 +112,22 @@ the latest release's two
 to a <abbr>GNU</abbr>/Linux or similar host.</p>
 <pre style="margin-left: 2em"><code>mkdir tzdb
 cd tzdb
-<a href="https://www.gnu.org/software/wget/";>wget</a> --retr-symlinks 'ftp://ftp.iana.org/tz/tz*-latest.tar.gz'
+<a href="https://www.gnu.org/software/wget/";>wget</a> https://www.iana.org/time-zones/repository/tzcode-latest.tar.gz
+wget https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz
 <a href="https://www.gnu.org/software/gzip/";>gzip</a> -dc tzcode-latest.tar.gz | <a href="https://www.gnu.org/software/tar/";>tar</a> -xf -
 gzip -dc tzdata-latest.tar.gz | tar -xf -
 </code></pre>
 <p>Alternatively, the following shell commands download the same
 release in a single-tarball format containing extra data
 useful for regression testing:</p>
-<pre style="margin-left: 2em"><code>wget --retr-symlinks 'ftp://ftp.iana.org/tz/tzdb-latest.tar.lz'
+<pre style="margin-left: 2em"><code>wget <a href="https://www.iana.org/time-zones/repository/tzdb-latest.tar.lz";>https://www.iana.org/time-zones/repository/tzdb-latest.tar.lz</a>
 <a href="http://www.nongnu.org/lzip/";>lzip</a> -dc tzdb-latest.tar.lz | tar -xf -
 </code></pre>
-<p>These commands use convenience links to the latest of the
-<a href="ftp://ftp.iana.org/tz/releases/";><abbr
-title="File Transfer Protocol">FTP</abbr> releases</a>
-of the <code><abbr>tz</abbr></code> database.
+<p>These commands use convenience links to the latest release
+of the <code><abbr>tz</abbr></code> database hosted by the
+<a href="https://www.iana.org/time-zones";>Time Zone Database website</a>
+of the <a href="https://www.iana.org";>Internet Assigned Numbers
+Authority (IANA)</a>.
 Older releases are in files named
 <code>tzcode<var>V</var>.tar.gz</code>,
 <code>tzdata<var>V</var>.tar.gz</code>, and
@@ -136,17 +137,23 @@ Since 1996, each version has been a four
 lower-case letter (<samp>a</samp> through <samp>z</samp>,
 then <samp>za</samp> through <samp>zz</samp>, then <samp>zza</samp>
 through <samp>zzz</samp>, and so on).
-The releases can also be obtained from the
-<a href="http://www.iana.org/time-zones";>Time Zone Database website</a>
-of the <a href="http://www.iana.org";>Internet Assigned Numbers
-Authority (IANA)</a>.
-A <a href="https://github.com/eggert/tz";>development
-repository</a> of the code and data is available
-in <a href="https://git-scm.com";>Git</a> form
-from <a href="https://github.com";>GitHub</a>; be careful, as this
-repository is less well tested and probably contains more errors.
+Since version 2016h, each release has contained a text file named
+"<samp>version</samp>" whose first (and currently only) line is the version.
+The releases are also available in an
+<a href="ftp://ftp.iana.org/tz/releases/";><abbr
+title="File Transfer Protocol">FTP</abbr> directory</a> via a
+less-secure protocol .</p>
+<p>Alternatively, a development repository of code and data can be
+retrieved from <a href="https://github.com";>GitHub</a> via the shell
+command:</p>
+<pre style="margin-left: 2em"><code><a href="https://git-scm.com";>git</a> clone <a href="https://github.com/eggert/tz";>https://github.com/eggert/tz</a>
+</code></pre>
+<p>
+Since version 2012e, each release has been tagged in development repositories.
+Untagged commits are less well tested and probably contain
+more errors.</p>
 <p>
-After extracting a distribution's files, see its
+After obtaining the code and data files, see the
 <code>README</code> file for what to do next.
 The code lets you compile the <code><abbr>tz</abbr></code> source files into
 machine-readable binary files, one for each location. It also lets
@@ -160,7 +167,7 @@ send changes to the <a href="mailto:tz@i
 mailing list</a>. You can also <a
 href="https://mm.icann.org/mailman/listinfo/tz";>subscribe</a> to it
 and browse the <a
-href="http://mm.icann.org/pipermail/tz/";>archive of old
+href="https://mm.icann.org/pipermail/tz/";>archive of old
 messages</a>.</p>
 <p>
 If your government plans to change its time zone boundaries or
@@ -237,9 +244,6 @@ Worldwide</a> lets you sort zone names a
 calculates the current time difference between locations.</li>
 <li><a href="http://www.wx-now.com";>Weather Now</a> lists the weather too.</li>
 <li><a href="http://www.thetimenow.com";>The Time Now</a> also lists weather.</li>
-<li><a href="https://worldtime.io";>worldtime.io</a>
-also contains data about time zone boundaries; it supports queries via place
-names and shows location maps.</li>
 </ul>
 <h2 id="protocols">Network protocols for <code><abbr>tz</abbr></code> data</h2>
 <ul>
@@ -414,8 +418,9 @@ It is freely available under the <abbr>L
 implementation of a binary file reader. It is freely available under
 the Apache License.</li>
 <li><a href="https://github.com/google/cctz";>CCTZ</a> is a simple C++
-library that translates between UTC and civil time and can read binary
-files. It is freely available under the Apache License.</li>
+library that translates between <abbr>UTC</abbr> and civil time and
+can read binary files. It is freely available under the Apache
+License.</li>
 <li><a href="http://bmsi.com/java/#TZ";>ZoneInfo.java</a>
 is a <code><abbr>tz</abbr></code> binary file reader written in Java.
 It is freely available under the <abbr>LGPL</abbr>.</li>
@@ -495,7 +500,7 @@ download, compile and use <code>tz</code
 is free.</li>
 <li><a
 href="http://veladg.com/velaterra.html";>VelaTerra</a> is
-an <abbr>OS X</abbr> program. Its developers
+a macOS program. Its developers
 <a href="http://veladg.com/tzoffer.html";>offer free
 licenses</a> to <code><abbr>tz</abbr></code> contributors.</li>
 </ul>
@@ -503,14 +508,9 @@ licenses</a> to <code><abbr>tz</abbr></c
 <ul>
 <li><a href="http://www.astro.com/atlas";>Time-zone Atlas</a>
 is Astrodienst's Web version of Shanks and Pottenger's
-time zone history atlases published in both <a
-href="http://astrocom.com/astrology-products/software/acs-atlas-software";>computer</a>
-and book form (<a
-href="http://www.astrocom.com/astrology/books/american-atlas";>one volume
-for the <abbr>US</abbr></a>, and <a
-href="http://www.astrocom.com/astrology/books/international-atlas";>one for
-other locations</a>) by <a
-href="http://astrocom.com";>Astro Computing Services</a>.
+time zone history atlases also published in <a
+href="http://astrocom.com/astrology-products/software/acs-atlas-software";>software</a>
+form by <a href="http://astrocom.com";>ACS-Starcrafts</a>.
 These atlases are extensive but unreliable, as Shanks appears to have
 guessed many <abbr>UT</abbr> offsets and transitions. The atlases cite no
 sources and do not indicate which entries are guesswork.</li>
@@ -579,8 +579,11 @@ sets of <code><abbr>tz</abbr></code> reg
 for all the world's regions</li>
 <li><a
 href="https://github.com/straup/whereonearth-timezone";>Whereonearth-timezone</a>
-is in <a href="http://geojson.org";>GeoJSON</a> form, and combines the
-the tz_world shapefiles with the GeoPlanet dataset.</li>
+is in <a href="https://tools.ietf.org/html/rfc7946";>GeoJSON</a> format
+(Internet <abbr>RFC</abbr> 7946), and combines the
+the tz_world shapefiles with the
+<a href="https://developer.yahoo.com/geo/geoplanet/";>GeoPlanet</a>
+dataset.</li>
 </ul></li>
 <li>Programmatic interfaces that map geographical coordinates via tz_world to
 <code><abbr>tz</abbr></code> regions include:
@@ -595,14 +598,17 @@ is written in Go and is freely available
 in both Java and
 <a href="https://en.wikipedia.org/wiki/Swift_(programming_language)">Swift</a>
 form, is freely available under the MIT license.</li>
+<li>For <a href="https://nodejs.org/en/";>Node.js</a>,
+the <a href="https://www.npmjs.com/package/geo-tz";>geo-tz module</a>
+is freely available under the MIT license, and
+the <a href="https://www.npmjs.com/package/tz-lookup";>tz-lookup module</a>
+is in the public domain.</li>
 <li>The <a
 href="https://github.com/MrMinimal64/timezonefinder";>timezonefinder</a>
 library for Python is freely available under the MIT license.
 <li>The <a
 href="https://github.com/gunyarakun/timezone_finder";>timezone_finder</a>
 library for Ruby is freely available under the MIT license.</li>
-<li>The <a href="https://www.npmjs.com/package/tz-lookup";>tz-lookup module</a>
-for <a href="https://nodejs.org/en/";>Node.js</a> is in the public domain.</li>
 <li><a href="https://derickrethans.nl/what-time-is-it.html";>What Time
 is It Here?</a> applies <a href="https://www.mongodb.com";>MongoDB</a>
 geospatial query operators to shapefiles' data.</li>
@@ -615,7 +621,7 @@ Commercial network API access is provide
 by <a href="https://askgeo.com";>AskGeo</a>
 and <a href="https://www.geogarage.com/blog/news-1/post/geogarage-time-zone-api-31";>GeoGarage</a>.
 Also, an <a
-href="http://mm.icann.org/pipermail/tz/2016-October/024309.html";>experimental
+href="https://mm.icann.org/pipermail/tz/2016-October/024309.html";>experimental
 server</a> is available for the TZDIST Geolocate Extension mentioned
 <a href="#TZDIST-Geolocate">above</a>.</li>
 <li>"<a
@@ -773,7 +779,7 @@ Times</a> explains more abstruse astrono
 <abbr title="Barycentric Dynamic Time">TDB</abbr>.
 <a href="http://www.ucolick.org/~sla/leapsecs/timescales.html";>Time
 Scales</a> goes into more detail, particularly for historical variants.</li>
-<li>The <a href="http://www.iau.org";><abbr
+<li>The <a href="https://www.iau.org";><abbr
 title="International Astronomical Union">IAU</abbr></a>'s <a
 href="http://www.iausofa.org";><abbr
 title="Standards Of Fundamental Astronomy">SOFA</abbr></a>
@@ -783,11 +789,8 @@ code for converting among time scales li
 <abbr title="International Atomic Time">TAI</abbr>,
 <abbr>TDB</abbr>, <abbr>TDT</abbr> and
 <abbr>UTC</abbr>.</li>
-<li><a href="http://solarsystem.nasa.gov/basics/bsf2-3.php";>Basics of
-Space Flight &ndash; Reference Systems &ndash; Time Conventions</a>
-briefly explains interplanetary space flight timekeeping.</li>
 <li><a
-href="http://www.giss.nasa.gov/tools/mars24/help/notes.html";>Mars24 Sunclock
+href="https://www.giss.nasa.gov/tools/mars24/help/notes.html";>Mars24 Sunclock
 &ndash; Time on Mars</a> describes Airy Mean Time (<abbr>AMT</abbr>) and the
 diverse local time
 scales used by each landed mission on Mars.</li>
@@ -799,20 +802,32 @@ how the art has progressed over the past
 href="https://www.iers.org/IERS/EN/Publications/Bulletins/bulletins.html";><abbr
 title="International Earth Rotation and Reference Systems Service">IERS</abbr>
 Bulletins</a> contains official publications of the International
-Earth Rotation and Reference Systems Service, which decides
-when leap seconds occur.</li>
+Earth Rotation and Reference Systems Service, which decides when leap
+seconds occur. The <code>tz</code> code and data support leap seconds
+via an optional "<code>right</code>" configuration, as opposed to the
+default "<code>posix</code>" configuration.</li>
+<li><a href="https://developers.google.com/time/smear";>Leap Smear</a>
+discusses how to gradually adjust <abbr>POSIX</abbr> clocks near a
+leap second so that they disagree with <abbr>UTC</abbr> by at most a
+half second, even though every <abbr>POSIX</abbr> minute has exactly
+sixty seconds. This approach works with the default <code>tz</code>
+"<code>posix</code>" configuration, is <a
+href="http://bk1.ntp.org/ntp-stable/README.leapsmear";>supported</a> by
+the <abbr>NTP</abbr> reference implementation, and is used by major
+cloud service providers.</li>
 <li>The <a
 href="https://pairlist6.pair.net/mailman/listinfo/leapsecs";>Leap
 Second Discussion List</a> covers <a
 href="http://www2.unb.ca/gge/Resources/gpsworld.november99.pdf";>McCarthy
-and Klepczynski's proposal to discontinue leap seconds</a>,
+and Klepczynski's 1999 proposal to discontinue leap seconds</a>,
 discussed further in
 <a href="http://www.cl.cam.ac.uk/~mgk25/time/metrologia-leapsecond.pdf";>The
 leap second: its history and possible future</a>.
 <a href="http://www.ucolick.org/~sla/leapsecs/";><abbr>UTC</abbr>
 might be redefined
 without Leap Seconds</a> gives pointers on this
-contentious issue.</li>
+contentious issue, which was active until 2015 and could become active
+again.</li>
 </ul>
 <h2 id="notation">Time notation</h2>
 <ul>

Index: src/lib/libc/time/version
diff -u src/lib/libc/time/version:1.2 src/lib/libc/time/version:1.3
--- src/lib/libc/time/version:1.2	Fri Nov  4 15:41:53 2016
+++ src/lib/libc/time/version	Sat Mar 11 13:23:14 2017
@@ -1 +1 @@
-2016i
+2017a

Index: src/lib/libc/time/zdump.c
diff -u src/lib/libc/time/zdump.c:1.45 src/lib/libc/time/zdump.c:1.46
--- src/lib/libc/time/zdump.c:1.45	Thu Oct 20 13:41:34 2016
+++ src/lib/libc/time/zdump.c	Sat Mar 11 13:23:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: zdump.c,v 1.45 2016/10/20 17:41:34 christos Exp $	*/
+/*	$NetBSD: zdump.c,v 1.46 2017/03/11 18:23:14 christos Exp $	*/
 /*
 ** This file is in the public domain, so clarified as of
 ** 2009-05-17 by Arthur David Olson.
@@ -6,14 +6,13 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: zdump.c,v 1.45 2016/10/20 17:41:34 christos Exp $");
+__RCSID("$NetBSD: zdump.c,v 1.46 2017/03/11 18:23:14 christos Exp $");
 #endif /* !defined lint */
 
 /*
 ** This code has been made independent of the rest of the time
 ** conversion package to increase confidence in the verification it provides.
 ** You can use this code to help in verifying other implementations.
-**
 ** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
 */
 
@@ -24,90 +23,8 @@ __RCSID("$NetBSD: zdump.c,v 1.45 2016/10
 # define USE_LTZ 1
 #endif
 
-#if USE_LTZ
-#include "private.h"
-#endif
-
-/* Enable tm_gmtoff and tm_zone on GNUish systems.  */
-#define _GNU_SOURCE 1
-/* Enable strtoimax on Solaris 10.  */
-#define __EXTENSIONS__ 1
-
-#include "stdio.h"	/* for stdout, stderr */
-#include "string.h"	/* for strcpy */
-#include "sys/types.h"	/* for time_t */
-#include "time.h"	/* for struct tm */
-#include "stdlib.h"	/* for exit, malloc, atoi */
-#include "limits.h"	/* for CHAR_BIT, LLONG_MAX */
-#include <errno.h>
 #include <err.h>
-
-/*
-** Substitutes for pre-C99 compilers.
-** Much of this section of code is stolen from private.h.
-*/
-
-#ifndef HAVE_STDINT_H
-# define HAVE_STDINT_H \
-    (199901 <= __STDC_VERSION__ \
-     || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__)	\
-     || __CYGWIN__ || INTMAX_MAX)
-#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
-
-/* 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
-
-#ifndef INTMAX_MAX
-# ifdef LLONG_MAX
-typedef long long intmax_t;
-#  define strtoimax strtoll
-#  define INTMAX_MAX LLONG_MAX
-# else
-typedef long intmax_t;
-#  define strtoimax strtol
-#  define INTMAX_MAX LONG_MAX
-# endif
-#endif
-
-#ifndef PRIdMAX
-# if INTMAX_MAX == LLONG_MAX
-#  define PRIdMAX "lld"
-# else
-#  define PRIdMAX "ld"
-# endif
-#endif
-
-/* 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
+#include "private.h"
 
 #ifndef HAVE_LOCALTIME_R
 # define HAVE_LOCALTIME_R 1
@@ -137,82 +54,6 @@ typedef long intmax_t;
 #define MAX_STRING_LENGTH	1024
 #endif /* !defined MAX_STRING_LENGTH */
 
-#if __STDC_VERSION__ < 199901
-# define true 1
-# define false 0
-# define bool int
-#else
-# include <stdbool.h>
-#endif
-
-#ifndef TYPE_BIT
-#define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
-#endif /* !defined TYPE_BIT */
-
-#ifndef TYPE_SIGNED
-#define TYPE_SIGNED(type) (((type) -1) < 0)
-#endif /* !defined TYPE_SIGNED */
-
-#ifndef INT_STRLEN_MAXIMUM
-/*
-** 302 / 1000 is log10(2.0) rounded up.
-** Subtract one for the sign bit if the type is signed;
-** add one for integer division truncation;
-** add one more for a minus sign if the type is signed.
-*/
-#define INT_STRLEN_MAXIMUM(type) \
-	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
-	1 + TYPE_SIGNED(type))
-#endif /* !defined INT_STRLEN_MAXIMUM */
-
-#ifndef EXIT_SUCCESS
-#define EXIT_SUCCESS	0
-#endif /* !defined EXIT_SUCCESS */
-
-#ifndef EXIT_FAILURE
-#define EXIT_FAILURE	1
-#endif /* !defined EXIT_FAILURE */
-
-#ifndef SECSPERMIN
-#define SECSPERMIN	60
-#endif /* !defined SECSPERMIN */
-
-#ifndef MINSPERHOUR
-#define MINSPERHOUR	60
-#endif /* !defined MINSPERHOUR */
-
-#ifndef SECSPERHOUR
-#define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
-#endif /* !defined SECSPERHOUR */
-
-#ifndef HOURSPERDAY
-#define HOURSPERDAY	24
-#endif /* !defined HOURSPERDAY */
-
-#ifndef EPOCH_YEAR
-#define EPOCH_YEAR	1970
-#endif /* !defined EPOCH_YEAR */
-
-#ifndef TM_YEAR_BASE
-#define TM_YEAR_BASE	1900
-#endif /* !defined TM_YEAR_BASE */
-
-#ifndef DAYSPERNYEAR
-#define DAYSPERNYEAR	365
-#endif /* !defined DAYSPERNYEAR */
-
-#ifndef isleap
-#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
-#endif /* !defined isleap */
-
-#ifndef isleap_sum
-/*
-** See tzfile.h for details on isleap_sum.
-*/
-#define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
-#endif /* !defined isleap_sum */
-
-#define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
 #define SECSPERNYEAR	(SECSPERDAY * DAYSPERNYEAR)
 #define SECSPERLYEAR	(SECSPERNYEAR + SECSPERDAY)
 #define SECSPER400YEARS	(SECSPERNYEAR * (intmax_t) (300 + 3)	\
@@ -227,48 +68,10 @@ typedef long intmax_t;
 */
 enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 };
 
-#ifndef HAVE_GETTEXT
-#define HAVE_GETTEXT 0
-#endif
 #if HAVE_GETTEXT
-#include "locale.h"	/* for setlocale */
-#include "libintl.h"
+#include <locale.h>	/* for setlocale */
 #endif /* HAVE_GETTEXT */
 
-#ifndef ATTRIBUTE_PURE
-#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
-# define ATTRIBUTE_PURE __attribute__ ((ATTRIBUTE_PURE__))
-#else
-# define ATTRIBUTE_PURE /* empty */
-#endif
-#endif
-
-#ifndef INITIALIZE
-#if defined(__GNUC__) || defined(__lint__)
-#define INITIALIZE(x)	((x) = 0)
-#else /* !defined GNUC || lint */
-#define INITIALIZE(x)
-#endif /* !defined GNUC || lint */
-#endif /* !defined INITIALIZE */
-
-/*
-** For the benefit of GNU folk...
-** '_(MSGID)' uses the current locale's message library string for MSGID.
-** The default is to use gettext if available, and use MSGID otherwise.
-*/
-
-#ifndef _
-#if HAVE_GETTEXT
-#define _(msgid) gettext(msgid)
-#else /* !HAVE_GETTEXT */
-#define _(msgid) msgid
-#endif /* !HAVE_GETTEXT */
-#endif /* !defined _ */
-
-#if !defined TZ_DOMAIN && defined HAVE_GETTEXT
-# define TZ_DOMAIN "tz"
-#endif
-
 #if ! HAVE_LOCALTIME_RZ
 # undef  timezone_t
 # define timezone_t char **
@@ -926,7 +729,7 @@ adjusted_yday(struct tm const *a, struct
    the same instant, return A's UTC offset in seconds, where positive
    offsets are east of Greenwich.  On failure, return LONG_MIN.
 
-   If T is nonnull, *T is the time stamp that corresponds to A; call
+   If T is nonnull, *T is the timestamp that corresponds to A; call
    my_gmtime_r and use its result instead of B.  Otherwise, B is the
    possibly nonnull result of an earlier call to my_gmtime_r.  */
 static long
@@ -1007,9 +810,11 @@ format_local_time(char *buf, size_t size
 
 /* Store into BUF, of size SIZE, a formatted UTC offset for the
    localtime *TM corresponding to time T.  Use ISO 8601 format
-   +HH:MM:SS, or -HH:MM:SS for time stamps west of Greenwich.  Omit
-   :SS if :SS is zero, and omit :MM too if :MM is also zero.  If the
-   time stamp represents an unknown UTC offset, use the format -00.
+   +HHMMSS, or -HHMMSS for timestamps west of Greenwich; use the
+   format -00 for unknown UTC offsets.  If the hour needs more than
+   two digits to represent, extend the length of HH as needed.
+   Otherwise, omit SS if SS is zero, and omit MM too if MM is also
+   zero.
 
    Return the length of the resulting string, or -1 if the result is
    not representable as a string.  If the string does not fit, return
@@ -1034,10 +839,10 @@ format_utc_offset(char *buf, size_t size
   ss = off % 60;
   mm = off / 60 % 60;
   hh = off / 60 / 60;
-  return (ss
-	  ? snprintf(buf, size, "%c%02ld:%02d:%02d", sign, hh, mm, ss)
+  return (ss || 100 <= hh
+	  ? snprintf(buf, size, "%c%02ld%02d%02d", sign, hh, mm, ss)
 	  : mm
-	  ? snprintf(buf, size, "%c%02ld:%02d", sign, hh, mm)
+	  ? snprintf(buf, size, "%c%02ld%02d", sign, hh, mm)
 	  : snprintf(buf, size, "%c%02ld", sign, hh));
 }
 
@@ -1072,7 +877,7 @@ format_quoted_string(char *buf, size_t s
   }
 }
 
-/* Store into BUF (of size SIZE) a time stamp formatted by TIME_FMT.
+/* Store into BUF (of size SIZE) a timestamp formatted by TIME_FMT.
    TM is the broken-down time, T the seconds count, AB the time zone
    abbreviation, and ZONE_NAME the zone name.  Return true if
    successful, false if the output would require more than SIZE bytes.
@@ -1153,7 +958,7 @@ istrftime(char *buf, size_t size, char c
 	}
 	break;
       }
-      if (! (formatted_len < s))
+      if (s <= formatted_len)
 	return false;
       b += formatted_len, s -= formatted_len;
       f = p + 1;

Index: src/lib/libc/time/zic.c
diff -u src/lib/libc/time/zic.c:1.67 src/lib/libc/time/zic.c:1.68
--- src/lib/libc/time/zic.c:1.67	Sat Nov  5 19:09:37 2016
+++ src/lib/libc/time/zic.c	Sat Mar 11 13:23:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: zic.c,v 1.67 2016/11/05 23:09:37 kre Exp $	*/
+/*	$NetBSD: zic.c,v 1.68 2017/03/11 18:23:14 christos Exp $	*/
 /*
 ** This file is in the public domain, so clarified as of
 ** 2006-07-17 by Arthur David Olson.
@@ -10,13 +10,14 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: zic.c,v 1.67 2016/11/05 23:09:37 kre Exp $");
+__RCSID("$NetBSD: zic.c,v 1.68 2017/03/11 18:23:14 christos Exp $");
 #endif /* !defined lint */
 
 #include "private.h"
-#include "locale.h"
 #include "tzfile.h"
 
+#include <fcntl.h>
+#include <locale.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <unistd.h>
@@ -128,10 +129,14 @@ extern int	optind;
 # define link(from, to) (errno = ENOTSUP, -1)
 #endif
 #if ! HAVE_SYMLINK
-# define lstat(name, st) stat(name, st)
+# define readlink(file, buf, size) (errno = ENOTSUP, -1)
 # define symlink(from, to) (errno = ENOTSUP, -1)
 # define S_ISLNK(m) 0
 #endif
+#ifndef AT_SYMLINK_FOLLOW
+# define linkat(fromdir, from, todir, to, flag) \
+    (itssymlink(from) ? (errno = ENOTSUP, -1) : link(from, to))
+#endif
 
 static void	addtt(zic_t starttime, int type);
 static int	addtype(zic_t, char const *, bool, bool, bool);
@@ -149,7 +154,8 @@ static void	inrule(char ** fields, int n
 static bool	inzcont(char ** fields, int nfields);
 static bool	inzone(char ** fields, int nfields);
 static bool	inzsub(char **, int, int);
-static int	itsdir(const char * name);
+static bool	itsdir(const char *);
+static bool	itssymlink(const char *);
 static bool	is_alpha(char a);
 static char	lowerit(char);
 static void	mkdirs(char const *, bool);
@@ -810,9 +816,9 @@ relname(char const *from, char const *to
   for (i = 0; f[i] && f[i] == to[i]; i++)
     if (f[i] == '/')
       dir_len = i + 1;
-  for (; f[i]; i++)
-    dotdots += f[i] == '/' && f[i - 1] != '/';
-  taillen = i - dir_len;
+  for (; to[i]; i++)
+    dotdots += to[i] == '/' && to[i - 1] != '/';
+  taillen = strlen(f + dir_len);
   dotdotetcsize = 3 * dotdots + taillen + 1;
   if (dotdotetcsize <= linksize) {
     if (!result)
@@ -824,10 +830,18 @@ relname(char const *from, char const *to
   return result;
 }
 
+/* Hard link FROM to TO, following any symbolic links.
+   Return 0 if successful, an error number otherwise.  */
+static int
+hardlinkerr(char const *from, char const *to)
+{
+  int r = linkat(AT_FDCWD, from, AT_FDCWD, to, AT_SYMLINK_FOLLOW);
+  return r == 0 ? 0 : errno;
+}
+
 static void
 dolink(char const *fromfield, char const *tofield, bool staysymlink)
 {
-	int fromisdir;
 	bool todirs_made = false;
 	int link_errno;
 
@@ -835,15 +849,13 @@ dolink(char const *fromfield, char const
 	** We get to be careful here since
 	** there's a fair chance of root running us.
 	*/
-	fromisdir = itsdir(fromfield);
-	if (fromisdir) {
-		char const *e = strerror(fromisdir < 0 ? errno : EPERM);
+	if (itsdir(fromfield)) {
 		fprintf(stderr, _("%s: link from %s/%s failed: %s\n"),
-			progname, directory, fromfield, e);
+			progname, directory, fromfield, strerror(EPERM));
 		exit(EXIT_FAILURE);
 	}
 	if (staysymlink)
-	  staysymlink = itsdir(tofield) == 2;
+	  staysymlink = itssymlink(tofield);
 	if (remove(tofield) == 0)
 	  todirs_made = true;
 	else if (errno != ENOENT) {
@@ -852,12 +864,11 @@ dolink(char const *fromfield, char const
 	    progname, directory, tofield, e);
 	  exit(EXIT_FAILURE);
 	}
-	link_errno = (staysymlink ? ENOTSUP
-		      : link(fromfield, tofield) == 0 ? 0 : errno);
+	link_errno = staysymlink ? ENOTSUP : hardlinkerr(fromfield, tofield);
 	if (link_errno == ENOENT && !todirs_made) {
 	  mkdirs(tofield, true);
 	  todirs_made = true;
-	  link_errno = link(fromfield, tofield) == 0 ? 0 : errno;
+	  link_errno = hardlinkerr(fromfield, tofield);
 	}
 	if (link_errno != 0) {
 	  bool absolute = *fromfield == '/';
@@ -947,28 +958,35 @@ static const zic_t early_time = (WORK_AR
 				 ? BIG_BANG
 				 : MINVAL(zic_t, TIME_T_BITS_IN_FILE));
 
-/* Return 1 if NAME is a directory, 2 if a symbolic link, 0 if
-   something else, -1 (setting errno) if trouble.  */
-static int
-itsdir(char const *name)
+/* Return true if NAME is a directory.  */
+static bool
+itsdir(const char *name)
 {
 	struct stat st;
-	int res = lstat(name, &st);
-	if (res == 0) {
+	int res = stat(name, &st);
 #ifdef S_ISDIR
-		return S_ISDIR(st.st_mode) ? 1 : S_ISLNK(st.st_mode) ? 2 : 0;
-#else
+	if (res == 0)
+		return S_ISDIR(st.st_mode) != 0;
+#endif
+	if (res == 0 || errno == EOVERFLOW) {
 		size_t n = strlen(name);
 		char *nameslashdot = emalloc(n + 3);
 		bool dir;
 		memcpy(nameslashdot, name, n);
 		strcpy(&nameslashdot[n], &"/."[! (n && name[n - 1] != '/')]);
-		dir = lstat(nameslashdot, &st) == 0;
+		dir = stat(nameslashdot, &st) == 0 || errno == EOVERFLOW;
 		free(nameslashdot);
 		return dir;
-#endif
 	}
-	return -1;
+	return false;
+}
+
+/* Return true if NAME is a symbolic link.  */
+static bool
+itssymlink(char const *name)
+{
+  char c;
+  return 0 <= readlink(name, &c, 1);
 }
 
 /*
@@ -2367,6 +2385,9 @@ outzone(const struct zone *zpfirst, ptrd
 	bool			do_extend;
 	int			version;
 	ptrdiff_t lastatmax = -1;
+	zic_t one = 1;
+	zic_t y2038_boundary = one << 31;
+	zic_t max_year0;
 
 	max_abbr_len = 2 + max_format_len + max_abbrvar_len;
 	max_envvar_len = 2 * max_abbr_len + 5 * 9;
@@ -2462,12 +2483,13 @@ outzone(const struct zone *zpfirst, ptrd
 	}
 	/*
 	** For the benefit of older systems,
-	** generate data from 1900 through 2037.
+	** generate data from 1900 through 2038.
 	*/
 	if (min_year > 1900)
 		min_year = 1900;
-	if (max_year < 2037)
-		max_year = 2037;
+	max_year0 = max_year;
+	if (max_year < 2038)
+		max_year = 2038;
 	for (i = 0; i < zonecount; ++i) {
 		/*
 		** A guess that may well be corrected later.
@@ -2507,8 +2529,12 @@ outzone(const struct zone *zpfirst, ptrd
 				rp->r_todo = year >= rp->r_loyear &&
 						year <= rp->r_hiyear &&
 						yearistype(year, rp->r_yrtype);
-				if (rp->r_todo)
+				if (rp->r_todo) {
 					rp->r_temp = rpytime(rp, year);
+					rp->r_todo
+					  = (rp->r_temp < y2038_boundary
+					     || year <= max_year0);
+				}
 			}
 			for ( ; ; ) {
 				ptrdiff_t	k;
@@ -3121,7 +3147,8 @@ mp = _("time zone abbreviation differs f
 	
 /* Ensure that the directories of ARGNAME exist, by making any missing
    ones.  If ANCESTORS, do this only for ARGNAME's ancestors; otherwise,
-   do it for ARGNAME too.  Exit with failure if there is trouble.  */
+   do it for ARGNAME too.  Exit with failure if there is trouble.
+   Do not consider an existing non-directory to be trouble.  */
 static void
 mkdirs(char const *argname, bool ancestors)
 {
@@ -3149,8 +3176,11 @@ mkdirs(char const *argname, bool ancesto
 		** is checked anyway if the mkdir fails.
 		*/
 		if (mkdir(name, MKDIR_UMASK) != 0) {
+			/* For speed, skip itsdir if errno == EEXIST.  Since
+			   mkdirs is called only after open fails with ENOENT
+			   on a subfile, EEXIST implies itsdir here.  */
 			int err = errno;
-			if (err != EEXIST && itsdir(name) < 0) {
+			if (err != EEXIST && !itsdir(name)) {
 				error(_("%s: Can't create directory %s: %s"),
 				      progname, name, strerror(err));
 				exit(EXIT_FAILURE);

Reply via email to