Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/time merge 2014i



details:   https://anonhg.NetBSD.org/src/rev/532d75ac026c
branches:  trunk
changeset: 333215:532d75ac026c
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Oct 23 18:45:58 2014 +0000

description:
merge 2014i

diffstat:

 lib/libc/time/Makefile    |    3 +-
 lib/libc/time/NEWS        |   66 ++++++++
 lib/libc/time/asctime.c   |    8 +-
 lib/libc/time/localtime.c |  339 ++++++++++++++++++++++++---------------------
 lib/libc/time/private.h   |   12 +-
 lib/libc/time/tz-art.htm  |   10 +-
 lib/libc/time/tz-link.htm |   12 +-
 lib/libc/time/tzset.3     |    9 +-
 lib/libc/time/zdump.8     |    6 +-
 lib/libc/time/zdump.c     |    7 +-
 10 files changed, 288 insertions(+), 184 deletions(-)

diffs (truncated from 972 to 300 lines):

diff -r 8cc260e4b254 -r 532d75ac026c lib/libc/time/Makefile
--- a/lib/libc/time/Makefile    Thu Oct 23 17:51:22 2014 +0000
+++ b/lib/libc/time/Makefile    Thu Oct 23 18:45:58 2014 +0000
@@ -5,7 +5,7 @@
 PACKAGE=       tzcode
 
 # Version numbers of the code and data distributions.
-VERSION=       2014h
+VERSION=       2014i
 
 # Email address for bug reports.
 BUGEMAIL=      tz%iana.org@localhost
@@ -129,6 +129,7 @@
 #  -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
 #      if you do not want run time warnings about formats that may cause
 #      year 2000 grief
+#  -Dssize_t=long on ancient hosts that lack ssize_t
 #  -DTHREAD_SAFE=1 to make localtime.c thread-safe, as POSIX requires;
 #      not needed by the main-program tz code, which is single-threaded.
 #      Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
diff -r 8cc260e4b254 -r 532d75ac026c lib/libc/time/NEWS
--- a/lib/libc/time/NEWS        Thu Oct 23 17:51:22 2014 +0000
+++ b/lib/libc/time/NEWS        Thu Oct 23 18:45:58 2014 +0000
@@ -1,5 +1,71 @@
 News for the tz database
 
+Release 2014i - 2014-10-21 22:04:57 -0700
+
+  Changes affecting future time stamps
+
+    Pacific/Fiji will observe DST from 2014-11-02 02:00 to 2015-01-18 03:00.
+    (Thanks to Ken Rylander for the heads-up.)  Guess that future
+    years will use a similar pattern.
+
+    A new Zone Pacific/Bougainville, for the part of Papua New Guinea
+    that plans to switch from UTC+10 to UTC+11 on 2014-12-28 at 02:00.
+    (Thanks to Kiley Walbom for the heads-up.)
+
+  Changes affecting time zone abbreviations
+
+    Since Belarus is not changing its clocks even though Moscow is,
+    the time zone abbreviation in Europe/Minsk is changing from FET
+    to its more-traditional value MSK on 2014-10-26 at 01:00.
+    (Thanks to Alexander Bokovoy for the heads-up about Belarus.)
+
+    The new abbreviation IDT stands for the pre-1976 use of UT+8 in
+    Indochina, to distinguish it better from ICT (UT+7).
+
+  Changes affecting past time stamps
+
+    Many time stamps have been corrected for Asia/Ho_Chi_Minh before 1976
+    (thanks to Trần Ng�c Quân for an indirect pointer to Trần Tiến Bình's
+    authoritative book).  Asia/Ho_Chi_Minh has been added to
+    zone1970.tab, to give tzselect users in Vietnam two choices,
+    since north and south Vietnam disagreed after our 1970 cutoff.
+
+    Asia/Phnom_Penh and Asia/Vientiane have been turned into links, as
+    they differed from existing zones only for older time stamps.  As
+    usual, these changes affect pre-1970 time stamps only.  Their old
+    contents have been moved to the 'backzone' file.
+
+  Changes affecting code
+
+    The time-related library functions now set errno on failure, and
+    some crashes in the new tzalloc-related library functions have
+    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,
+    the tz library's localtime and mktime functions now set the extern
+    variable timezone to a value appropriate for that time stamp; 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
+    than having undefined behavior.
+
+    Some bugs associated with the new 2014g functions have been fixed.
+    This includes a bug that largely incapacitated the new functions
+    time2posix_z and posix2time_z.  (Thanks to Christos Zoulas.)
+    It also includes some uses of uninitialized variables after tzalloc.
+    The new code uses the standard type 'ssize_t', which the Makefile
+    now gives porting advice about.
+
+  Changes affecting commentary
+
+    Updated URLs for NRC Canada (thanks to Matt Johnson and Brian Inglis).
+
+
 Release 2014h - 2014-09-25 18:59:03 -0700
 
   Changes affecting past time stamps
diff -r 8cc260e4b254 -r 532d75ac026c lib/libc/time/asctime.c
--- a/lib/libc/time/asctime.c   Thu Oct 23 17:51:22 2014 +0000
+++ b/lib/libc/time/asctime.c   Thu Oct 23 18:45:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asctime.c,v 1.19 2014/08/15 11:04:07 christos Exp $    */
+/*     $NetBSD: asctime.c,v 1.20 2014/10/23 18:45:58 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.19 2014/08/15 11:04:07 christos Exp $");
+__RCSID("$NetBSD: asctime.c,v 1.20 2014/10/23 18:45:58 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -126,11 +126,7 @@
        if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime)
                return strcpy(buf, result);
        else {
-#ifdef EOVERFLOW
                errno = EOVERFLOW;
-#else /* !defined EOVERFLOW */
-               errno = EINVAL;
-#endif /* !defined EOVERFLOW */
                return NULL;
        }
 }
diff -r 8cc260e4b254 -r 532d75ac026c lib/libc/time/localtime.c
--- a/lib/libc/time/localtime.c Thu Oct 23 17:51:22 2014 +0000
+++ b/lib/libc/time/localtime.c Thu Oct 23 18:45:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: localtime.c,v 1.90 2014/10/16 17:53:32 christos Exp $  */
+/*     $NetBSD: localtime.c,v 1.91 2014/10/23 18:45:58 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.90 2014/10/16 17:53:32 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.91 2014/10/23 18:45:58 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -216,6 +216,17 @@
 long                   altzone = 0;
 #endif /* defined ALTZONE */
 
+/* Initialize *S to a value based on GMTOFF, ISDST, and ABBRIND.  */
+static void
+init_ttinfo(struct ttinfo *s, int_fast32_t gmtoff, bool isdst, int abbrind)
+{
+       s->tt_gmtoff = gmtoff;
+       s->tt_isdst = isdst;
+       s->tt_abbrind = abbrind;
+       s->tt_ttisstd = false;
+       s->tt_ttisgmt = false;
+}
+
 static int_fast32_t
 detzcode(const char *const codep)
 {
@@ -327,61 +338,63 @@
        return (int_fast64_t)t1 - (int_fast64_t)t0 == SECSPERREPEAT;
 }
 
-static bool
-tzload(const char *name, timezone_t sp, bool doextend)
+union input_buffer {
+       /* The first part of the buffer, interpreted as a header.  */
+       struct tzhead tzhead;
+
+       /* The entire buffer.  */
+       char buf[2 * sizeof(struct tzhead) + 2 * sizeof (struct state)
+         + 4 * TZ_MAX_TIMES];
+};
+
+/* Local storage needed for 'tzloadbody'.  */
+union local_storage {
+       /* The file name to be opened.  */
+       char fullname[FILENAME_MAX + 1];
+
+       /* The results of analyzing the file's contents after it is opened.  */
+       struct {
+               /* The input buffer.  */
+               union input_buffer u;
+
+               /* A temporary state used for parsing a TZ string in the file.  */
+               struct state st;
+       } u;
+};
+
+/* Load tz data from the file named NAME into *SP.  Read extended
+   format if DOEXTEND.  Use *LSP for temporary storage.  Return 0 on
+   success, an errno value on failure.  */
+static int
+tzloadbody(char const *name, struct state *sp, bool doextend,
+  union local_storage *lsp)
 {
-       const char *            p;
        int                     i;
        int                     fid;
        int                     stored;
        ssize_t                 nread;
-       typedef union {
-               struct tzhead   tzhead;
-               char            buf[2 * sizeof(struct tzhead) +
-                                       2 * sizeof *sp +
-                                       4 * TZ_MAX_TIMES];
-       } u_t;
-       union local_storage {
-               /*
-               ** Section 4.9.1 of the C standard says that
-               ** "FILENAME_MAX expands to an integral constant expression
-               ** that is the size needed for an array of char large enough
-               ** to hold the longest file name string that the implementation
-               ** guarantees can be opened."
-               */
-               char            fullname[FILENAME_MAX + 1];
-
-               /* The main part of the storage for this function.  */
-               struct {
-                       u_t u;
-                       struct state st;
-               } u;
-       };
-       char *fullname;
-       u_t *up;
-       bool doaccess;
-       union local_storage *lsp;
-       lsp = malloc(sizeof *lsp);
-       if (!lsp)
-               return false;
-       fullname = lsp->fullname;
-       up = &lsp->u.u;
+       bool                    doaccess;
+       char                    *fullname = lsp->fullname;
+       union input_buffer      *up = &lsp->u.u;
+       size_t                  tzheadsize = sizeof(struct tzhead);
 
        sp->goback = sp->goahead = false;
 
        if (! name) {
                name = TZDEFAULT;
                if (! name)
-                       goto oops;
+                       return EINVAL;
        }
 
        if (name[0] == ':')
                ++name;
        doaccess = name[0] == '/';
        if (!doaccess) {
-               p = TZDIR;
-               if (! p || sizeof lsp->fullname - 1 <= strlen(p) + strlen(name))
-                       goto oops;
+               char const *p = TZDIR;
+               if (! p)
+                       return EINVAL;
+               if (sizeof lsp->fullname - 1 <= strlen(p) + strlen(name))
+                       return ENAMETOOLONG;
                strcpy(fullname, p);
                strcat(fullname, "/");
                strcat(fullname, name);
@@ -391,14 +404,19 @@
                name = fullname;
        }
        if (doaccess && access(name, R_OK) != 0)
-               goto oops;
+               return errno;
 
        fid = open(name, OPEN_MODE);
        if (fid < 0)
-               goto oops;
+               return errno;
        nread = read(fid, up->buf, sizeof up->buf);
-       if (close(fid) < 0 || nread <= 0)
-               goto oops;
+       if (nread < (ssize_t)tzheadsize) {
+               int err = nread < 0 ? errno : EINVAL;
+               close(fid);
+               return err;
+       }
+       if (close(fid) < 0)
+               return errno;
        for (stored = 4; stored <= 8; stored *= 2) {
                int_fast32_t ttisstdcnt = detzcode(up->tzhead.tzh_ttisstdcnt);
                int_fast32_t ttisgmtcnt = detzcode(up->tzhead.tzh_ttisgmtcnt);
@@ -406,23 +424,24 @@
                int_fast32_t timecnt = detzcode(up->tzhead.tzh_timecnt);
                int_fast32_t typecnt = detzcode(up->tzhead.tzh_typecnt);
                int_fast32_t charcnt = detzcode(up->tzhead.tzh_charcnt);
-               p = up->tzhead.tzh_charcnt + sizeof up->tzhead.tzh_charcnt;
+               char const *p = up->buf + tzheadsize;
                if (! (0 <= leapcnt && leapcnt < TZ_MAX_LEAPS
                       && 0 < typecnt && typecnt < TZ_MAX_TYPES
                       && 0 <= timecnt && timecnt < TZ_MAX_TIMES
                       && 0 <= charcnt && charcnt < TZ_MAX_CHARS
                       && (ttisstdcnt == typecnt || ttisstdcnt == 0)
                       && (ttisgmtcnt == typecnt || ttisgmtcnt == 0)))
-                               goto oops;



Home | Main Index | Thread Index | Old Index