]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: Fix test failure on Cygwin.
authorBruno Haible <bruno@clisp.org>
Mon, 17 Jun 2024 19:53:30 +0000 (21:53 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 17 Jun 2024 19:53:30 +0000 (21:53 +0200)
* m4/vasnprintf.m4 (gl_FUNC_VASNPRINTF): Require AC_CANONICAL_HOST. Test
whether vasnprintf works reliably; invoke gl_REPLACE_VASNPRINTF if not.

ChangeLog
m4/vasnprintf.m4

index aaf0153f092067e98537f42f400ff52c3ccb3001..f0593b5e50f79cc7bc9bfa07f1cc4187940d4a0f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-06-17  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Fix test failure on Cygwin.
+       * m4/vasnprintf.m4 (gl_FUNC_VASNPRINTF): Require AC_CANONICAL_HOST. Test
+       whether vasnprintf works reliably; invoke gl_REPLACE_VASNPRINTF if not.
+
 2024-06-17  Bruno Haible  <bruno@clisp.org>
 
        nstrftime, c-nstrftime: Fix crash on Solaris 11.4.
index 5dc3fe0c4d626c709dba37061cf46ba6bc849b4d..a02f4e1e1de25ae9f1c78a05b9b7c42496ba527e 100644 (file)
@@ -1,5 +1,5 @@
 # vasnprintf.m4
-# serial 53
+# serial 54
 dnl Copyright (C) 2002-2004, 2006-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,
@@ -7,8 +7,40 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_VASNPRINTF],
 [
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CHECK_FUNCS_ONCE([vasnprintf])
-  if test $ac_cv_func_vasnprintf = no; then
+  if test $ac_cv_func_vasnprintf = yes; then
+    dnl On Cygwin, in directives with a huge width, the width is ignored, and
+    dnl the function returns a wrong result.
+    AC_CACHE_CHECK([whether vasnprintf works],
+      [gl_cv_func_vasnprintf_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_SOURCE(
+            [[#include <stdio.h>
+            ]],
+            [[size_t len;
+              char *res = vasnprintf (NULL, &len, "x%03000000000dy\n", -17);
+              /* On Cygwin 3.4.6, res is "x-17y\n" and len == 6: wrong.  */
+              return (res != NULL && len < 10);
+            ]])
+         ],
+         [gl_cv_func_vasnprintf_works=yes],
+         [gl_cv_func_vasnprintf_works=no],
+         [case "$host_os" in
+                     # Guess no on Cygwin.
+            cygwin*) gl_cv_func_vasnprintf_works="guessing no";;
+                     # If we don't know, obey --enable-cross-guesses.
+            *)       gl_cv_func_vasnprintf_works="$gl_cross_guess_normal";;
+          esac
+         ])
+      ])
+  fi
+  if test $ac_cv_func_vasnprintf != yes \
+     || case "$gl_cv_func_vasnprintf_works" in
+          *yes) false;;
+          *)    true;;
+        esac
+  then
     gl_REPLACE_VASNPRINTF
   fi
 ])