svn commit: r272562 - head/lib/libc/stdtime
Ian Lepore
ian at FreeBSD.org
Mon Oct 6 22:45:28 UTC 2014
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
More information about the svn-src-all
mailing list