+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.
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.
--- /dev/null
+/* 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
/* 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
--- /dev/null
+# 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
+])
[
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])
--- /dev/null
+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
-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' \