bug-gnulib
[Top][All Lists]
Advanced

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

new module 'wcsftime'


From: Bruno Haible
Subject: new module 'wcsftime'
Date: Sun, 30 Apr 2017 19:54:03 +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):
> 
>   wcsftime, _wcsftime_l
>   https://msdn.microsoft.com/en-us/library/fe06s4ak.aspx
>   http://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html

Fixed like this:


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

        wcsftime: New module.
        * lib/wchar.in.h (wcsftime): New declaration.
        * lib/wcsftime.c: New file.
        * m4/wcsftime.m4: New file.
        * m4/wchar_h.m4 (gl_WCHAR_H): Test for wcsftime declaration.
        (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_WCSFTIME,
        HAVE_WCSFTIME, REPLACE_WCSFTIME.
        * modules/wchar (Makefile.am): Substitute GNULIB_WCSFTIME,
        HAVE_WCSFTIME, REPLACE_WCSFTIME.
        * modules/wcsftime: New file.
        * doc/posix-functions/wcsftime.texi: Mention the new module.

diff --git a/doc/posix-functions/wcsftime.texi 
b/doc/posix-functions/wcsftime.texi
index 8ab82c2..931b81c 100644
--- a/doc/posix-functions/wcsftime.texi
+++ b/doc/posix-functions/wcsftime.texi
@@ -4,10 +4,13 @@
 
 POSIX specification:@* 
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html}
 
-Gnulib module: ---
+Gnulib module: wcsftime
 
 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:
@@ -16,9 +19,6 @@ Portability problems not fixed by Gnulib:
 This function is missing on some platforms:
 OpenBSD 3.8, Minix 3.1.8, IRIX 5.3, Solaris 2.5.1, Cygwin 1.5.x, BeOS.
 @item
-On native Windows platforms (mingw, MSVC), this function works incorrectly
-when the environment variable @code{TZ} has been set by Cygwin.
address@hidden
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore 
cannot
 accommodate all Unicode characters.
 @end itemize
diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index 4969a0c..ef155d2 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -1036,6 +1036,38 @@ _GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - "
 #endif
 
 
+/* Convert *TP to a date and time wide string.  See
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html>.  
*/
+#if @GNULIB_WCSFTIME@
+# if @REPLACE_WCSFTIME@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcsftime
+#   define wcsftime rpl_wcsftime
+#  endif
+_GL_FUNCDECL_RPL (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
+                                     const wchar_t *__fmt, const struct tm 
*__tp)
+                                    _GL_ARG_NONNULL ((1, 3, 4)));
+_GL_CXXALIAS_RPL (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
+                                     const wchar_t *__fmt, const struct tm 
*__tp));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
+                                     const wchar_t *__fmt, const struct tm 
*__tp)
+                                    _GL_ARG_NONNULL ((1, 3, 4)));
+#  endif
+_GL_CXXALIAS_SYS (wcsftime, size_t, (wchar_t *__buf, size_t __bufsize,
+                                     const wchar_t *__fmt, const struct tm 
*__tp));
+# endif
+_GL_CXXALIASWARN (wcsftime);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsftime
+# if HAVE_RAW_DECL_WCSFTIME
+_GL_WARN_ON_USE (wcsftime, "wcsftime is unportable - "
+                 "use gnulib module wcsftime for portability");
+# endif
+#endif
+
+
 #endif /* address@hidden@_WCHAR_H */
 #endif /* address@hidden@_WCHAR_H */
 #endif
diff --git a/lib/wcsftime.c b/lib/wcsftime.c
new file mode 100644
index 0000000..cffe2e0
--- /dev/null
+++ b/lib/wcsftime.c
@@ -0,0 +1,41 @@
+/* Work around platform bugs in wcsftime.
+   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 <wchar.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#undef wcsftime
+
+size_t
+rpl_wcsftime (wchar_t *buf, size_t bufsize, const wchar_t *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 wcsftime (buf, bufsize, format, tp);
+}
diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4
index d0e11a0..621cfb9 100644
--- a/m4/wchar_h.m4
+++ b/m4/wchar_h.m4
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 dnl Written by Eric Blake.
 
-# wchar_h.m4 serial 40
+# wchar_h.m4 serial 41
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -53,7 +53,7 @@ AC_DEFUN([gl_WCHAR_H],
      wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset
      wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
      wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
-     wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth
+     wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
     ])
 ])
 
@@ -177,6 +177,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   GNULIB_WCSSTR=0;      AC_SUBST([GNULIB_WCSSTR])
   GNULIB_WCSTOK=0;      AC_SUBST([GNULIB_WCSTOK])
   GNULIB_WCSWIDTH=0;    AC_SUBST([GNULIB_WCSWIDTH])
+  GNULIB_WCSFTIME=0;    AC_SUBST([GNULIB_WCSFTIME])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
@@ -215,6 +216,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   HAVE_WCSSTR=1;        AC_SUBST([HAVE_WCSSTR])
   HAVE_WCSTOK=1;        AC_SUBST([HAVE_WCSTOK])
   HAVE_WCSWIDTH=1;      AC_SUBST([HAVE_WCSWIDTH])
+  HAVE_WCSFTIME=1;      AC_SUBST([HAVE_WCSFTIME])
   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
@@ -230,4 +232,5 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
   REPLACE_WCSWIDTH=0;   AC_SUBST([REPLACE_WCSWIDTH])
+  REPLACE_WCSFTIME=0;   AC_SUBST([REPLACE_WCSFTIME])
 ])
diff --git a/m4/wcsftime.m4 b/m4/wcsftime.m4
new file mode 100644
index 0000000..a28d4d5
--- /dev/null
+++ b/m4/wcsftime.m4
@@ -0,0 +1,19 @@
+# wcsftime.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_WCSFTIME],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CHECK_FUNCS_ONCE([wcsftime])
+  if test $ac_cv_func_wcsftime = no; then
+    HAVE_WCSFTIME=0
+  else
+    case "$host_os" in
+      mingw*) REPLACE_WCSFTIME=1 ;;
+    esac
+  fi
+])
diff --git a/modules/wchar b/modules/wchar
index f29b200..73012c6 100644
--- a/modules/wchar
+++ b/modules/wchar
@@ -71,6 +71,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's/@''GNULIB_WCSSTR''@/$(GNULIB_WCSSTR)/g' \
              -e 's/@''GNULIB_WCSTOK''@/$(GNULIB_WCSTOK)/g' \
              -e 's/@''GNULIB_WCSWIDTH''@/$(GNULIB_WCSWIDTH)/g' \
+             -e 's/@''GNULIB_WCSFTIME''@/$(GNULIB_WCSFTIME)/g' \
              < $(srcdir)/wchar.in.h | \
          sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
              -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
@@ -110,6 +111,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \
              -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \
              -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \
+             -e 's|@''HAVE_WCSFTIME''@|$(HAVE_WCSFTIME)|g' \
              -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
              -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
          | \
@@ -126,6 +128,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \
              -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
              -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
+             -e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
diff --git a/modules/wcsftime b/modules/wcsftime
new file mode 100644
index 0000000..d911a28
--- /dev/null
+++ b/modules/wcsftime
@@ -0,0 +1,27 @@
+Description:
+wcsftime() function: convert broken-down time to wide string.
+
+Files:
+lib/wcsftime.c
+m4/wcsftime.m4
+
+Depends-on:
+wchar
+
+configure.ac:
+gl_FUNC_WCSFTIME
+if test $REPLACE_WCSFTIME = 1; then
+  AC_LIBOBJ([wcsftime])
+fi
+gl_WCHAR_MODULE_INDICATOR([wcsftime])
+
+Makefile.am:
+
+Include:
+<wchar.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all




reply via email to

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