]> Savannah Git Hosting - gnulib.git/commitdiff
strftime-fixes: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 30 Apr 2017 15:14:35 +0000 (17:14 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 30 Apr 2017 17:26:38 +0000 (19:26 +0200)
* 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.

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

index 01cc13788fdf8925e1c10882167184d92a543c94..73faa79d14dc4c364a53209a1b1b19d56821c7d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
index d371818e2e0c4978140f69ae06191aa2114f00ca..0c2d992f93c55d2b0c9ea24e32a65124e1a8457f 100644 (file)
@@ -4,18 +4,18 @@
 
 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).
diff --git a/lib/strftime-fixes.c b/lib/strftime-fixes.c
new file mode 100644 (file)
index 0000000..6618c13
--- /dev/null
@@ -0,0 +1,40 @@
+/* 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);
+}
index 2587cdd1eafdbd8a12a999db76ff77206498eb14..8f748ecddae9c52969609978560e477cc811beb7 100644 (file)
@@ -249,6 +249,25 @@ _GL_CXXALIAS_SYS (ctime, char *, (time_t const *__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));
diff --git a/m4/strftime-fixes.m4 b/m4/strftime-fixes.m4
new file mode 100644 (file)
index 0000000..dbeb4d9
--- /dev/null
@@ -0,0 +1,15 @@
+# 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
+])
index 3a5db9b4e3c941f1b9e5d46ba2c8d2cf7422e1dd..d2dac9e232854e71530a97ee7e4756c0a50daea7 100644 (file)
@@ -1,4 +1,4 @@
-# serial 33
+# serial 34
 
 # Copyright (C) 1996-1997, 1999-2007, 2009-2017 Free Software Foundation, Inc.
 #
@@ -9,12 +9,6 @@
 # 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])
index 2eaf3aeb3a8aa3dc00037e7b3938d8f0b5c79e0a..e0f663ec711f4e46c8a023be570baa0e19bb558c 100644 (file)
@@ -108,6 +108,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
   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])
@@ -124,6 +125,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
   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.
diff --git a/modules/strftime-fixes b/modules/strftime-fixes
new file mode 100644 (file)
index 0000000..4a7bebf
--- /dev/null
@@ -0,0 +1,27 @@
+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
index 4bbfbd4578721275407de8aa4d23c1c342838551..5cb8ac2c528f77044d543c40a780f216a278e5ab 100644 (file)
@@ -35,6 +35,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \
@@ -50,6 +51,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \