Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/time Add code (not enabled) that allows mktime() to...
details: https://anonhg.NetBSD.org/src/rev/193d2fbbe81e
branches: trunk
changeset: 770431:193d2fbbe81e
user: christos <christos%NetBSD.org@localhost>
date: Sun Oct 16 17:59:32 2011 +0000
description:
Add code (not enabled) that allows mktime() to return a value for times
in the DST gap when tm_isdst == -1, like glibc does. Document both behaviors.
diffstat:
lib/libc/time/Makefile | 2 ++
lib/libc/time/ctime.3 | 17 +++++++++++++++--
lib/libc/time/localtime.c | 25 +++++++++++++++++++++++--
3 files changed, 40 insertions(+), 4 deletions(-)
diffs (92 lines):
diff -r 05104b7f61fd -r 193d2fbbe81e lib/libc/time/Makefile
--- a/lib/libc/time/Makefile Sun Oct 16 17:24:50 2011 +0000
+++ b/lib/libc/time/Makefile Sun Oct 16 17:59:32 2011 +0000
@@ -113,6 +113,8 @@
# -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
+# -DNO_ERROR_IN_DST_GAP=1
+# if you want mktime() not to return an error in the DST gap.
# -DZIC_MAX_ABBR_LEN_WO_WARN=3
# (or some other number) to set the maximum time zone abbreviation length
# that zic will accept without a warning (the default is 6)
diff -r 05104b7f61fd -r 193d2fbbe81e lib/libc/time/ctime.3
--- a/lib/libc/time/ctime.3 Sun Oct 16 17:24:50 2011 +0000
+++ b/lib/libc/time/ctime.3 Sun Oct 16 17:59:32 2011 +0000
@@ -1,8 +1,8 @@
-.\" $NetBSD: ctime.3,v 1.42 2011/07/09 09:12:11 plunky Exp $
+.\" $NetBSD: ctime.3,v 1.43 2011/10/16 17:59:32 christos Exp $
.\"
.\" XXX: Lincense missing?
.\"
-.Dd July 9, 2011
+.Dd October 16, 2011
.Dt CTIME 3
.Os
.Sh NAME
@@ -245,6 +245,19 @@
The function returns the specified calendar time;
if the calendar time cannot be represented, it returns
.Va "(time_t)-1" .
+This can happen either because the resulting conversion would not fit
+in a
+.Vt time_t
+variable, or because the time specified happens to be in the daylight
+savings gap and
+.Fa tm_isdst
+was set to
+.Dv \-1 .
+Other
+.Fn mktime
+implementations do not return an error in the second case and return
+the appropriate time offset after the daylight savings gap.
+There is code to mimick this behavior, but it is not enabled by default.
.It Fn mktime_z "tz" "tm"
The
.Fn mktime_z
diff -r 05104b7f61fd -r 193d2fbbe81e lib/libc/time/localtime.c
--- a/lib/libc/time/localtime.c Sun Oct 16 17:24:50 2011 +0000
+++ b/lib/libc/time/localtime.c Sun Oct 16 17:59:32 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: localtime.c,v 1.58 2011/09/04 10:10:26 christos Exp $ */
+/* $NetBSD: localtime.c,v 1.59 2011/10/16 17:59:32 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.58 2011/09/04 10:10:26 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.59 2011/10/16 17:59:32 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -1912,6 +1912,27 @@
return WRONG;
--hi;
}
+#ifdef NO_ERROR_IN_DST_GAP
+ if (lo - 1 == hi && yourtm.tm_isdst < 0) {
+ time_t off = 0;
+ for (i = sp->typecnt - 1; i >= 0; --i) {
+ for (j = sp->typecnt - 1; j >= 0; --j) {
+ if (sp->ttis[j].tt_isdst ==
+ sp->ttis[i].tt_isdst)
+ continue;
+ off = sp->ttis[j].tt_gmtoff -
+ sp->ttis[i].tt_gmtoff;
+ break;
+ }
+ if (j >= 0)
+ break;
+ }
+ if (off) {
+ t = hi + off;
+ break;
+ }
+ }
+#endif
if (lo > hi)
return WRONG;
if (dir > 0)
Home |
Main Index |
Thread Index |
Old Index