localtime: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 30 Apr 2017 11:32:40 +0000 (13:32 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 30 Apr 2017 17:26:37 +0000 (19:26 +0200)
* lib/time.in.h (localtime): Declare also if requested by module
'localtime'.
* lib/localtime.c: New file.
* m4/localtime.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_LOCALTIME.
* modules/time (Makefile.am): Substitute GNULIB_LOCALTIME.
* modules/localtime: New file.
* doc/posix-functions/localtime.texi: Mention the new module.

ChangeLog
doc/posix-functions/localtime.texi
lib/localtime.c [new file with mode: 0644]
lib/time.in.h
m4/localtime.m4 [new file with mode: 0644]
m4/time_h.m4
modules/localtime [new file with mode: 0644]
modules/time

index 17c3bf6e84a43779a4bb1c6c470ea23ff74405fe..af7f731c4ee269af2b2e0169ae3214d928f85e34 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-04-30  Bruno Haible  <bruno@clisp.org>
+
+       localtime: New module.
+       * lib/time.in.h (localtime): Declare also if requested by module
+       'localtime'.
+       * lib/localtime.c: New file.
+       * m4/localtime.m4: New file.
+       * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_LOCALTIME.
+       * modules/time (Makefile.am): Substitute GNULIB_LOCALTIME.
+       * modules/localtime: New file.
+       * doc/posix-functions/localtime.texi: Mention the new module.
+
 2017-04-30  Bruno Haible  <bruno@clisp.org>
 
        ctime: New module.
index 1d6acdba8f4292bbb700b9df91e7aa0535977d1e..74d4a6a48ec48ec36cf35d1f05d037f1c8051c38 100644 (file)
@@ -4,18 +4,18 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/localtime.html}
 
-Gnulib module: ---
+Gnulib module: localtime
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+On native Windows platforms (mingw, MSVC), this function works incorrectly
+when the environment variable @code{TZ} has been set by Cygwin.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-On native Windows platforms (mingw, MSVC), this function works incorrectly
-when the environment variable @code{TZ} has been set by Cygwin.
-@item
 On some platforms, this function returns nonsense values for
 unsupported arguments (like @math{2^56}), rather than failing:
 FreeBSD 10.
diff --git a/lib/localtime.c b/lib/localtime.c
new file mode 100644 (file)
index 0000000..07b532a
--- /dev/null
@@ -0,0 +1,45 @@
+/* Work around platform bugs in localtime.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <time.h>
+
+/* Keep consistent with gettimeofday.c!  */
+#if !(GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME)
+
+# include <stdlib.h>
+# include <string.h>
+
+# undef localtime
+
+struct tm *
+rpl_localtime (const time_t *tp)
+{
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* 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
+
+  return localtime (tp);
+}
+
+#endif
index 47087d8da67d08dd4f5dac3581cab931b1f417b2..2587cdd1eafdbd8a12a999db76ff77206498eb14 100644 (file)
@@ -187,7 +187,7 @@ _GL_CXXALIASWARN (gmtime_r);
 /* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
    <http://www.opengroup.org/susv3xsh/localtime.html> and
    <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
-# if @GNULIB_GETTIMEOFDAY@
+# if @GNULIB_LOCALTIME@ || @GNULIB_GETTIMEOFDAY@
 #  if @REPLACE_LOCALTIME@
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #    undef localtime
diff --git a/m4/localtime.m4 b/m4/localtime.m4
new file mode 100644 (file)
index 0000000..deb54a3
--- /dev/null
@@ -0,0 +1,14 @@
+# localtime.m4 serial 1
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_LOCALTIME],
+[
+  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  case "$host_os" in
+    mingw*) REPLACE_LOCALTIME=1 ;;
+  esac
+])
index fdd819bc59a26141aa9f5cc3e3c4d9bcd83ea67b..2eaf3aeb3a8aa3dc00037e7b3938d8f0b5c79e0a 100644 (file)
@@ -106,6 +106,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
 [
   GNULIB_CTIME=0;                        AC_SUBST([GNULIB_CTIME])
   GNULIB_MKTIME=0;                       AC_SUBST([GNULIB_MKTIME])
+  GNULIB_LOCALTIME=0;                    AC_SUBST([GNULIB_LOCALTIME])
   GNULIB_NANOSLEEP=0;                    AC_SUBST([GNULIB_NANOSLEEP])
   GNULIB_STRPTIME=0;                     AC_SUBST([GNULIB_STRPTIME])
   GNULIB_TIMEGM=0;                       AC_SUBST([GNULIB_TIMEGM])
diff --git a/modules/localtime b/modules/localtime
new file mode 100644 (file)
index 0000000..5da46a9
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+localtime() function: convert time to broken-down local time.
+
+Files:
+lib/localtime.c
+m4/localtime.m4
+
+Depends-on:
+time
+
+configure.ac:
+gl_FUNC_LOCALTIME
+if test $REPLACE_LOCALTIME = 1; then
+  AC_LIBOBJ([localtime])
+fi
+gl_TIME_MODULE_INDICATOR([localtime])
+
+Makefile.am:
+
+Include:
+<time.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index eff6132fd20ebda8d8d39d849b44938f75949672..4bbfbd4578721275407de8aa4d23c1c342838551 100644 (file)
@@ -32,6 +32,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
              -e 's/@''GNULIB_CTIME''@/$(GNULIB_CTIME)/g' \
              -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
+             -e 's/@''GNULIB_LOCALTIME''@/$(GNULIB_LOCALTIME)/g' \
              -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
              -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
              -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \