summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2017-04-30 17:56:49 +0200
committerBruno Haible <bruno@clisp.org>2017-04-30 19:26:39 +0200
commit05226f4e52f0d6ff55c598c24b07672cc6fa295e (patch)
tree3430fd48548673bf6bbf789a867f0d10f9d4d74e
parent9df4babee613569704bd8947de9a3cd46086b43e (diff)
downloadgnulib-05226f4e52f0d6ff55c598c24b07672cc6fa295e.tar.gz
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.
-rw-r--r--ChangeLog14
-rw-r--r--doc/posix-functions/wcsftime.texi8
-rw-r--r--lib/wchar.in.h32
-rw-r--r--lib/wcsftime.c41
-rw-r--r--m4/wchar_h.m47
-rw-r--r--m4/wcsftime.m419
-rw-r--r--modules/wchar3
-rw-r--r--modules/wcsftime27
8 files changed, 145 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 73faa79d14..a3b8f5ed38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
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.
* lib/time.in.h (strftime): New declaration.
* lib/strftime-fixes.c: New file.
diff --git a/doc/posix-functions/wcsftime.texi b/doc/posix-functions/wcsftime.texi
index 8ab82c20a1..931b81c1a1 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
+@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 @@ 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.
-@item
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 4969a0c99a..ef155d22d7 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 !@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
diff --git a/lib/wcsftime.c b/lib/wcsftime.c
new file mode 100644
index 0000000000..cffe2e0932
--- /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 d0e11a04e2..621cfb9df4 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 0000000000..a28d4d50ad
--- /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 f29b200b3a..73012c60d1 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 0000000000..d911a28897
--- /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