Work even if the system <string.h> declares memeq and streq.
Current standards allow systems to do that,
and we hope future systems will do it.
* lib/string.in.h (memeq) [HAVE_DECL_MEMEQ]: Do not define.
(streq) [HAVE_DECL_STREQ]: Do not define.
* m4/string_h.m4 (gl_STRING_H_DEFAULTS): Default HAVE_DECL_MEMEQ,
HAVE_DECL_STREQ.
* modules/string-h (string-h):
Substitute HAVE_DECL_MEMEQ, HAVE_DECL_STREQ.
* modules/stringeq (configure.ac):
Define HAVE_DECL_MEMEQ, HAVE_DECL_STREQ.
---
 ChangeLog        | 15 +++++++++++++++
 lib/string.in.h  |  4 ++--
 m4/string_h.m4   |  2 ++
 modules/string-h |  2 ++
 modules/stringeq |  3 +++
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0be6c8855c..908c46cbd1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2025-09-17  Paul Eggert  <egg...@cs.ucla.edu>
+
+       stringeq: port to platforms declaring memeq, streq
+       Work even if the system <string.h> declares memeq and streq.
+       Current standards allow systems to do that,
+       and we hope future systems will do it.
+       * lib/string.in.h (memeq) [HAVE_DECL_MEMEQ]: Do not define.
+       (streq) [HAVE_DECL_STREQ]: Do not define.
+       * m4/string_h.m4 (gl_STRING_H_DEFAULTS): Default HAVE_DECL_MEMEQ,
+       HAVE_DECL_STREQ.
+       * modules/string-h (string-h):
+       Substitute HAVE_DECL_MEMEQ, HAVE_DECL_STREQ.
+       * modules/stringeq (configure.ac):
+       Define HAVE_DECL_MEMEQ, HAVE_DECL_STREQ.
+
 2025-09-17  Bruno Haible  <br...@clisp.org>
 
        gen-uni-tables: Fix module description (left-over from 2025-05-11).
diff --git a/lib/string.in.h b/lib/string.in.h
index c42a77cd5f..2c941d08f4 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -416,7 +416,7 @@ _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs 
- "
 #endif
 
 /* Are S1 and S2, of size N, bytewise equal?  */
-#if @GNULIB_STRINGEQ@
+#if @GNULIB_STRINGEQ@ && !@HAVE_DECL_MEMEQ@
 _GL_STRING_INLINE bool
 memeq (void const *__s1, void const *__s2, size_t __n)
 {
@@ -805,7 +805,7 @@ _GL_CXXALIASWARN (strdup);
 #endif
 
 /* Are strings S1 and S2 equal?  */
-#if @GNULIB_STRINGEQ@
+#if @GNULIB_STRINGEQ@ && !@HAVE_DECL_STREQ@
 _GL_STRING_INLINE bool
 streq (char const *__s1, char const *__s2)
 {
diff --git a/m4/string_h.m4 b/m4/string_h.m4
index d5dd315729..b5324e3a37 100644
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -115,6 +115,7 @@ AC_DEFUN([gl_STRING_H_DEFAULTS],
   HAVE_EXPLICIT_BZERO=1;        AC_SUBST([HAVE_EXPLICIT_BZERO])
   HAVE_FFSL=1;                  AC_SUBST([HAVE_FFSL])
   HAVE_FFSLL=1;                 AC_SUBST([HAVE_FFSLL])
+  HAVE_DECL_MEMEQ=0;            AC_SUBST([HAVE_DECL_MEMEQ])
   HAVE_DECL_MEMMEM=1;           AC_SUBST([HAVE_DECL_MEMMEM])
   HAVE_MEMPCPY=1;               AC_SUBST([HAVE_MEMPCPY])
   HAVE_MEMSET_EXPLICIT=1;       AC_SUBST([HAVE_MEMSET_EXPLICIT])
@@ -124,6 +125,7 @@ AC_DEFUN([gl_STRING_H_DEFAULTS],
   HAVE_STPNCPY=1;               AC_SUBST([HAVE_STPNCPY])
   HAVE_STRCHRNUL=1;             AC_SUBST([HAVE_STRCHRNUL])
   HAVE_DECL_STRDUP=1;           AC_SUBST([HAVE_DECL_STRDUP])
+  HAVE_DECL_STREQ=0;            AC_SUBST([HAVE_DECL_STREQ])
   HAVE_DECL_STRNDUP=1;          AC_SUBST([HAVE_DECL_STRNDUP])
   HAVE_DECL_STRNLEN=1;          AC_SUBST([HAVE_DECL_STRNLEN])
   HAVE_STRPBRK=1;               AC_SUBST([HAVE_STRPBRK])
diff --git a/modules/string-h b/modules/string-h
index 852d94d1c5..90ed663ae8 100644
--- a/modules/string-h
+++ b/modules/string-h
@@ -91,6 +91,7 @@ string.h: string.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \
              -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \
              -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \
+             -e 's|@''HAVE_DECL_MEMEQ''@|$(HAVE_DECL_MEMEQ)|g' \
              -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
              -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
              -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
@@ -100,6 +101,7 @@ string.h: string.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \
              -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \
              -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \
+             -e 's|@''HAVE_DECL_STREQ''@|$(HAVE_DECL_STREQ)|g' \
              -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \
              -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \
              -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \
diff --git a/modules/stringeq b/modules/stringeq
index fb620cf16d..bfc387db49 100644
--- a/modules/stringeq
+++ b/modules/stringeq
@@ -9,6 +9,9 @@ bool
 string-h
 
 configure.ac:
+AC_CHECK_DECLS_ONCE([memeq, streq])
+test $ac_cv_have_decl_memeq = no || HAVE_DECL_MEMEQ=1
+test $ac_cv_have_decl_streq = no || HAVE_DECL_STREQ=1
 gl_STRING_MODULE_INDICATOR([stringeq])
 
 Makefile.am:
-- 
2.48.1


Reply via email to