]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
string-h: Support multiple gnulib-tool invocations in the same package.
authorBruno Haible <bruno@clisp.org>
Tue, 28 Apr 2026 23:47:39 +0000 (01:47 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 28 Apr 2026 23:47:39 +0000 (01:47 +0200)
* lib/string.in.h (GNULIB_defined_memeq, GNULIB_defined_streq,
GNULIB_defined_strnul): New macros.

ChangeLog
lib/string.in.h

index c0ea7c1dde3203486b8f5bdfd0ff6981630b7ee0..0ef64fe22caa829169315fe959bcca41e22a51ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-04-28  Bruno Haible  <bruno@clisp.org>
+
+       string-h: Support multiple gnulib-tool invocations in the same package.
+       * lib/string.in.h (GNULIB_defined_memeq, GNULIB_defined_streq,
+       GNULIB_defined_strnul): New macros.
+
 2026-04-28  Bruno Haible  <bruno@clisp.org>
 
        stdbit-h: Support multiple gnulib-tool invocations in the same package.
index f04bbc6514ae3bd2ef3f94e66e7eed345247361d..3fa3e943ebea3c50a4ae09a4832250ef33380bfc 100644 (file)
@@ -420,16 +420,19 @@ _GL_WARN_ON_USE_CXX (memchr,
 
 /* Are S1 and S2, of size N, bytewise equal?  */
 #if @GNULIB_MEMEQ@ && !@HAVE_DECL_MEMEQ@
-# ifdef __cplusplus
+# if !GNULIB_defined_memeq
+#  ifdef __cplusplus
 extern "C" {
-# endif
+#  endif
 _GL_MEMEQ_INLINE bool
 memeq (void const *__s1, void const *__s2, size_t __n)
 {
   return !memcmp (__s1, __s2, __n);
 }
-# ifdef __cplusplus
+#  ifdef __cplusplus
 }
+#  endif
+#  define GNULIB_defined_memeq 1
 # endif
 #endif
 
@@ -805,16 +808,19 @@ _GL_CXXALIASWARN (strdup);
 
 /* Are strings S1 and S2 equal?  */
 #if @GNULIB_STREQ@ && !@HAVE_DECL_STREQ@
-# ifdef __cplusplus
+# if !GNULIB_defined_streq
+#  ifdef __cplusplus
 extern "C" {
-# endif
+#  endif
 _GL_STREQ_INLINE bool
 streq (char const *__s1, char const *__s2)
 {
   return !strcmp (__s1, __s2);
 }
-# ifdef __cplusplus
+#  ifdef __cplusplus
 }
+#  endif
+#  define GNULIB_defined_streq 1
 # endif
 #endif
 
@@ -1245,9 +1251,10 @@ _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
      string + strlen (string)
    or to
      strchr (string, '\0').  */
-# ifdef __cplusplus
+# if !GNULIB_defined_strnul
+#  ifdef __cplusplus
 extern "C" {
-# endif
+#  endif
 _GL_STRNUL_INLINE const char *_gl_strnul (const char *string)
      _GL_ATTRIBUTE_PURE
      _GL_ARG_NONNULL ((1));
@@ -1261,10 +1268,10 @@ _GL_STRNUL_INLINE const char *_gl_strnul (const char *string)
      option '-fno-builtin' is in use.  */
   return string + strlen (string);
 }
-# ifdef __cplusplus
+#  ifdef __cplusplus
 }
-# endif
-# ifdef __cplusplus
+#  endif
+#  ifdef __cplusplus
 _GL_BEGIN_NAMESPACE
 template <typename T> T strnul (T);
 template <> inline const char *strnul<const char *> (const char *s)
@@ -1272,11 +1279,11 @@ template <> inline const char *strnul<const char *> (const char *s)
 template <> inline       char *strnul<      char *> (      char *s)
 { return const_cast<char *>(_gl_strnul (s)); }
 _GL_END_NAMESPACE
-# else
-#  if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __cplusplus) \
-      || (defined __clang__ && __clang_major__ >= 3) \
-      || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) \
-      || (__STDC_VERSION__ >= 201112L && !defined __GNUC__)
+#  else
+#   if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __cplusplus) \
+       || (defined __clang__ && __clang_major__ >= 3) \
+       || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) \
+       || (__STDC_VERSION__ >= 201112L && !defined __GNUC__)
 /* The compiler supports _Generic from ISO C11.  */
 /* Since in C (but not in C++!), any function that accepts a '[const] char *'
    also accepts a '[const] void *' as argument, we make sure that the function-
@@ -1284,14 +1291,16 @@ _GL_END_NAMESPACE
      char *, void *             -> void *
      const char *, const void * -> const void *
    This mapping is done through the conditional expression.  */
-#   define strnul(s) \
-      _Generic (1 ? (s) : (void *) 99, \
-                void *       : (char *) _gl_strnul (s), \
-                const void * : _gl_strnul (s))
-#  else
-#   define strnul(s) \
-      ((char *) _gl_strnul (s))
+#    define strnul(s) \
+       _Generic (1 ? (s) : (void *) 99, \
+                 void *       : (char *) _gl_strnul (s), \
+                 const void * : _gl_strnul (s))
+#   else
+#    define strnul(s) \
+       ((char *) _gl_strnul (s))
+#   endif
 #  endif
+#  define GNULIB_defined_strnul 1
 # endif
 #endif