changeset 38519:673604d917b1

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 30 Apr 2017 17:56:49 +0200
parents 74c98c38c0fc
children 0f47931842b9
files ChangeLog doc/posix-functions/wcsftime.texi lib/wchar.in.h lib/wcsftime.c m4/wchar_h.m4 m4/wcsftime.m4 modules/wchar modules/wcsftime
diffstat 8 files changed, 145 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Apr 30 17:14:35 2017 +0200
+++ b/ChangeLog	Sun Apr 30 17:56:49 2017 +0200
@@ -1,3 +1,17 @@
+2017-04-30  Bruno Haible  <bruno@clisp.org>
+
+	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.
+
 2017-04-30  Bruno Haible  <bruno@clisp.org>
 
 	strftime-fixes: New module.
--- a/doc/posix-functions/wcsftime.texi	Sun Apr 30 17:14:35 2017 +0200
+++ b/doc/posix-functions/wcsftime.texi	Sun Apr 30 17:56:49 2017 +0200
@@ -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
+@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:
@@ -16,9 +19,6 @@
 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.
-@item
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
 @end itemize
--- a/lib/wchar.in.h	Sun Apr 30 17:14:35 2017 +0200
+++ b/lib/wchar.in.h	Sun Apr 30 17:56:49 2017 +0200
@@ -1036,6 +1036,38 @@
 #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 !@HAVE_WCSFTIME@
+_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 /* _@GUARD_PREFIX@_WCHAR_H */
 #endif /* _@GUARD_PREFIX@_WCHAR_H */
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/wcsftime.c	Sun Apr 30 17:56:49 2017 +0200
@@ -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);
+}
--- a/m4/wchar_h.m4	Sun Apr 30 17:14:35 2017 +0200
+++ b/m4/wchar_h.m4	Sun Apr 30 17:56:49 2017 +0200
@@ -7,7 +7,7 @@
 
 dnl Written by Eric Blake.
 
-# wchar_h.m4 serial 40
+# wchar_h.m4 serial 41
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -53,7 +53,7 @@
      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 @@
   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 @@
   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 @@
   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])
 ])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/wcsftime.m4	Sun Apr 30 17:56:49 2017 +0200
@@ -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
+])
--- a/modules/wchar	Sun Apr 30 17:14:35 2017 +0200
+++ b/modules/wchar	Sun Apr 30 17:56:49 2017 +0200
@@ -71,6 +71,7 @@
 	      -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 @@
 	      -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 @@
 	      -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)'; \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/wcsftime	Sun Apr 30 17:56:49 2017 +0200
@@ -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