]> Savannah Git Hosting - gnulib.git/commitdiff
wcsncat: Guarantee N3322 functionality.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 20:11:33 +0000 (21:11 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 21:38:35 +0000 (22:38 +0100)
* lib/wchar.in.h (wcsncat): Consider REPLACE_WCSNCAT.
* m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Test whether the zero-length bug is
present.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCAT.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSNCAT.
* modules/wcsncat (Status, Notice): Remove.
(configure.ac): Consider REPLACE_WCSNCAT.
* doc/posix-functions/wcsncat.texi: Mention the zero-length bug.

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

index 5f1a392fb4af9f05edbc41afaa6926d9dbf0dcb4..c019e77f02cf6084157c697b92614d48941d9a16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-11-05  Bruno Haible  <bruno@clisp.org>
+
+       wcsncat: Guarantee N3322 functionality.
+       * lib/wchar.in.h (wcsncat): Consider REPLACE_WCSNCAT.
+       * m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Test whether the zero-length bug is
+       present.
+       * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCAT.
+       * modules/wchar (Makefile.am): Substitute REPLACE_WCSNCAT.
+       * modules/wcsncat (Status, Notice): Remove.
+       (configure.ac): Consider REPLACE_WCSNCAT.
+       * doc/posix-functions/wcsncat.texi: Mention the zero-length bug.
+
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
        wmemmove tests: Verify N3322 functionality.
index 70232aa30e6356befe63171f3d94b983a7ee6de3..28cbe049f4ddfb2311d1b31a2cce2222861ec882 100644 (file)
@@ -9,6 +9,10 @@ Gnulib module: wcsncat
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function does not support zero-length operations on NULL pointers
+on some platforms:
+macOS 15, NetBSD 10.0, OpenBSD 7.6, Solaris 11.4, Cygwin 3.5.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 54354559efa67c0c4a3516a020c2647c6461f4bd..3c6beb0712300d58b3df8f8012cdc02cdceff138 100644 (file)
@@ -1149,14 +1149,27 @@ _GL_WARN_ON_USE (wcscat, "wcscat is unportable - "
 
 /* Append no more than N wide characters of SRC onto DEST.  */
 #if @GNULIB_WCSNCAT@
-# if !@HAVE_WCSNCAT@
+# if @REPLACE_WCSNCAT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef wcsncat
+#   define wcsncat rpl_wcsncat
+#  endif
+_GL_FUNCDECL_RPL (wcsncat, wchar_t *,
+                  (wchar_t *restrict dest, const wchar_t *restrict src,
+                   size_t n), );
+_GL_CXXALIAS_RPL (wcsncat, wchar_t *,
+                  (wchar_t *restrict dest, const wchar_t *restrict src,
+                   size_t n));
+# else
+#  if !@HAVE_WCSNCAT@
 _GL_FUNCDECL_SYS (wcsncat, wchar_t *,
                   (wchar_t *restrict dest, const wchar_t *restrict src,
                    size_t n), );
-# endif
+#  endif
 _GL_CXXALIAS_SYS (wcsncat, wchar_t *,
                   (wchar_t *restrict dest, const wchar_t *restrict src,
                    size_t n));
+# endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (wcsncat);
 # endif
index 14296d02915bb7b9e8f25186f0ea8afddf091033..cba48b3dc93ae5ab81044b65b13fe48c875cbfae 100644 (file)
@@ -1,5 +1,5 @@
 # wchar_h.m4
-# serial 64
+# serial 65
 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -257,6 +257,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   REPLACE_WCSWIDTH=0;   AC_SUBST([REPLACE_WCSWIDTH])
   REPLACE_WCSFTIME=0;   AC_SUBST([REPLACE_WCSFTIME])
   REPLACE_WCSCMP=0;     AC_SUBST([REPLACE_WCSCMP])
+  REPLACE_WCSNCAT=0;    AC_SUBST([REPLACE_WCSNCAT])
   REPLACE_WCSNCMP=0;    AC_SUBST([REPLACE_WCSNCMP])
   REPLACE_WCSSTR=0;     AC_SUBST([REPLACE_WCSSTR])
   REPLACE_WCSTOK=0;     AC_SUBST([REPLACE_WCSTOK])
index 13dbe354a5196da0078022ec2143ca56b2305482..7b04f23c95b33258020a6ad9912354b37976ad7c 100644 (file)
@@ -1,5 +1,5 @@
 # wcsncat.m4
-# serial 2
+# serial 3
 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,8 +9,37 @@ dnl This file is offered as-is, without any warranty.
 AC_DEFUN([gl_FUNC_WCSNCAT],
 [
   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
   AC_CHECK_FUNCS_ONCE([wcsncat])
-  if test $ac_cv_func_wcsncat = no; then
+  if test $ac_cv_func_wcsncat = yes; then
+    AC_CACHE_CHECK([for working wcsncat], [gl_cv_func_wcsncat_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <wchar.h>
+              #include <stddef.h>
+            ]], [[
+              wchar_t y[1];
+              int volatile value = (wcsncat (y, NULL, 0) == y);
+              return !value;
+            ]])
+         ],
+         [gl_cv_func_wcsncat_works=yes],
+         [gl_cv_func_wcsncat_works=no],
+         [case "$host_os" in
+            # Guess no on macOS, NetBSD, OpenBSD, Solaris, Cygwin.
+            darwin* | netbsd* | openbsd* | solaris* | cygwin*)
+              gl_cv_func_wcsncat_works="guessing no" ;;
+            *)
+              gl_cv_func_strndup_works="guessing yes" ;;
+          esac
+         ])
+      ])
+    case "$gl_cv_func_wcsncat_works" in
+      *yes) ;;
+      *) REPLACE_WCSNCAT=1 ;;
+    esac
+  else
     HAVE_WCSNCAT=0
   fi
 ])
index 393b2b18370126557f404fbd5761753449bae789..ac2ce394a3de937d5d77388f8199b24cda19b781 100644 (file)
@@ -148,6 +148,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
              -e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \
              -e 's|@''REPLACE_WCSCMP''@|$(REPLACE_WCSCMP)|g' \
+             -e 's|@''REPLACE_WCSNCAT''@|$(REPLACE_WCSNCAT)|g' \
              -e 's|@''REPLACE_WCSNCMP''@|$(REPLACE_WCSNCMP)|g' \
              -e 's|@''REPLACE_WCSSTR''@|$(REPLACE_WCSSTR)|g' \
              -e 's|@''REPLACE_WCSTOK''@|$(REPLACE_WCSTOK)|g' \
index 354e31761624b025e39942e0679dcde586b873a2..86708e543ed411bdc2b62c147dd37feec07caead 100644 (file)
@@ -1,12 +1,6 @@
 Description:
 wcsncat() function: append part of a wide string to a wide string.
 
-Status:
-obsolete
-
-Notice:
-This module is obsolete.
-
 Files:
 lib/wcsncat.c
 lib/wcsncat-impl.h
@@ -17,7 +11,8 @@ wchar
 
 configure.ac:
 gl_FUNC_WCSNCAT
-gl_CONDITIONAL([GL_COND_OBJ_WCSNCAT], [test $HAVE_WCSNCAT = 0])
+gl_CONDITIONAL([GL_COND_OBJ_WCSNCAT],
+               [test $HAVE_WCSNCAT = 0 || test $REPLACE_WCSNCAT = 1])
 gl_WCHAR_MODULE_INDICATOR([wcsncat])
 
 Makefile.am: