* lib/time.in.h (strftime): New declaration.
* lib/strftime-fixes.c: New file.
* m4/strftime.m4 (gl_FUNC_GNU_STRFTIME): Inline gl_FUNC_STRFTIME macro.
(gl_FUNC_STRFTIME): Remove macro.
* m4/strftime-fixes.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_STRFTIME,
REPLACE_STRFTIME.
* modules/time (Makefile.am): Substitute GNULIB_STRFTIME,
REPLACE_STRFTIME.
* modules/strftime-fixes: New file.
* doc/posix-functions/strftime.texi: Mention the new module.
+2017-04-30 Bruno Haible <bruno@clisp.org>
+
+ strftime-fixes: New module.
+ * lib/time.in.h (strftime): New declaration.
+ * lib/strftime-fixes.c: New file.
+ * m4/strftime.m4 (gl_FUNC_GNU_STRFTIME): Inline gl_FUNC_STRFTIME macro.
+ (gl_FUNC_STRFTIME): Remove macro.
+ * m4/strftime-fixes.m4: New file.
+ * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_STRFTIME,
+ REPLACE_STRFTIME.
+ * modules/time (Makefile.am): Substitute GNULIB_STRFTIME,
+ REPLACE_STRFTIME.
+ * modules/strftime-fixes: New file.
+ * doc/posix-functions/strftime.texi: Mention the new module.
+
2017-04-30 Bruno Haible <bruno@clisp.org>
mktime: Work around TZ problem on native Windows.
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/strftime.html}
-Gnulib module: ---
+Gnulib module: strftime-fixes
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
The Windows C runtime library (which is used by MinGW) does not
support the %e specifier (and possibly the other more recent SUS
specifiers too, i.e., %C, %D, %h, %n, %r, %R, %t, and %T).
--- /dev/null
+/* Work around platform bugs in strftime.
+ 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>
+
+#include <stdlib.h>
+#include <string.h>
+
+#undef strftime
+
+size_t
+rpl_strftime (char *buf, size_t bufsize, const char *format, const struct tm *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 strftime (buf, bufsize, format, tp);
+}
_GL_CXXALIASWARN (ctime);
# endif
+/* Convert *TP to a date and time string. See
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
+# if @GNULIB_STRFTIME@
+# if @REPLACE_STRFTIME@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define strftime rpl_strftime
+# endif
+_GL_FUNCDECL_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
+ const char *__fmt, const struct tm *__tp)
+ _GL_ARG_NONNULL ((1, 3, 4)));
+_GL_CXXALIAS_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
+ const char *__fmt, const struct tm *__tp));
+# else
+_GL_CXXALIAS_SYS (strftime, size_t, (char *__buf, size_t __bufsize,
+ const char *__fmt, const struct tm *__tp));
+# endif
+_GL_CXXALIASWARN (strftime);
+# endif
+
# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
typedef struct tm_zone *timezone_t;
_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
--- /dev/null
+# strftime-fixes.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_STRFTIME],
+[
+ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ case "$host_os" in
+ mingw*) REPLACE_STRFTIME=1 ;;
+ *) REPLACE_STRFTIME=0 ;;
+ esac
+])
-# serial 33
+# serial 34
# Copyright (C) 1996-1997, 1999-2007, 2009-2017 Free Software Foundation, Inc.
#
# Written by Jim Meyering and Paul Eggert.
AC_DEFUN([gl_FUNC_GNU_STRFTIME],
-[
- gl_FUNC_STRFTIME
-])
-
-# These are the prerequisite macros for GNU's strftime.c replacement.
-AC_DEFUN([gl_FUNC_STRFTIME],
[
# This defines (or not) HAVE_TZNAME and HAVE_TM_ZONE.
AC_REQUIRE([AC_STRUCT_TIMEZONE])
GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
GNULIB_LOCALTIME=0; AC_SUBST([GNULIB_LOCALTIME])
GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
+ GNULIB_STRFTIME=0; AC_SUBST([GNULIB_STRFTIME])
GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
+ REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME])
REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
dnl Hack so that the time module doesn't depend on the sys_time module.
--- /dev/null
+Description:
+strftime() function: convert broken-down time to string.
+
+Files:
+lib/strftime-fixes.c
+m4/strftime-fixes.m4
+
+Depends-on:
+time
+
+configure.ac:
+gl_FUNC_STRFTIME
+if test $REPLACE_STRFTIME = 1; then
+ AC_LIBOBJ([strftime-fixes])
+fi
+gl_TIME_MODULE_INDICATOR([strftime])
+
+Makefile.am:
+
+Include:
+<time.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-e 's/@''GNULIB_LOCALTIME''@/$(GNULIB_LOCALTIME)/g' \
-e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
-e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
+ -e 's/@''GNULIB_STRFTIME''@/$(GNULIB_STRFTIME)/g' \
-e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
-e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
-e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
-e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
-e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
-e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
+ -e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \
-e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
-e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \
-e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \