From 806d6f857009f0920b74405004a8ea42b4adb23d Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 22 Mar 2023 21:33:24 +0100
Subject: [PATCH] =?utf8?q?vasnwprintf:=20Fix=20a=20warning:=20implicit=20d?=
 =?utf8?q?eclaration=20of=20function=20=E2=80=98wcsnlen=E2=80=99.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

* m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Test also whether wcsnlen is
declared.
* lib/vasnprintf.c (local_wcsnlen): Together with HAVE_WCSNLEN, test
also HAVE_DECL_WCSNLEN.
---
 ChangeLog        | 8 ++++++++
 lib/vasnprintf.c | 2 +-
 m4/vasnprintf.m4 | 3 ++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 39f5b2c117..88a8ea4d36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-03-22  Bruno Haible  <bruno@clisp.org>
+
+	vasnwprintf: Fix a warning: implicit declaration of function ‘wcsnlen’.
+	* m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Test also whether wcsnlen is
+	declared.
+	* lib/vasnprintf.c (local_wcsnlen): Together with HAVE_WCSNLEN, test
+	also HAVE_DECL_WCSNLEN.
+
 2023-03-22  Bruno Haible  <bruno@clisp.org>
 
 	vasnwprintf: Fix a "warning: unused function local_wcsnlen".
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 618fae7c77..5cd52b5b6e 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -271,7 +271,7 @@ local_wcslen (const wchar_t *s)
 #endif
 
 #if (!USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
-# if HAVE_WCSNLEN
+# if HAVE_WCSNLEN && HAVE_DECL_WCSNLEN
 #  define local_wcsnlen wcsnlen
 # else
 #  ifndef local_wcsnlen_defined
diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4
index 911e77c874..a42b5f83ac 100644
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 45
+# vasnprintf.m4 serial 46
 dnl Copyright (C) 2002-2004, 2006-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -96,6 +96,7 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNWPRINTF],
 [
   AC_CHECK_FUNCS_ONCE([swprintf wcsnlen mbrtowc])
   AC_CHECK_DECLS([_snwprintf], , , [[#include <stdio.h>]])
+  AC_CHECK_DECLS([wcsnlen], , , [[#include <wchar.h>]])
   gl_SWPRINTF_WORKS
   case "$gl_cv_func_swprintf_works" in
     *yes)
-- 
2.39.5