From owner-svn-src-all@FreeBSD.ORG Mon Oct 6 22:45:28 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 838B5A42; Mon, 6 Oct 2014 22:45:28 +0000 (UTC) Received: from mho-01-ewr.mailhop.org (mho-03-ewr.mailhop.org [204.13.248.66]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 581B8760; Mon, 6 Oct 2014 22:45:27 +0000 (UTC) Received: from [73.34.117.227] (helo=ilsoft.org) by mho-01-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1XbH1y-000FiX-4D; Mon, 06 Oct 2014 22:45:26 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id s96MjPUY029064; Mon, 6 Oct 2014 16:45:25 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1/2JcPcuP2S7XaUtUy40pBW X-Authentication-Warning: paranoia.hippie.lan: Host revolution.hippie.lan [172.22.42.240] claimed to be [172.22.42.240] Subject: Re: svn commit: r272562 - head/lib/libc/stdtime From: Ian Lepore To: "Andrey A. Chernov" In-Reply-To: <201410050729.s957TpY9020060@svn.freebsd.org> References: <201410050729.s957TpY9020060@svn.freebsd.org> Content-Type: text/plain; charset="us-ascii" Date: Mon, 06 Oct 2014 16:45:24 -0600 Message-ID: <1412635524.12052.188.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Oct 2014 22:45:28 -0000 On Sun, 2014-10-05 at 07:29 +0000, Andrey A. Chernov wrote: > Author: ache > Date: Sun Oct 5 07:29:50 2014 > New Revision: 272562 > URL: https://svnweb.freebsd.org/changeset/base/272562 > > Log: > 1) For %Z format, understand "UTC" name too. > 2) Return NULL if timegm() fails, because it means we can convert > what we have in GMT to local time needed. > > Modified: > head/lib/libc/stdtime/strptime.c > > Modified: head/lib/libc/stdtime/strptime.c > ============================================================================== > --- head/lib/libc/stdtime/strptime.c Sun Oct 5 07:27:05 2014 (r272561) > +++ head/lib/libc/stdtime/strptime.c Sun Oct 5 07:29:50 2014 (r272562) > @@ -552,7 +552,8 @@ label: > strncpy(zonestr, buf, cp - buf); > zonestr[cp - buf] = '\0'; > tzset(); > - if (0 == strcmp(zonestr, "GMT")) { > + if (0 == strcmp(zonestr, "GMT") || > + 0 == strcmp(zonestr, "UTC")) { > *GMTp = 1; > } else if (0 == strcmp(zonestr, tzname[0])) { > tm->tm_isdst = 0; > @@ -674,6 +675,9 @@ strptime_l(const char * __restrict buf, > ret = _strptime(buf, fmt, tm, &gmt, loc); > if (ret && gmt) { > time_t t = timegm(tm); > + > + if (t == -1) > + return (NULL); > localtime_r(&t, tm); > } > > Using -1 as an error indicator in time conversions has drawbacks (your change doesn't make it any better or worse, I'm just whining in general)... revolution > date -ujf "%Y-%m-%dT%H:%M:%S" +%s 1970-01-01T0:0:0 0 revolution > date -ujf "%Y-%m-%dT%H:%M:%S" +%s 1969-12-31T23:59:58 -2 revolution > date -ujf "%Y-%m-%dT%H:%M:%S" +%s 1969-12-31T23:59:59 date: nonexistent time If timegm() and mktime() were to set errno in addition to returning -1, strptime() (and others) could use that to see the difference between errors and the second immediately before the epoch. I'm not sure of the standards-related implications of those routines setting errno though. -- Ian