]> Savannah Git Hosting - gnulib.git/commitdiff
wcstok: Work around wrong signature on native Windows.
authorBruno Haible <bruno@clisp.org>
Sun, 24 Nov 2019 12:11:12 +0000 (13:11 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 24 Nov 2019 12:11:12 +0000 (13:11 +0100)
* lib/wchar.in.h (wcstok): Override when REPLACE_WCSTOK is 1.
* m4/wcstok.m4 (gl_FUNC_WCSTOK): Check for signature of wcstok. Set
REPLACE_WCSTOK.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSTOK.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSTOK.
* modules/wcstok (Depends-on, configure.ac): Consider REPLACE_WCSTOK.
* doc/posix-functions/wcstok.texi: Mention the problem.

ChangeLog
doc/posix-functions/wcstok.texi
lib/wchar.in.h
m4/wchar_h.m4
m4/wcstok.m4
modules/wchar
modules/wcstok

index 47b079b8255865ac75ce48926fedd0ef4f68efa6..9e6725afcce1f3d6387145c433b5fcf3ee434132 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
+       wcstok: Work around wrong signature on native Windows.
+       * lib/wchar.in.h (wcstok): Override when REPLACE_WCSTOK is 1.
+       * m4/wcstok.m4 (gl_FUNC_WCSTOK): Check for signature of wcstok. Set
+       REPLACE_WCSTOK.
+       * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSTOK.
+       * modules/wchar (Makefile.am): Substitute REPLACE_WCSTOK.
+       * modules/wcstok (Depends-on, configure.ac): Consider REPLACE_WCSTOK.
+       * doc/posix-functions/wcstok.texi: Mention the problem.
+
 2019-11-22  Paul Eggert  <eggert@cs.ucla.edu>
 
        intprops: INT_MULTIPLY_WRAPV speedup for GCC 8.4+
index c93e236b941302c9a7b9d5805dbb150d6587d768..6f971e148055034f4d082fc44d97781984a023d1 100644 (file)
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Cygwin 1.5.x.
+@item
+This function takes only two arguments on some platforms:
+mingw, MSVC 14.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 3ebcdba1abe62eca47ea9365c451176143724270..9807f6069aa16db084ca11d6f3ed05cc2c1c1b61 100644 (file)
@@ -1037,12 +1037,23 @@ _GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - "
 
 /* Divide WCS into tokens separated by characters in DELIM.  */
 #if @GNULIB_WCSTOK@
-# if !@HAVE_WCSTOK@
+# if @REPLACE_WCSTOK@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcstok
+#   define wcstok rpl_wcstok
+#  endif
+_GL_FUNCDECL_RPL (wcstok, wchar_t *,
+                  (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
+_GL_CXXALIAS_RPL (wcstok, wchar_t *,
+                  (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
+# else
+#  if !@HAVE_WCSTOK@
 _GL_FUNCDECL_SYS (wcstok, wchar_t *,
                   (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (wcstok, wchar_t *,
                   (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr));
+# endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (wcstok);
 # endif
index cd20e7a0c174abb3d16b2bbb2516d0d53d0f625a..8c6ebccfcbd0ac7b09783067578368e805d909dd 100644 (file)
@@ -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 43
+# wchar_h.m4 serial 44
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -237,4 +237,5 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
   REPLACE_WCSWIDTH=0;   AC_SUBST([REPLACE_WCSWIDTH])
   REPLACE_WCSFTIME=0;   AC_SUBST([REPLACE_WCSFTIME])
+  REPLACE_WCSTOK=0;     AC_SUBST([REPLACE_WCSTOK])
 ])
index 8201ca36ccb764d3f18522eb6a4f25b0e0f9fd4b..8f0aeb0f54eac02248721f5802b2ae58cf9981d6 100644 (file)
@@ -1,4 +1,4 @@
-# wcstok.m4 serial 2
+# wcstok.m4 serial 3
 dnl Copyright (C) 2011-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,7 +8,32 @@ AC_DEFUN([gl_FUNC_WCSTOK],
 [
   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
   AC_CHECK_FUNCS_ONCE([wcstok])
-  if test $ac_cv_func_wcstok = no; then
+  if test $ac_cv_func_wcstok = yes; then
+    dnl POSIX:        wchar_t *wcstok (wchar_t *, const wchar_t *, wchar_t **);
+    dnl mingw, MSVC:  wchar_t *wcstok (wchar_t *, const wchar_t *);
+    AC_CACHE_CHECK([for wcstok with POSIX signature],
+      [gl_cv_func_wcstok_posix_signature],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+   included before <wchar.h>.  */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+wchar_t *wcstok (wchar_t *, const wchar_t *, wchar_t **);
+]],
+            [])],
+         [gl_cv_func_wcstok_posix_signature=yes],
+         [gl_cv_func_wcstok_posix_signature=no])
+      ])
+    if test $gl_cv_func_wcstok_posix_signature = no; then
+      REPLACE_WCSTOK=1
+    fi
+  else
     HAVE_WCSTOK=0
   fi
 ])
index 29c67e84795d2eea2822b7f5768e238e6631e2e8..a943740a91201281f53955672bc3584475f6ba50 100644 (file)
@@ -131,6 +131,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
              -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
              -e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \
+             -e 's|@''REPLACE_WCSTOK''@|$(REPLACE_WCSTOK)|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)'; \
index 3ee3192fb18f8b04ec3e485edae396717762d0a1..6f7e62c8ba1d54e6594000580b05b2dbb1e3d262 100644 (file)
@@ -8,12 +8,12 @@ m4/wcstok.m4
 
 Depends-on:
 wchar
-wcsspn          [test $HAVE_WCSTOK = 0]
-wcspbrk         [test $HAVE_WCSTOK = 0]
+wcsspn          [test $HAVE_WCSTOK = 0 || test $REPLACE_WCSTOK = 1]
+wcspbrk         [test $HAVE_WCSTOK = 0 || test $REPLACE_WCSTOK = 1]
 
 configure.ac:
 gl_FUNC_WCSTOK
-if test $HAVE_WCSTOK = 0; then
+if test $HAVE_WCSTOK = 0 || test $REPLACE_WCSTOK = 1; then
   AC_LIBOBJ([wcstok])
 fi
 gl_WCHAR_MODULE_INDICATOR([wcstok])