]> Savannah Git Hosting - gnulib.git/commitdiff
strncasecmp: Work around Solaris, Cygwin bug.
authorBruno Haible <bruno@clisp.org>
Sun, 16 Feb 2025 17:22:31 +0000 (18:22 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 16 Feb 2025 17:22:31 +0000 (18:22 +0100)
* lib/strings.in.h (strncasecmp): Consider REPLACE_STRNCASECMP. Use the
usual idioms.
* m4/strings_h.m4 (gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRNCASECMP,
REPLACE_STRNCASECMP.
* m4/strncasecmp.m4 (gl_FUNC_STRNCASECMP): Invoke gl_STRNCASECMP_WORKS.
Set REPLACE_STRNCASECMP. Assume that HAVE_STRNCASECMP is initialized.
* modules/strncasecmp (Files): Add m4/strcasecmp.m4.
(configure.ac): Consider REPLACE_STRNCASECMP.
* modules/strings-h (Makefile.am): Substitute HAVE_STRNCASECMP,
REPLACE_STRNCASECMP.
* doc/posix-functions/strncasecmp.texi: Mention the Solaris, Cygwin bug.

ChangeLog
doc/posix-functions/strncasecmp.texi
lib/strings.in.h
m4/strings_h.m4
m4/strncasecmp.m4
modules/strings-h
modules/strncasecmp

index 052ec74b9dcd946faf8ebf7406a6b3efb70d0653..e73bdd78042c8651f985de5d707083742976df24 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2025-02-16  Bruno Haible  <bruno@clisp.org>
+
+       strncasecmp: Work around Solaris, Cygwin bug.
+       * lib/strings.in.h (strncasecmp): Consider REPLACE_STRNCASECMP. Use the
+       usual idioms.
+       * m4/strings_h.m4 (gl_STRINGS_H_DEFAULTS): Initialize HAVE_STRNCASECMP,
+       REPLACE_STRNCASECMP.
+       * m4/strncasecmp.m4 (gl_FUNC_STRNCASECMP): Invoke gl_STRNCASECMP_WORKS.
+       Set REPLACE_STRNCASECMP. Assume that HAVE_STRNCASECMP is initialized.
+       * modules/strncasecmp (Files): Add m4/strcasecmp.m4.
+       (configure.ac): Consider REPLACE_STRNCASECMP.
+       * modules/strings-h (Makefile.am): Substitute HAVE_STRNCASECMP,
+       REPLACE_STRNCASECMP.
+       * doc/posix-functions/strncasecmp.texi: Mention the Solaris, Cygwin bug.
+
 2025-02-16  Bruno Haible  <bruno@clisp.org>
 
        strcasecmp: Add tests.
index 1fc9e0307a920f5d49dd7b4c3366c3686a8afef6..b52cedb4f3501c7efb3d13b1c303274e1a64b356 100644 (file)
@@ -12,6 +12,11 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 MSVC 14.
+@item
+This function uses the case mappings of a wrong locale on some platforms:
+Solaris 11.4,
+@c https://sourceware.org/pipermail/cygwin/2025-February/257347.html
+Cygwin 3.5.6.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index b356115181f10836cd217d8ce3335a0eb6997618..12a9c40a7da72f6e07862dee2e58dbae8bce216e 100644 (file)
@@ -77,23 +77,23 @@ _GL_WARN_ON_USE (ffs, "ffs is not portable - use the ffs module");
    greater than zero if S1 is lexicographically less than, equal to or greater
    than S2.
    Note: This function does not work in multibyte locales.  */
-# if @REPLACE_STRCASECMP@
+# if @REPLACE_STRNCASECMP@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#   undef strcasecmp
-#   define strcasecmp rpl_strcasecmp
+#   undef strncasecmp
+#   define strncasecmp rpl_strncasecmp
 #  endif
-_GL_FUNCDECL_RPL (strcasecmp, int, (const char *, const char *),
-                                   _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (strcasecmp, int, (const char *, const char *));
+_GL_FUNCDECL_RPL (strncasecmp, int, (const char *, const char *, size_t),
+                                    _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (strncasecmp, int, (const char *, const char *, size_t));
 # else
-#  if !@HAVE_STRCASECMP@
-_GL_FUNCDECL_SYS (strcasecmp, int, (const char *, const char *),
-                                   _GL_ARG_NONNULL ((1, 2)));
+#  if !@HAVE_STRNCASECMP@
+_GL_FUNCDECL_SYS (strncasecmp, int, (const char *, const char *, size_t),
+                                    _GL_ARG_NONNULL ((1, 2)));
 #  endif
-_GL_CXXALIAS_SYS (strcasecmp, int, (const char *, const char *));
+_GL_CXXALIAS_SYS (strncasecmp, int, (const char *, const char *, size_t));
 # endif
 # if __GLIBC__ >= 2
-_GL_CXXALIASWARN (strcasecmp);
+_GL_CXXALIASWARN (strncasecmp);
 # endif
 #elif defined GNULIB_POSIXCHECK
 /* strcasecmp() does not work with multibyte strings:
@@ -126,7 +126,7 @@ extern int strncasecmp (char const *s1, char const *s2, size_t n)
 # undef strncasecmp
 # if HAVE_RAW_DECL_STRNCASECMP
 _GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character "
-                 "strings in multibyte locales - "
+                 "strings in multibyte locales and is unportable - "
                  "use mbsncasecmp or mbspcasecmp if you care about "
                  "internationalization, or use c_strncasecmp "
                  "(gnulib module c-strncasecmp) if you want a locale "
index b88e1105fbd4c83be43d067edacd0a881941435f..f635575012518e9714281deeb2caa4b8531e9a75 100644 (file)
@@ -1,5 +1,5 @@
 # strings_h.m4
-# serial 11
+# serial 12
 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,
@@ -62,6 +62,8 @@ 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_STRNCASECMP=1;      AC_SUBST([HAVE_STRNCASECMP])
   HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP])
   REPLACE_STRCASECMP=1;    AC_SUBST([REPLACE_STRCASECMP])
+  REPLACE_STRNCASECMP=1;   AC_SUBST([REPLACE_STRNCASECMP])
 ])
index d27a4a0c5ec72c84577b06e9401a0e33baa2ae22..c7c8b240360a5c0934a558e20900b19ae13c293e 100644 (file)
@@ -1,5 +1,5 @@
 # strncasecmp.m4
-# serial 1
+# serial 2
 dnl Copyright (C) 2002-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,
@@ -11,7 +11,12 @@ AC_DEFUN([gl_FUNC_STRNCASECMP],
   AC_REQUIRE([gl_STRINGS_H_DEFAULTS])
   AC_CHECK_FUNCS([strncasecmp])
   if test $ac_cv_func_strncasecmp = yes; then
-    HAVE_STRNCASECMP=1
+    dnl Assume that strncasecmp and strcasecmp share the same bugs.
+    gl_STRCASECMP_WORKS
+    case "$gl_cv_func_strcasecmp_works" in
+      *yes) ;;
+      *) REPLACE_STRNCASECMP=1 ;;
+    esac
   else
     HAVE_STRNCASECMP=0
   fi
index 5c6c6736c291d7de1cb92e8782d26fa07ed3b669..2e0f0c10123593b61c84592fc08f2bee4a421bbc 100644 (file)
@@ -37,8 +37,10 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
              -e 's/@''GNULIB_STRNCASECMP''@/$(GNULIB_STRNCASECMP)/g' \
              -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \
              -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|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_STRNCASECMP''@|$(REPLACE_STRNCASECMP)|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 5fca265bad07655b9d8f3b0f7fb409cc36d3e0c9..816cd0fae67a43134fc2b4cc68d58bf5f404da83 100644 (file)
@@ -4,13 +4,15 @@ Case-insensitive string comparison function for unibyte locales.
 Files:
 lib/strncasecmp.c
 m4/strncasecmp.m4
+m4/strcasecmp.m4
 
 Depends-on:
 strings-h
 
 configure.ac:
 gl_FUNC_STRNCASECMP
-gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP], [test $HAVE_STRNCASECMP = 0])
+gl_CONDITIONAL([GL_COND_OBJ_STRNCASECMP],
+               [test $HAVE_STRNCASECMP = 0 || test $REPLACE_STRNCASECMP = 1])
 AM_COND_IF([GL_COND_OBJ_STRNCASECMP], [
   gl_PREREQ_STRNCASECMP
 ])