Now that we have a unit test and workarounds for strcasecmp, it's
relatively easy to implement strcasecmp_l. Done through these patches:


2025-02-16  Bruno Haible  <br...@clisp.org>

        strncasecmp_l: Add tests.
        * tests/test-strncasecmp_l.c: New file.
        * modules/strncasecmp_l-tests: New file.

        strncasecmp_l: New module.
        * lib/strings.in.h (strncasecmp_l): New declaration.
        * lib/strncasecmp_l.c: New file, based on lib/strncasecmp.c.
        * m4/strncasecmp_l.m4: New file.
        * m4/strings_h.m4 (gl_STRINGS_H): Test for strncasecmp_l.
        (gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRNCASECMP_L.
        (gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRNCASECMP_L,
        REPLACE_STRNCASECMP_L.
        * modules/strings-h (Makefile.am): Substitute GNULIB_STRNCASECMP_L,
        HAVE_STRNCASECMP_L, REPLACE_STRNCASECMP_L.
        * modules/strncasecmp_l: New file.
        * tests/test-strings-h-c++.cc: Check declaration of strncasecmp_l.
        * doc/posix-functions/strncasecmp_l.texi: Mention the new module and the
        macOS, Solaris, Cygwin bugs.

2025-02-16  Bruno Haible  <br...@clisp.org>

        strcasecmp_l: Add tests.
        * tests/test-strcasecmp_l.c: New file.
        * modules/strcasecmp_l-tests: New file.

        strcasecmp_l: New module.
        * lib/strings.in.h: Include <locale.h>.
        (strcasecmp_l): New declaration.
        * lib/strcasecmp_l.c: New file, based on lib/strcasecmp.c.
        * m4/strcasecmp_l.m4: New file.
        * m4/strings_h.m4 (gl_STRINGS_H): Test for strcasecmp_l.
        (gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRCASECMP_L.
        (gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRCASECMP_L,
        REPLACE_STRCASECMP_L.
        * modules/strings-h (Makefile.am): Substitute GNULIB_STRCASECMP_L,
        HAVE_STRCASECMP_L, REPLACE_STRCASECMP_L.
        * modules/strcasecmp_l: New file.
        * tests/test-strings-h-c++.cc: Check declaration of strcasecmp_l.
        * doc/posix-functions/strcasecmp_l.texi: Mention the new module and the
        macOS, Solaris, Cygwin bugs.

>From 6fafa36c5140b9fa0470da7f49e1fb212f608961 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 16 Feb 2025 22:32:02 +0100
Subject: [PATCH 1/4] strcasecmp_l: New module.

* lib/strings.in.h: Include <locale.h>.
(strcasecmp_l): New declaration.
* lib/strcasecmp_l.c: New file, based on lib/strcasecmp.c.
* m4/strcasecmp_l.m4: New file.
* m4/strings_h.m4 (gl_STRINGS_H): Test for strcasecmp_l.
(gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRCASECMP_L.
(gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRCASECMP_L,
REPLACE_STRCASECMP_L.
* modules/strings-h (Makefile.am): Substitute GNULIB_STRCASECMP_L,
HAVE_STRCASECMP_L, REPLACE_STRCASECMP_L.
* modules/strcasecmp_l: New file.
* tests/test-strings-h-c++.cc: Check declaration of strcasecmp_l.
* doc/posix-functions/strcasecmp_l.texi: Mention the new module and the
macOS, Solaris, Cygwin bugs.
---
 ChangeLog                             | 18 ++++++
 doc/posix-functions/strcasecmp_l.texi | 16 +++--
 lib/strcasecmp_l.c                    | 84 +++++++++++++++++++++++++++
 lib/strings.in.h                      | 47 ++++++++++++++-
 m4/strcasecmp_l.m4                    | 34 +++++++++++
 m4/strings_h.m4                       |  7 ++-
 modules/strcasecmp_l                  | 39 +++++++++++++
 modules/strings-h                     |  3 +
 tests/test-strings-h-c++.cc           |  5 ++
 9 files changed, 246 insertions(+), 7 deletions(-)
 create mode 100644 lib/strcasecmp_l.c
 create mode 100644 m4/strcasecmp_l.m4
 create mode 100644 modules/strcasecmp_l

diff --git a/ChangeLog b/ChangeLog
index ba22c1571a..0ffa42d3e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2025-02-16  Bruno Haible  <br...@clisp.org>
+
+	strcasecmp_l: New module.
+	* lib/strings.in.h: Include <locale.h>.
+	(strcasecmp_l): New declaration.
+	* lib/strcasecmp_l.c: New file, based on lib/strcasecmp.c.
+	* m4/strcasecmp_l.m4: New file.
+	* m4/strings_h.m4 (gl_STRINGS_H): Test for strcasecmp_l.
+	(gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRCASECMP_L.
+	(gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRCASECMP_L,
+	REPLACE_STRCASECMP_L.
+	* modules/strings-h (Makefile.am): Substitute GNULIB_STRCASECMP_L,
+	HAVE_STRCASECMP_L, REPLACE_STRCASECMP_L.
+	* modules/strcasecmp_l: New file.
+	* tests/test-strings-h-c++.cc: Check declaration of strcasecmp_l.
+	* doc/posix-functions/strcasecmp_l.texi: Mention the new module and the
+	macOS, Solaris, Cygwin bugs.
+
 2025-02-16  Collin Funk  <collin.fu...@gmail.com>
 
 	unistd-h tests: Check that unistd.h defines O_CLOEXEC.
diff --git a/doc/posix-functions/strcasecmp_l.texi b/doc/posix-functions/strcasecmp_l.texi
index 2b8273a66c..6d26ae8649 100644
--- a/doc/posix-functions/strcasecmp_l.texi
+++ b/doc/posix-functions/strcasecmp_l.texi
@@ -4,15 +4,23 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp_l.html}
 
-Gnulib module: ---
+Gnulib module: strcasecmp_l
+@mindex strcasecmp_l
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+FreeBSD 9.0, NetBSD 10.0, OpenBSD 6.1, Minix 3.3.0, AIX 6.1, HP-UX 11, Solaris 11.3, Cygwin 2.5.x, mingw, MSVC 14, Android 5.1.
+@item
+This function is declared in @code{<string.h>} instead of @code{<strings.h>}
+on some platforms:
+glibc 2.9, macOS 15.
+@item
+This function uses the case mappings of a wrong locale on some platforms:
+Solaris 11.4, Cygwin 3.5.6.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-FreeBSD 6.0, NetBSD 10.0, OpenBSD 6.0, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.3, Cygwin 1.7.x, mingw, MSVC 14, Android 5.1.
 @end itemize
diff --git a/lib/strcasecmp_l.c b/lib/strcasecmp_l.c
new file mode 100644
index 0000000000..6ed2a72f8d
--- /dev/null
+++ b/lib/strcasecmp_l.c
@@ -0,0 +1,84 @@
+/* Case-insensitive string comparison function for unibyte locales.
+   Copyright (C) 1998-2025 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <strings.h>
+
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+
+int
+strcasecmp_l (const char *s1, const char *s2, locale_t locale)
+{
+#if GNULIB_defined_locale_t
+
+  struct gl_locale_category_t *plc =
+    &locale->category[gl_log2_lc_mask (LC_CTYPE)];
+  if (plc->is_c_locale)
+    /* Implementation for the "C" locale.  */
+    return c_strcasecmp (s1, s2);
+# if HAVE_WINDOWS_LOCALE_T
+  /* Documentation:
+     <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/stricmp-wcsicmp-mbsicmp-stricmp-l-wcsicmp-l-mbsicmp-l>  */
+  return _stricmp_l (s1, s2, plc->system_locale);
+# else
+  /* Implementation for the global locale.  */
+  {
+    int ret;
+#  if HAVE_WORKING_USELOCALE
+    locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
+#  endif
+    ret = strcasecmp (s1, s2);
+#  if HAVE_WORKING_USELOCALE
+    uselocale (saved_locale);
+#  endif
+    return ret;
+  }
+# endif
+
+#else
+
+  unsigned char c1, c2;
+
+  if (s1 == s2)
+    return 0;
+
+  do
+    {
+      c1 = tolower_l ((unsigned char) *s1, locale);
+      c2 = tolower_l ((unsigned char) *s2, locale);
+
+      if (c1 == '\0')
+        break;
+
+      ++s1;
+      ++s2;
+    }
+  while (c1 == c2);
+
+  if (UCHAR_MAX <= INT_MAX)
+    return c1 - c2;
+  else
+    /* On machines where 'char' and 'int' are types of the same size, the
+       difference of two 'unsigned char' values - including the sign bit -
+       doesn't fit in an 'int'.  */
+    return _GL_CMP (c1, c2);
+
+#endif
+}
diff --git a/lib/strings.in.h b/lib/strings.in.h
index 7aa72deeaf..f355e806a2 100644
--- a/lib/strings.in.h
+++ b/lib/strings.in.h
@@ -36,7 +36,7 @@
 #ifndef _@GUARD_PREFIX@_STRINGS_H
 #define _@GUARD_PREFIX@_STRINGS_H
 
-/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*.  */
+/* This file uses _GL_ARG_NONNULL, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*.  */
 #if !_GL_CONFIG_H_INCLUDED
  #error "Please include config.h first."
 #endif
@@ -46,6 +46,16 @@
 # include <stddef.h>
 #endif
 
+#if @GNULIB_STRCASECMP_L@
+/* Get locale_t.  */
+# include <locale.h>
+# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ < 10) \
+      || (defined __APPLE__ && defined __MACH__))
+/* Get the declaration of strcasecmp_l.  */
+#  include <string.h>
+# endif
+#endif
+
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
@@ -110,6 +120,41 @@ _GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character "
 # endif
 #endif
 
+#if @GNULIB_STRCASECMP_L@
+# if @REPLACE_STRCASECMP_L@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef strcasecmp_l
+#   define strcasecmp_l rpl_strcasecmp_l
+#  endif
+_GL_FUNCDECL_RPL (strcasecmp_l, int,
+                  (const char *s1, const char *s2, locale_t locale),
+                  _GL_ARG_NONNULL ((1, 2, 3)));
+_GL_CXXALIAS_RPL (strcasecmp_l, int,
+                  (const char *s1, const char *s2, locale_t locale));
+# else
+#  if !@HAVE_STRCASECMP_L@
+_GL_FUNCDECL_SYS (strcasecmp_l, int,
+                  (const char *s1, const char *s2, locale_t locale),
+                  _GL_ARG_NONNULL ((1, 2, 3)));
+#  endif
+_GL_CXXALIAS_SYS (strcasecmp_l, int,
+                  (const char *s1, const char *s2, locale_t locale));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (strcasecmp_l);
+# endif
+#elif defined GNULIB_POSIXCHECK
+/* strcasecmp_l() does not work with multibyte strings:
+   POSIX says that it operates on "strings", and "string" in POSIX is defined
+   as a sequence of bytes, not of characters.   */
+# undef strcasecmp_l
+# if HAVE_RAW_DECL_STRCASECMP_L
+_GL_WARN_ON_USE (strcasecmp_l, "strcasecmp_l cannot work correctly on "
+                 "character strings in multibyte locales and is unportable - "
+                 "use gnulib module strcasecmp_l for portability");
+# endif
+#endif
+
 #if @GNULIB_STRNCASECMP@
 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
    returning less than, equal to or greater than zero if S1 is
diff --git a/m4/strcasecmp_l.m4 b/m4/strcasecmp_l.m4
new file mode 100644
index 0000000000..c8ef932aaa
--- /dev/null
+++ b/m4/strcasecmp_l.m4
@@ -0,0 +1,34 @@
+# strcasecmp_l.m4
+# serial 1
+dnl Copyright (C) 2009-2025 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.
+dnl This file is offered as-is, without any warranty.
+
+AC_DEFUN([gl_FUNC_STRCASECMP_L],
+[
+  AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
+
+  dnl Persuade glibc <strings.h> to declare strcasecmp_l().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([strcasecmp_l])
+  if test $ac_cv_func_strcasecmp_l = yes; then
+    dnl strcasecmp_l usually has the same bug as strcasecmp.
+    gl_STRCASECMP_WORKS
+    case "$gl_cv_func_strcasecmp_works" in
+      *yes) ;;
+      *) REPLACE_STRCASECMP_L=1 ;;
+    esac
+  else
+    HAVE_STRCASECMP_L=0
+  fi
+])
+
+# Prerequisites of lib/strcasecmp_l.c.
+AC_DEFUN([gl_PREREQ_STRCASECMP_L],
+[
+  AC_REQUIRE([gt_FUNC_USELOCALE])
+  :
+])
diff --git a/m4/strings_h.m4 b/m4/strings_h.m4
index d36ff4ec02..992503779c 100644
--- a/m4/strings_h.m4
+++ b/m4/strings_h.m4
@@ -1,5 +1,5 @@
 # strings_h.m4
-# serial 12
+# serial 13
 dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -29,7 +29,7 @@ AC_DEFUN_ONCE([gl_STRINGS_H]
        <strings.h>.  */
     #include <sys/types.h>
     #include <strings.h>
-    ]], [ffs strcasecmp strncasecmp])
+    ]], [ffs strcasecmp strcasecmp_l strncasecmp])
 ])
 
 # gl_STRINGS_MODULE_INDICATOR([modulename])
@@ -51,6 +51,7 @@ AC_DEFUN([gl_STRINGS_H_REQUIRE_DEFAULTS]
   m4_defun(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS], [
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFS])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASECMP])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASECMP_L])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNCASECMP])
   ])
   m4_require(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS])
@@ -62,8 +63,10 @@ AC_DEFUN([gl_STRINGS_H_DEFAULTS]
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_FFS=1;              AC_SUBST([HAVE_FFS])
   HAVE_STRCASECMP=1;       AC_SUBST([HAVE_STRCASECMP])
+  HAVE_STRCASECMP_L=1;     AC_SUBST([HAVE_STRCASECMP_L])
   HAVE_STRNCASECMP=1;      AC_SUBST([HAVE_STRNCASECMP])
   HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP])
   REPLACE_STRCASECMP=0;    AC_SUBST([REPLACE_STRCASECMP])
+  REPLACE_STRCASECMP_L=0;  AC_SUBST([REPLACE_STRCASECMP_L])
   REPLACE_STRNCASECMP=0;   AC_SUBST([REPLACE_STRNCASECMP])
 ])
diff --git a/modules/strcasecmp_l b/modules/strcasecmp_l
new file mode 100644
index 0000000000..e2b4be7e62
--- /dev/null
+++ b/modules/strcasecmp_l
@@ -0,0 +1,39 @@
+Description:
+Case-insensitive string comparison for unibyte locales.
+
+Files:
+lib/strcasecmp_l.c
+m4/strcasecmp_l.m4
+m4/strcasecmp.m4
+m4/intl-thread-locale.m4
+
+Depends-on:
+strings-h
+locale-h
+extensions
+c-strcasecmp    [test $HAVE_STRCASECMP_L = 0 || test $REPLACE_STRCASECMP_L = 1]
+tolower_l       [test $HAVE_STRCASECMP_L = 0 || test $REPLACE_STRCASECMP_L = 1]
+
+configure.ac:
+gl_FUNC_STRCASECMP_L
+gl_CONDITIONAL([GL_COND_OBJ_STRCASECMP_L],
+               [test $HAVE_STRCASECMP_L = 0 || test $REPLACE_STRCASECMP_L = 1])
+AM_COND_IF([GL_COND_OBJ_STRCASECMP_L], [
+  gl_PREREQ_STRCASECMP_L
+])
+gl_MODULE_INDICATOR([strcasecmp_l])
+gl_STRINGS_MODULE_INDICATOR([strcasecmp_l])
+
+Makefile.am:
+if GL_COND_OBJ_STRCASECMP_L
+lib_SOURCES += strcasecmp_l.c
+endif
+
+Include:
+<strings.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/strings-h b/modules/strings-h
index 2e0f0c1012..f03d16223e 100644
--- a/modules/strings-h
+++ b/modules/strings-h
@@ -34,12 +34,15 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
 	      -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \
 	      -e 's/@''GNULIB_FFS''@/$(GNULIB_FFS)/g' \
 	      -e 's/@''GNULIB_STRCASECMP''@/$(GNULIB_STRCASECMP)/g' \
+	      -e 's/@''GNULIB_STRCASECMP_L''@/$(GNULIB_STRCASECMP_L)/g' \
 	      -e 's/@''GNULIB_STRNCASECMP''@/$(GNULIB_STRNCASECMP)/g' \
 	      -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \
 	      -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \
+	      -e 's|@''HAVE_STRCASECMP_L''@|$(HAVE_STRCASECMP_L)|g' \
 	      -e 's|@''HAVE_STRNCASECMP''@|$(HAVE_STRNCASECMP)|g' \
 	      -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \
 	      -e 's|@''REPLACE_STRCASECMP''@|$(REPLACE_STRCASECMP)|g' \
+	      -e 's|@''REPLACE_STRCASECMP_L''@|$(REPLACE_STRCASECMP_L)|g' \
 	      -e 's|@''REPLACE_STRNCASECMP''@|$(REPLACE_STRNCASECMP)|g' \
 	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
 	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
diff --git a/tests/test-strings-h-c++.cc b/tests/test-strings-h-c++.cc
index 1e872e285b..ce6dcda2ca 100644
--- a/tests/test-strings-h-c++.cc
+++ b/tests/test-strings-h-c++.cc
@@ -28,6 +28,11 @@
 SIGNATURE_CHECK (GNULIB_NAMESPACE::ffs, int, (int));
 #endif
 
+#if GNULIB_TEST_STRCASECMP_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::strcasecmp_l, int,
+                 (const char *, const char *, locale_t));
+#endif
+
 
 int
 main ()
-- 
2.43.0

>From 9b269e666a57079664969c40ef99599e1e98482b Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 16 Feb 2025 22:32:19 +0100
Subject: [PATCH 2/4] strcasecmp_l: Add tests.

* tests/test-strcasecmp_l.c: New file.
* modules/strcasecmp_l-tests: New file.
---
 ChangeLog                  |  4 ++
 modules/strcasecmp_l-tests | 16 +++++++
 tests/test-strcasecmp_l.c  | 88 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 modules/strcasecmp_l-tests
 create mode 100644 tests/test-strcasecmp_l.c

diff --git a/ChangeLog b/ChangeLog
index 0ffa42d3e7..a8731ea5ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-02-16  Bruno Haible  <br...@clisp.org>
 
+	strcasecmp_l: Add tests.
+	* tests/test-strcasecmp_l.c: New file.
+	* modules/strcasecmp_l-tests: New file.
+
 	strcasecmp_l: New module.
 	* lib/strings.in.h: Include <locale.h>.
 	(strcasecmp_l): New declaration.
diff --git a/modules/strcasecmp_l-tests b/modules/strcasecmp_l-tests
new file mode 100644
index 0000000000..b096df6fb8
--- /dev/null
+++ b/modules/strcasecmp_l-tests
@@ -0,0 +1,16 @@
+Files:
+tests/test-strcasecmp_l.c
+tests/signature.h
+tests/macros.h
+m4/musl.m4
+
+Depends-on:
+newlocale
+freelocale
+
+configure.ac:
+gl_MUSL_LIBC
+
+Makefile.am:
+TESTS += test-strcasecmp_l
+check_PROGRAMS += test-strcasecmp_l
diff --git a/tests/test-strcasecmp_l.c b/tests/test-strcasecmp_l.c
new file mode 100644
index 0000000000..6202634c4d
--- /dev/null
+++ b/tests/test-strcasecmp_l.c
@@ -0,0 +1,88 @@
+/* Test of strcasecmp_l() function.
+   Copyright (C) 2020-2025 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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <strings.h>
+#include <locale.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (strcasecmp_l, int, (const char *, const char *, locale_t));
+
+#include <stdio.h>
+
+#include "macros.h"
+
+static void
+test_single_locale_common (locale_t locale)
+{
+  ASSERT (strcasecmp_l ("paragraph", "Paragraph", locale) == 0);
+
+  ASSERT (strcasecmp_l ("paragrapH", "parAgRaph", locale) == 0);
+
+  ASSERT (strcasecmp_l ("paragraph", "paraLyzed", locale) < 0);
+  ASSERT (strcasecmp_l ("paraLyzed", "paragraph", locale) > 0);
+
+  ASSERT (strcasecmp_l ("para", "paragraph", locale) < 0);
+  ASSERT (strcasecmp_l ("paragraph", "para", locale) > 0);
+}
+
+int
+main ()
+{
+  {
+    locale_t locale = newlocale (LC_ALL_MASK, "C", NULL);
+    ASSERT (locale != NULL);
+
+    test_single_locale_common (locale);
+
+    freelocale (locale);
+  }
+#if !MUSL_LIBC /* musl libc has no unibyte locales */
+  {
+# if defined _WIN32 && !defined __CYGWIN__
+    locale_t locale = newlocale (LC_ALL_MASK, "French_France.1252", NULL);
+# else
+    locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.ISO-8859-1", NULL);
+    if (locale == NULL)
+      locale = newlocale (LC_ALL_MASK, "fr_FR.ISO8859-1", NULL);
+# endif
+    if (locale != NULL)
+      {
+        test_single_locale_common (locale);
+
+        /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
+
+        /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
+        /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
+        ASSERT (strcasecmp_l ("Fej\311r", "Fej\351r", locale) == 0);
+        ASSERT (strcasecmp_l ("Fej\351r", "Fej\311r", locale) == 0);
+        ASSERT (strcasecmp_l ("Fejer", "Fej\311r", locale) < 0);
+        ASSERT (strcasecmp_l ("Fej\311r", "Fejer", locale) > 0);
+
+        /* Compare with U+00D7 MULTIPLICATION SIGN */
+        ASSERT (strcasecmp_l ("Fej\311r", "Fej\327", locale) > 0);
+        ASSERT (strcasecmp_l ("Fej\327", "Fej\311r", locale) < 0);
+        ASSERT (strcasecmp_l ("Fej\351r", "Fej\327", locale) > 0);
+        ASSERT (strcasecmp_l ("Fej\327", "Fej\351r", locale) < 0);
+
+        freelocale (locale);
+      }
+  }
+#endif
+
+  return test_exit_status;
+}
-- 
2.43.0

>From b2bf05b12753a6c8905ea4bd9550be2a1da95694 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 16 Feb 2025 22:32:33 +0100
Subject: [PATCH 3/4] strncasecmp_l: New module.

* lib/strings.in.h (strncasecmp_l): New declaration.
* lib/strncasecmp_l.c: New file, based on lib/strncasecmp.c.
* m4/strncasecmp_l.m4: New file.
* m4/strings_h.m4 (gl_STRINGS_H): Test for strncasecmp_l.
(gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRNCASECMP_L.
(gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRNCASECMP_L,
REPLACE_STRNCASECMP_L.
* modules/strings-h (Makefile.am): Substitute GNULIB_STRNCASECMP_L,
HAVE_STRNCASECMP_L, REPLACE_STRNCASECMP_L.
* modules/strncasecmp_l: New file.
* tests/test-strings-h-c++.cc: Check declaration of strncasecmp_l.
* doc/posix-functions/strncasecmp_l.texi: Mention the new module and the
macOS, Solaris, Cygwin bugs.
---
 ChangeLog                              | 17 ++++++
 doc/posix-functions/strncasecmp_l.texi | 16 +++--
 lib/strings.in.h                       | 37 +++++++++++-
 lib/strncasecmp_l.c                    | 84 ++++++++++++++++++++++++++
 m4/strings_h.m4                        |  7 ++-
 m4/strncasecmp_l.m4                    | 34 +++++++++++
 modules/strings-h                      |  3 +
 modules/strncasecmp_l                  | 39 ++++++++++++
 tests/test-strings-h-c++.cc            |  5 ++
 9 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 lib/strncasecmp_l.c
 create mode 100644 m4/strncasecmp_l.m4
 create mode 100644 modules/strncasecmp_l

diff --git a/ChangeLog b/ChangeLog
index a8731ea5ff..aa5f4dd468 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2025-02-16  Bruno Haible  <br...@clisp.org>
+
+	strncasecmp_l: New module.
+	* lib/strings.in.h (strncasecmp_l): New declaration.
+	* lib/strncasecmp_l.c: New file, based on lib/strncasecmp.c.
+	* m4/strncasecmp_l.m4: New file.
+	* m4/strings_h.m4 (gl_STRINGS_H): Test for strncasecmp_l.
+	(gl_STRINGS_H_REQUIRE_DEFAULTS): Initialize GNULIB_STRNCASECMP_L.
+	(gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRNCASECMP_L,
+	REPLACE_STRNCASECMP_L.
+	* modules/strings-h (Makefile.am): Substitute GNULIB_STRNCASECMP_L,
+	HAVE_STRNCASECMP_L, REPLACE_STRNCASECMP_L.
+	* modules/strncasecmp_l: New file.
+	* tests/test-strings-h-c++.cc: Check declaration of strncasecmp_l.
+	* doc/posix-functions/strncasecmp_l.texi: Mention the new module and the
+	macOS, Solaris, Cygwin bugs.
+
 2025-02-16  Bruno Haible  <br...@clisp.org>
 
 	strcasecmp_l: Add tests.
diff --git a/doc/posix-functions/strncasecmp_l.texi b/doc/posix-functions/strncasecmp_l.texi
index bfe8a16426..e39a67e7d2 100644
--- a/doc/posix-functions/strncasecmp_l.texi
+++ b/doc/posix-functions/strncasecmp_l.texi
@@ -4,15 +4,23 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncasecmp_l.html}
 
-Gnulib module: ---
+Gnulib module: strncasecmp_l
+@mindex strncasecmp_l
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many platforms:
+FreeBSD 9.0, NetBSD 10.0, OpenBSD 6.1, Minix 3.3.0, AIX 6.1, HP-UX 11, Solaris 11.3, Cygwin 2.5.x, mingw, MSVC 14, Android 5.1.
+@item
+This function is declared in @code{<string.h>} instead of @code{<strings.h>}
+on some platforms:
+glibc 2.9, macOS 15.
+@item
+This function uses the case mappings of a wrong locale on some platforms:
+Solaris 11.4, Cygwin 3.5.6.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on many platforms:
-FreeBSD 6.0, NetBSD 10.0, OpenBSD 6.0, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 11.3, Cygwin 1.7.x, mingw, MSVC 14, Android 5.1.
 @end itemize
diff --git a/lib/strings.in.h b/lib/strings.in.h
index f355e806a2..40c891d749 100644
--- a/lib/strings.in.h
+++ b/lib/strings.in.h
@@ -46,7 +46,7 @@
 # include <stddef.h>
 #endif
 
-#if @GNULIB_STRCASECMP_L@
+#if @GNULIB_STRCASECMP_L@ || @GNULIB_STRNCASECMP_L@
 /* Get locale_t.  */
 # include <locale.h>
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ < 10) \
@@ -193,6 +193,41 @@ _GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character "
 # endif
 #endif
 
+#if @GNULIB_STRNCASECMP_L@
+# if @REPLACE_STRNCASECMP_L@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef strncasecmp_l
+#   define strncasecmp_l rpl_strncasecmp_l
+#  endif
+_GL_FUNCDECL_RPL (strncasecmp_l, int,
+                  (const char *s1, const char *s2, size_t n, locale_t locale),
+                  _GL_ARG_NONNULL ((1, 2, 4)));
+_GL_CXXALIAS_RPL (strncasecmp_l, int,
+                  (const char *s1, const char *s2, size_t n, locale_t locale));
+# else
+#  if !@HAVE_STRNCASECMP_L@
+_GL_FUNCDECL_SYS (strncasecmp_l, int,
+                  (const char *s1, const char *s2, size_t n, locale_t locale),
+                  _GL_ARG_NONNULL ((1, 2, 4)));
+#  endif
+_GL_CXXALIAS_SYS (strncasecmp_l, int,
+                  (const char *s1, const char *s2, size_t n, locale_t locale));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (strncasecmp_l);
+# endif
+#elif defined GNULIB_POSIXCHECK
+/* strncasecmp_l() does not work with multibyte strings:
+   POSIX says that it operates on "strings", and "string" in POSIX is defined
+   as a sequence of bytes, not of characters.   */
+# undef strncasecmp_l
+# if HAVE_RAW_DECL_STRNCASECMP_L
+_GL_WARN_ON_USE (strncasecmp_l, "strncasecmp_l cannot work correctly on "
+                 "character strings in multibyte locales and is unportable - "
+                 "use gnulib module strncasecmp_l for portability");
+# endif
+#endif
+
 
 #ifdef __cplusplus
 }
diff --git a/lib/strncasecmp_l.c b/lib/strncasecmp_l.c
new file mode 100644
index 0000000000..f20cdc7155
--- /dev/null
+++ b/lib/strncasecmp_l.c
@@ -0,0 +1,84 @@
+/* Case-insensitive string comparison function for unibyte locales.
+   Copyright (C) 1998-2025 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <strings.h>
+
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+
+int
+strncasecmp_l (const char *s1, const char *s2, size_t n, locale_t locale)
+{
+#if GNULIB_defined_locale_t
+
+  struct gl_locale_category_t *plc =
+    &locale->category[gl_log2_lc_mask (LC_CTYPE)];
+  if (plc->is_c_locale)
+    /* Implementation for the "C" locale.  */
+    return c_strncasecmp (s1, s2, n);
+# if HAVE_WINDOWS_LOCALE_T
+  /* Documentation:
+     <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strnicmp-wcsnicmp-mbsnicmp-strnicmp-l-wcsnicmp-l-mbsnicmp-l>  */
+  return _strnicmp_l (s1, s2, n, plc->system_locale);
+# else
+  /* Implementation for the global locale.  */
+  {
+    int ret;
+#  if HAVE_WORKING_USELOCALE
+    locale_t saved_locale = uselocale (LC_GLOBAL_LOCALE);
+#  endif
+    ret = strncasecmp (s1, s2, n);
+#  if HAVE_WORKING_USELOCALE
+    uselocale (saved_locale);
+#  endif
+    return ret;
+  }
+# endif
+
+#else
+
+  unsigned char c1, c2;
+
+  if (s1 == s2 || n == 0)
+    return 0;
+
+  do
+    {
+      c1 = tolower ((unsigned char) *s1);
+      c2 = tolower ((unsigned char) *s2);
+
+      if (--n == 0 || c1 == '\0')
+        break;
+
+      ++s1;
+      ++s2;
+    }
+  while (c1 == c2);
+
+  if (UCHAR_MAX <= INT_MAX)
+    return c1 - c2;
+  else
+    /* On machines where 'char' and 'int' are types of the same size, the
+       difference of two 'unsigned char' values - including the sign bit -
+       doesn't fit in an 'int'.  */
+    return _GL_CMP (c1, c2);
+
+#endif
+}
diff --git a/m4/strings_h.m4 b/m4/strings_h.m4
index 992503779c..18f30d4aed 100644
--- a/m4/strings_h.m4
+++ b/m4/strings_h.m4
@@ -1,5 +1,5 @@
 # strings_h.m4
-# serial 13
+# serial 14
 dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -29,7 +29,7 @@ AC_DEFUN_ONCE([gl_STRINGS_H]
        <strings.h>.  */
     #include <sys/types.h>
     #include <strings.h>
-    ]], [ffs strcasecmp strcasecmp_l strncasecmp])
+    ]], [ffs strcasecmp strcasecmp_l strncasecmp strncasecmp_l])
 ])
 
 # gl_STRINGS_MODULE_INDICATOR([modulename])
@@ -53,6 +53,7 @@ AC_DEFUN([gl_STRINGS_H_REQUIRE_DEFAULTS]
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASECMP])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASECMP_L])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNCASECMP])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNCASECMP_L])
   ])
   m4_require(GL_MODULE_INDICATOR_PREFIX[_STRINGS_H_MODULE_INDICATOR_DEFAULTS])
   AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
@@ -65,8 +66,10 @@ AC_DEFUN([gl_STRINGS_H_DEFAULTS]
   HAVE_STRCASECMP=1;       AC_SUBST([HAVE_STRCASECMP])
   HAVE_STRCASECMP_L=1;     AC_SUBST([HAVE_STRCASECMP_L])
   HAVE_STRNCASECMP=1;      AC_SUBST([HAVE_STRNCASECMP])
+  HAVE_STRNCASECMP_L=1;    AC_SUBST([HAVE_STRNCASECMP_L])
   HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP])
   REPLACE_STRCASECMP=0;    AC_SUBST([REPLACE_STRCASECMP])
   REPLACE_STRCASECMP_L=0;  AC_SUBST([REPLACE_STRCASECMP_L])
   REPLACE_STRNCASECMP=0;   AC_SUBST([REPLACE_STRNCASECMP])
+  REPLACE_STRNCASECMP_L=0; AC_SUBST([REPLACE_STRNCASECMP_L])
 ])
diff --git a/m4/strncasecmp_l.m4 b/m4/strncasecmp_l.m4
new file mode 100644
index 0000000000..efdc90cf06
--- /dev/null
+++ b/m4/strncasecmp_l.m4
@@ -0,0 +1,34 @@
+# strncasecmp_l.m4
+# serial 1
+dnl Copyright (C) 2009-2025 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.
+dnl This file is offered as-is, without any warranty.
+
+AC_DEFUN([gl_FUNC_STRNCASECMP_L],
+[
+  AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
+
+  dnl Persuade glibc <strings.h> to declare strncasecmp_l().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([strncasecmp_l])
+  if test $ac_cv_func_strncasecmp_l = yes; then
+    dnl strncasecmp_l usually has the same bug as strncasecmp.
+    gl_STRCASECMP_WORKS
+    case "$gl_cv_func_strcasecmp_works" in
+      *yes) ;;
+      *) REPLACE_STRNCASECMP_L=1 ;;
+    esac
+  else
+    HAVE_STRNCASECMP_L=0
+  fi
+])
+
+# Prerequisites of lib/strncasecmp_l.c.
+AC_DEFUN([gl_PREREQ_STRNCASECMP_L],
+[
+  AC_REQUIRE([gt_FUNC_USELOCALE])
+  :
+])
diff --git a/modules/strings-h b/modules/strings-h
index f03d16223e..ae047ec155 100644
--- a/modules/strings-h
+++ b/modules/strings-h
@@ -36,14 +36,17 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
 	      -e 's/@''GNULIB_STRCASECMP''@/$(GNULIB_STRCASECMP)/g' \
 	      -e 's/@''GNULIB_STRCASECMP_L''@/$(GNULIB_STRCASECMP_L)/g' \
 	      -e 's/@''GNULIB_STRNCASECMP''@/$(GNULIB_STRNCASECMP)/g' \
+	      -e 's/@''GNULIB_STRNCASECMP_L''@/$(GNULIB_STRNCASECMP_L)/g' \
 	      -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \
 	      -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \
 	      -e 's|@''HAVE_STRCASECMP_L''@|$(HAVE_STRCASECMP_L)|g' \
 	      -e 's|@''HAVE_STRNCASECMP''@|$(HAVE_STRNCASECMP)|g' \
+	      -e 's|@''HAVE_STRNCASECMP_L''@|$(HAVE_STRNCASECMP_L)|g' \
 	      -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \
 	      -e 's|@''REPLACE_STRCASECMP''@|$(REPLACE_STRCASECMP)|g' \
 	      -e 's|@''REPLACE_STRCASECMP_L''@|$(REPLACE_STRCASECMP_L)|g' \
 	      -e 's|@''REPLACE_STRNCASECMP''@|$(REPLACE_STRNCASECMP)|g' \
+	      -e 's|@''REPLACE_STRNCASECMP_L''@|$(REPLACE_STRNCASECMP_L)|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/strncasecmp_l b/modules/strncasecmp_l
new file mode 100644
index 0000000000..154bd44de1
--- /dev/null
+++ b/modules/strncasecmp_l
@@ -0,0 +1,39 @@
+Description:
+Case-insensitive string comparison for unibyte locales.
+
+Files:
+lib/strncasecmp_l.c
+m4/strncasecmp_l.m4
+m4/strcasecmp.m4
+m4/intl-thread-locale.m4
+
+Depends-on:
+strings-h
+locale-h
+extensions
+c-strncasecmp   [test $HAVE_STRNCASECMP_L = 0 || test $REPLACE_STRNCASECMP_L = 1]
+tolower_l       [test $HAVE_STRNCASECMP_L = 0 || test $REPLACE_STRNCASECMP_L = 1]
+
+configure.ac:
+gl_FUNC_STRNCASECMP_L
+gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP_L],
+               [test $HAVE_STRNCASECMP_L = 0 || test $REPLACE_STRNCASECMP_L = 1])
+AM_COND_IF([GL_COND_OBJ_STRNCASECMP_L], [
+  gl_PREREQ_STRNCASECMP_L
+])
+gl_MODULE_INDICATOR([strncasecmp_l])
+gl_STRINGS_MODULE_INDICATOR([strncasecmp_l])
+
+Makefile.am:
+if GL_COND_OBJ_STRNCASECMP_L
+lib_SOURCES += strncasecmp_l.c
+endif
+
+Include:
+<strings.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/tests/test-strings-h-c++.cc b/tests/test-strings-h-c++.cc
index ce6dcda2ca..4f6d505db0 100644
--- a/tests/test-strings-h-c++.cc
+++ b/tests/test-strings-h-c++.cc
@@ -33,6 +33,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::strcasecmp_l, int,
                  (const char *, const char *, locale_t));
 #endif
 
+#if GNULIB_TEST_STRNCASECMP_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::strncasecmp_l, int,
+                 (const char *, const char *, size_t, locale_t));
+#endif
+
 
 int
 main ()
-- 
2.43.0

>From bc89c9cf1efebd9bc7b7524e3f6471e1c367f706 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 16 Feb 2025 22:32:37 +0100
Subject: [PATCH 4/4] strncasecmp_l: Add tests.

* tests/test-strncasecmp_l.c: New file.
* modules/strncasecmp_l-tests: New file.
---
 ChangeLog                   |  4 ++
 modules/strncasecmp_l-tests | 16 +++++++
 tests/test-strncasecmp_l.c  | 88 +++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 modules/strncasecmp_l-tests
 create mode 100644 tests/test-strncasecmp_l.c

diff --git a/ChangeLog b/ChangeLog
index aa5f4dd468..21c1b8a491 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-02-16  Bruno Haible  <br...@clisp.org>
 
+	strncasecmp_l: Add tests.
+	* tests/test-strncasecmp_l.c: New file.
+	* modules/strncasecmp_l-tests: New file.
+
 	strncasecmp_l: New module.
 	* lib/strings.in.h (strncasecmp_l): New declaration.
 	* lib/strncasecmp_l.c: New file, based on lib/strncasecmp.c.
diff --git a/modules/strncasecmp_l-tests b/modules/strncasecmp_l-tests
new file mode 100644
index 0000000000..909d11701e
--- /dev/null
+++ b/modules/strncasecmp_l-tests
@@ -0,0 +1,16 @@
+Files:
+tests/test-strncasecmp_l.c
+tests/signature.h
+tests/macros.h
+m4/musl.m4
+
+Depends-on:
+newlocale
+freelocale
+
+configure.ac:
+gl_MUSL_LIBC
+
+Makefile.am:
+TESTS += test-strncasecmp_l
+check_PROGRAMS += test-strncasecmp_l
diff --git a/tests/test-strncasecmp_l.c b/tests/test-strncasecmp_l.c
new file mode 100644
index 0000000000..a043539fcd
--- /dev/null
+++ b/tests/test-strncasecmp_l.c
@@ -0,0 +1,88 @@
+/* Test of strncasecmp_l() function.
+   Copyright (C) 2020-2025 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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <strings.h>
+#include <locale.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (strncasecmp_l, int, (const char *, const char *, size_t, locale_t));
+
+#include <stdio.h>
+
+#include "macros.h"
+
+static void
+test_single_locale_common (locale_t locale)
+{
+  ASSERT (strncasecmp_l ("paragraph", "Paragraph", 9, locale) == 0);
+
+  ASSERT (strncasecmp_l ("paragrapH", "parAgRaph", 9, locale) == 0);
+
+  ASSERT (strncasecmp_l ("paragraph", "paraLyzed", 9, locale) < 0);
+  ASSERT (strncasecmp_l ("paraLyzed", "paragraph", 9, locale) > 0);
+
+  ASSERT (strncasecmp_l ("para", "paragraph", 9, locale) < 0);
+  ASSERT (strncasecmp_l ("paragraph", "para", 9, locale) > 0);
+}
+
+int
+main ()
+{
+  {
+    locale_t locale = newlocale (LC_ALL_MASK, "C", NULL);
+    ASSERT (locale != NULL);
+
+    test_single_locale_common (locale);
+
+    freelocale (locale);
+  }
+#if !MUSL_LIBC /* musl libc has no unibyte locales */
+  {
+# if defined _WIN32 && !defined __CYGWIN__
+    locale_t locale = newlocale (LC_ALL_MASK, "French_France.1252", NULL);
+# else
+    locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.ISO-8859-1", NULL);
+    if (locale == NULL)
+      locale = newlocale (LC_ALL_MASK, "fr_FR.ISO8859-1", NULL);
+# endif
+    if (locale != NULL)
+      {
+        test_single_locale_common (locale);
+
+        /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
+
+        /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
+        /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
+        ASSERT (strncasecmp_l ("Fej\311r", "Fej\351r", 5, locale) == 0);
+        ASSERT (strncasecmp_l ("Fej\351r", "Fej\311r", 5, locale) == 0);
+        ASSERT (strncasecmp_l ("Fejer", "Fej\311r", 5, locale) < 0);
+        ASSERT (strncasecmp_l ("Fej\311r", "Fejer", 5, locale) > 0);
+
+        /* Compare with U+00D7 MULTIPLICATION SIGN */
+        ASSERT (strncasecmp_l ("Fej\311r", "Fej\327", 5, locale) > 0);
+        ASSERT (strncasecmp_l ("Fej\327", "Fej\311r", 5, locale) < 0);
+        ASSERT (strncasecmp_l ("Fej\351r", "Fej\327", 5, locale) > 0);
+        ASSERT (strncasecmp_l ("Fej\327", "Fej\351r", 5, locale) < 0);
+
+        freelocale (locale);
+      }
+  }
+#endif
+
+  return test_exit_status;
+}
-- 
2.43.0

Reply via email to