summaryrefslogtreecommitdiff
path: root/lib/mktime.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-04-30 14:52:10 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-04-30 14:53:17 -0700
commitb6aa3446df5e715fd74f010afad75c3c8589a9a1 (patch)
tree3b5377b3651ef95a0a77becaa7ee7ccba7b37168 /lib/mktime.c
parent3ad9d5c347739bb6c5450ed443ffa1608a94394c (diff)
downloademacs-b6aa3446df5e715fd74f010afad75c3c8589a9a1.tar.gz
Merge from gnulib
This incorporates: 2017-04-30 strftime-fixes: New module 2017-04-30 mktime: Work around TZ problem on native Windows 2017-04-30 ctime, localtime: New modules 2017-04-30 gettimeofday: Provide higher resolution on native Windows 2017-04-29 utime-h: Modernize handling of 'struct utimbuf' 2017-04-29 Make use of module 'utime-h' 2017-04-30 Fix a few typos * admin/merge-gnulib (AVOIDED_MODULES): Avoid utime-h, too. * lib/gettimeofday.c, lib/mktime.c, lib/time.in.h, lib/utimens.c: * m4/gettimeofday.m4, m4/include_next.m4, m4/mktime.m4: * m4/strftime.m4, m4/time_h.m4, m4/timegm.m4, m4/utimens.m4: Copy from gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib/mktime.c')
-rw-r--r--lib/mktime.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/lib/mktime.c b/lib/mktime.c
index 998882f5860..06d5916e910 100644
--- a/lib/mktime.c
+++ b/lib/mktime.c
@@ -23,6 +23,19 @@
# define DEBUG_MKTIME 0
#endif
+/* The following macros influence what gets defined when this file is compiled:
+
+ Macro/expression Which gnulib module This compilation unit
+ should define
+
+ NEED_MKTIME_WORKING mktime rpl_mktime
+ || NEED_MKTIME_WINDOWS
+
+ NEED_MKTIME_INTERNAL mktime-internal mktime_internal
+
+ DEBUG_MKTIME (defined manually) my_mktime, main
+ */
+
#if !defined _LIBC && !DEBUG_MKTIME
# include <config.h>
#endif
@@ -51,6 +64,13 @@
# define mktime my_mktime
#endif
+#if NEED_MKTIME_WINDOWS /* on native Windows */
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+#if NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL || DEBUG_MKTIME
+
/* A signed type that can represent an integer number of years
multiplied by three times the number of seconds in a year. It is
needed when converting a tm_year value times the number of seconds
@@ -458,25 +478,46 @@ __mktime_internal (struct tm *tp,
return t;
}
+#endif /* NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL || DEBUG_MKTIME */
+
+#if NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS || DEBUG_MKTIME
+# if NEED_MKTIME_WORKING || DEBUG_MKTIME
static mktime_offset_t localtime_offset;
+# endif
/* Convert *TP to a time_t value. */
time_t
mktime (struct tm *tp)
{
-#ifdef _LIBC
+# if NEED_MKTIME_WINDOWS
+ /* If the environment variable TZ has been set by Cygwin, neutralize it.
+ The Microsoft CRT interprets TZ differently than Cygwin and produces
+ incorrect results if TZ has the syntax used by Cygwin. */
+ const char *tz = getenv ("TZ");
+ if (tz != NULL && strchr (tz, '/') != NULL)
+ _putenv ("TZ=");
+# endif
+
+# if NEED_MKTIME_WORKING || DEBUG_MKTIME
+# ifdef _LIBC
/* POSIX.1 8.1.1 requires that whenever mktime() is called, the
time zone names contained in the external variable 'tzname' shall
be set as if the tzset() function had been called. */
__tzset ();
-#elif HAVE_TZSET
+# elif HAVE_TZSET
tzset ();
-#endif
+# endif
return __mktime_internal (tp, __localtime_r, &localtime_offset);
+# else
+# undef mktime
+ return mktime (tp);
+# endif
}
+#endif /* NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS || DEBUG_MKTIME */
+
#ifdef weak_alias
weak_alias (mktime, timelocal)
#endif