bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'strftime-fixes'


From: Bruno Haible
Subject: new module 'strftime-fixes'
Date: Sun, 30 Apr 2017 19:52:53 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-75-generic; KDE/5.18.0; x86_64; ; )

> * Some which should obey TZ, just that they should ignore the values set by
>   Cygwin (instead of exhibiting garbage behaviour):
> 
>   strftime, _strftime_l
>   https://msdn.microsoft.com/en-us/library/fe06s4ak.aspx
>   http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

This implements the workaround. Unfortunately, the module name 'strftime' was
already taken.


2017-04-30  Bruno Haible  <address@hidden>

        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.

diff --git a/doc/posix-functions/strftime.texi 
b/doc/posix-functions/strftime.texi
index d371818..0c2d992 100644
--- a/doc/posix-functions/strftime.texi
+++ b/doc/posix-functions/strftime.texi
@@ -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
address@hidden
+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.
address@hidden
 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
index 0000000..6618c13
--- /dev/null
+++ b/lib/strftime-fixes.c
@@ -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);
+}
diff --git a/lib/time.in.h b/lib/time.in.h
index 2587cdd..8f748ec 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -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
index 0000000..dbeb4d9
--- /dev/null
+++ b/m4/strftime-fixes.m4
@@ -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
+])
diff --git a/m4/strftime.m4 b/m4/strftime.m4
index 3a5db9b..d2dac9e 100644
--- a/m4/strftime.m4
+++ b/m4/strftime.m4
@@ -1,4 +1,4 @@
-# serial 33
+# serial 34
 
 # Copyright (C) 1996-1997, 1999-2007, 2009-2017 Free Software Foundation, Inc.
 #
@@ -10,12 +10,6 @@
 
 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])
 
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index 2eaf3ae..e0f663e 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -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
index 0000000..4a7bebf
--- /dev/null
+++ b/modules/strftime-fixes
@@ -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
diff --git a/modules/time b/modules/time
index 4bbfbd4..5cb8ac2 100644
--- a/modules/time
+++ b/modules/time
@@ -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'
 \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]