Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/time Don't try to print NULL if we can't get a time...
details: https://anonhg.NetBSD.org/src/rev/513d9b493df3
branches: trunk
changeset: 998107:513d9b493df3
user: christos <christos%NetBSD.org@localhost>
date: Sun Apr 07 14:51:14 2019 +0000
description:
Don't try to print NULL if we can't get a timezone name. First we try dst,
then we try the non-dst name and finally we just print ??? if that did not
work. This is not needed to handle the "TZ= date" case which was crashing
before because the default timezone was not consistently initialized, but
should handle any timezone now.
diffstat:
lib/libc/time/strftime.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diffs (37 lines):
diff -r 7ca42a0bf076 -r 513d9b493df3 lib/libc/time/strftime.c
--- a/lib/libc/time/strftime.c Sun Apr 07 14:50:41 2019 +0000
+++ b/lib/libc/time/strftime.c Sun Apr 07 14:51:14 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strftime.c,v 1.44 2019/04/05 21:27:44 christos Exp $ */
+/* $NetBSD: strftime.c,v 1.45 2019/04/07 14:51:14 christos Exp $ */
/* Convert a broken-down timestamp to a string. */
@@ -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.44 2019/04/05 21:27:44 christos Exp $");
+__RCSID("$NetBSD: strftime.c,v 1.45 2019/04/07 14:51:14 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -544,9 +544,15 @@
#ifdef TM_ZONE
pt = _add(t->TM_ZONE, pt, ptlim);
#elif HAVE_TZNAME
- if (t->tm_isdst >= 0)
- pt = _add(tzgetname(sp, t->tm_isdst),
- pt, ptlim);
+ if (t->tm_isdst >= 0) {
+ int oerrno = errno, dst = t->tm_isdst;
+ const char *z =
+ tzgetname(sp, dst);
+ if (z == NULL)
+ z = tzgetname(sp, !dst);
+ pt = _add(z ? z : "???", pt, ptlim);
+ errno = oerrno;
+ }
#endif
/*
** C99 and later say that %Z must be
Home |
Main Index |
Thread Index |
Old Index