[glibc] string: Declare Issue 8 functions for POSIX.1-2024 [BZ #34466]

Adhemerval Zanella via Glibc-cvs <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7820b97b7aa84cd555fa2e8f34a6c85565a76094

commit 7820b97b7aa84cd555fa2e8f34a6c85565a76094
Author: Matthias Goergens <[email protected]>
Date:   Wed Aug 5 16:02:13 2026 +0800

    string: Declare Issue 8 functions for POSIX.1-2024 [BZ #34466]
    
    POSIX.1-2024 requires memmem, strlcpy, and strlcat in <string.h>, and
    wcslcpy and wcslcat in <wchar.h>. Expose these declarations and their
    fortified wrappers under __USE_XOPEN2K24 as well as __USE_MISC. Keep
    mempcpy restricted to __USE_MISC.
    
    Add declaration tests for POSIX and X/Open Issue 8 modes, including
    fortified headers.
    
    Signed-off-by: Matthias Goergens <[email protected]>
    Reviewed-by: DJ Delorie <[email protected]>

Diff:
---
 string/Makefile                       |  6 +++++
 string/bits/string_fortified.h        |  4 ++--
 string/string.h                       |  6 +++--
 string/tst-string-posix2024-fortify.c |  6 +++++
 string/tst-string-posix2024-main.c    | 45 +++++++++++++++++++++++++++++++++++
 string/tst-string-posix2024.c         |  5 ++++
 string/tst-string-xopen2024.c         |  5 ++++
 wcsmbs/Makefile                       |  5 ++++
 wcsmbs/bits/wchar2-decl.h             |  4 ++--
 wcsmbs/bits/wchar2.h                  |  4 ++--
 wcsmbs/tst-wchar-posix2024-fortify.c  |  6 +++++
 wcsmbs/tst-wchar-posix2024-main.c     | 41 +++++++++++++++++++++++++++++++
 wcsmbs/tst-wchar-posix2024.c          |  5 ++++
 wcsmbs/tst-wchar-xopen2024.c          |  5 ++++
 wcsmbs/wchar.h                        |  2 +-
 15 files changed, 140 insertions(+), 9 deletions(-)

diff --git a/string/Makefile b/string/Makefile
index aa0b0c2f57..503d32e037 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -203,6 +203,9 @@ tests := \
   tst-memmove-overflow \
   tst-strerror-fail \
   tst-strfry \
+  tst-string-posix2024 \
+  tst-string-posix2024-fortify \
+  tst-string-xopen2024 \
   tst-strlcat \
   tst-strlcat2 \
   tst-strlcpy \
@@ -218,6 +221,9 @@ tests := \
   tst-xmemset-opt \
 # tests
 
+CPPFLAGS-tst-string-posix2024-fortify.c += \
+  $(no-fortify-source) -D_FORTIFY_SOURCE=2
+
 tests-static-internal := \
   test-memswap \
 # tests-static-internal
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h
index f1f597ec78..ae97bb5544 100644
--- a/string/bits/string_fortified.h
+++ b/string/bits/string_fortified.h
@@ -162,7 +162,7 @@ __NTH (strncat (__fortify_clang_overload_arg (char *, __restrict, __dest),
 				  __glibc_objsize (__dest));
 }
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 extern size_t __strlcpy_chk (char *__dest, const char *__src, size_t __n,
 			     size_t __destlen) __THROW;
 extern size_t __REDIRECT_NTH (__strlcpy_alias,
@@ -197,6 +197,6 @@ __NTH (strlcat (__fortify_clang_overload_arg (char *, __restrict, __dest),
     return __strlcat_chk (__dest, __src, __n, __glibc_objsize (__dest));
   return __strlcat_alias (__dest, __src, __n);
 }
-#endif /* __USE_MISC */
+#endif /* __USE_MISC || __USE_XOPEN2K24 */
 
 #endif /* bits/string_fortified.h */
diff --git a/string/string.h b/string/string.h
index 743395b3e3..15959356a2 100644
--- a/string/string.h
+++ b/string/string.h
@@ -414,7 +414,7 @@ extern char *strcasestr (const char *__haystack, const char *__needle)
 # endif
 #endif
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 /* Find the first occurrence of NEEDLE in HAYSTACK.
    NEEDLE is NEEDLELEN bytes long;
    HAYSTACK is HAYSTACKLEN bytes long.  */
@@ -423,7 +423,9 @@ extern void *memmem (const void *__haystack, size_t __haystacklen,
      __THROW __attribute_pure__ __nonnull ((1, 3))
     __attr_access ((__read_only__, 1, 2))
     __attr_access ((__read_only__, 3, 4));
+#endif
 
+#ifdef __USE_MISC
 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
    last written byte.  */
 extern void *__mempcpy (void *__restrict __dest,
@@ -533,7 +535,7 @@ extern char *stpncpy (char *__restrict __dest,
      __THROW __nonnull ((1, 2));
 #endif
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 /* Copy at most N - 1 characters from SRC to DEST.  */
 extern size_t strlcpy (char *__restrict __dest,
 		       const char *__restrict __src, size_t __n)
diff --git a/string/tst-string-posix2024-fortify.c b/string/tst-string-posix2024-fortify.c
new file mode 100644
index 0000000000..67f2967d1a
--- /dev/null
+++ b/string/tst-string-posix2024-fortify.c
@@ -0,0 +1,6 @@
+/* Process tst-string-posix2024-main.c in fortified POSIX.1-2024 mode.  */
+#undef _GNU_SOURCE
+#define _POSIX_C_SOURCE 202405L
+#define TEST_FORTIFY 1
+
+#include "tst-string-posix2024-main.c"
diff --git a/string/tst-string-posix2024-main.c b/string/tst-string-posix2024-main.c
new file mode 100644
index 0000000000..4a52b09c59
--- /dev/null
+++ b/string/tst-string-posix2024-main.c
@@ -0,0 +1,45 @@
+/* Check POSIX.1-2024 declarations in <string.h>.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library 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.
+
+   The GNU C Library 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 the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <string.h>
+
+static int
+do_test (void)
+{
+  void *(*memmem_function) (const void *, size_t, const void *, size_t)
+    = memmem;
+  size_t (*strlcpy_function) (char *, const char *, size_t) = strlcpy;
+  size_t (*strlcat_function) (char *, const char *, size_t) = strlcat;
+
+#ifdef TEST_FORTIFY
+  size_t (*strlcpy_chk_function) (char *, const char *, size_t, size_t)
+    = __strlcpy_chk;
+  size_t (*strlcat_chk_function) (char *, const char *, size_t, size_t)
+    = __strlcat_chk;
+#endif
+
+  int result = memmem_function == NULL
+    || strlcpy_function == NULL
+    || strlcat_function == NULL;
+#ifdef TEST_FORTIFY
+  result |= strlcpy_chk_function == NULL || strlcat_chk_function == NULL;
+#endif
+  return result;
+}
+
+#include <support/test-driver.c>
diff --git a/string/tst-string-posix2024.c b/string/tst-string-posix2024.c
new file mode 100644
index 0000000000..a903dd1217
--- /dev/null
+++ b/string/tst-string-posix2024.c
@@ -0,0 +1,5 @@
+/* Process tst-string-posix2024-main.c in POSIX.1-2024 mode.  */
+#undef _GNU_SOURCE
+#define _POSIX_C_SOURCE 202405L
+
+#include "tst-string-posix2024-main.c"
diff --git a/string/tst-string-xopen2024.c b/string/tst-string-xopen2024.c
new file mode 100644
index 0000000000..8f1deaa9d7
--- /dev/null
+++ b/string/tst-string-xopen2024.c
@@ -0,0 +1,5 @@
+/* Process tst-string-posix2024-main.c in X/Open Issue 8 mode.  */
+#undef _GNU_SOURCE
+#define _XOPEN_SOURCE 800
+
+#include "tst-string-posix2024-main.c"
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
index f4f89c030f..e06289128f 100644
--- a/wcsmbs/Makefile
+++ b/wcsmbs/Makefile
@@ -179,6 +179,9 @@ tests := \
   tst-mbsrtowcs \
   tst-mbstowcs \
   tst-wchar-h \
+  tst-wchar-posix2024 \
+  tst-wchar-posix2024-fortify \
+  tst-wchar-xopen2024 \
   tst-wcpncpy \
   tst-wcrtomb \
   tst-wcslcat \
@@ -270,6 +273,8 @@ CFLAGS-wcstold_l.c += $(strtox-CFLAGS)
 CFLAGS-wcstof128_l.c += $(strtox-CFLAGS)
 CFLAGS-wcstof_l.c += $(strtox-CFLAGS)
 CPPFLAGS-tst-wchar-h.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
+CPPFLAGS-tst-wchar-posix2024-fortify.c += \
+  $(no-fortify-source) -D_FORTIFY_SOURCE=2
 
 CFLAGS-isoc99_wscanf.c += -fexceptions
 CFLAGS-isoc99_fwscanf.c += -fexceptions
diff --git a/wcsmbs/bits/wchar2-decl.h b/wcsmbs/bits/wchar2-decl.h
index 0f61877b31..75e2c0664a 100644
--- a/wcsmbs/bits/wchar2-decl.h
+++ b/wcsmbs/bits/wchar2-decl.h
@@ -279,7 +279,7 @@ extern size_t __REDIRECT_NTH (__wcsnrtombs_chk_warn,
 
 #endif
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 extern size_t __wcslcpy_chk (wchar_t *__dest, const wchar_t *__src, size_t __n,
 			     size_t __destlen) __THROW;
 extern size_t __REDIRECT_NTH (__wcslcpy_alias,
@@ -291,6 +291,6 @@ extern size_t __wcslcat_chk (wchar_t *__dest, const wchar_t *__src, size_t __n,
 extern size_t __REDIRECT_NTH (__wcslcat_alias,
 			      (wchar_t *__dest, const wchar_t *__src,
 			       size_t __n), wcslcat);
-#endif /* __USE_MISC */
+#endif /* __USE_MISC || __USE_XOPEN2K24 */
 
 #endif /* bits/wchar2-decl.h.  */
diff --git a/wcsmbs/bits/wchar2.h b/wcsmbs/bits/wchar2.h
index 2966c0ec6d..bd99d5201e 100644
--- a/wcsmbs/bits/wchar2.h
+++ b/wcsmbs/bits/wchar2.h
@@ -134,7 +134,7 @@ __NTH (wcsncat (__fortify_clang_overload_arg (wchar_t *, __restrict, __dest),
   return __wcsncat_alias (__dest, __src, __n);
 }
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 __fortify_function __attribute_overloadable__ size_t
 __NTH (wcslcpy (__fortify_clang_overload_arg (wchar_t *, __restrict, __dest),
 		const wchar_t *__restrict __src, size_t __n))
@@ -163,7 +163,7 @@ __NTH (wcslcat (__fortify_clang_overload_arg (wchar_t *, __restrict, __dest),
 			  __glibc_objsize (__dest) / sizeof (wchar_t));
   return __wcslcat_alias (__dest, __src, __n);
 }
-#endif /* __USE_MISC */
+#endif /* __USE_MISC || __USE_XOPEN2K24 */
 
 #ifdef __va_arg_pack
 __fortify_function int
diff --git a/wcsmbs/tst-wchar-posix2024-fortify.c b/wcsmbs/tst-wchar-posix2024-fortify.c
new file mode 100644
index 0000000000..ff30525aa7
--- /dev/null
+++ b/wcsmbs/tst-wchar-posix2024-fortify.c
@@ -0,0 +1,6 @@
+/* Process tst-wchar-posix2024-main.c in fortified POSIX.1-2024 mode.  */
+#undef _GNU_SOURCE
+#define _POSIX_C_SOURCE 202405L
+#define TEST_FORTIFY 1
+
+#include "tst-wchar-posix2024-main.c"
diff --git a/wcsmbs/tst-wchar-posix2024-main.c b/wcsmbs/tst-wchar-posix2024-main.c
new file mode 100644
index 0000000000..d744e5489f
--- /dev/null
+++ b/wcsmbs/tst-wchar-posix2024-main.c
@@ -0,0 +1,41 @@
+/* Check POSIX.1-2024 declarations in <wchar.h>.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library 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.
+
+   The GNU C Library 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 the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <wchar.h>
+
+static int
+do_test (void)
+{
+  size_t (*wcslcpy_function) (wchar_t *, const wchar_t *, size_t) = wcslcpy;
+  size_t (*wcslcat_function) (wchar_t *, const wchar_t *, size_t) = wcslcat;
+
+#ifdef TEST_FORTIFY
+  size_t (*wcslcpy_chk_function) (wchar_t *, const wchar_t *, size_t, size_t)
+    = __wcslcpy_chk;
+  size_t (*wcslcat_chk_function) (wchar_t *, const wchar_t *, size_t, size_t)
+    = __wcslcat_chk;
+#endif
+
+  int result = wcslcpy_function == NULL || wcslcat_function == NULL;
+#ifdef TEST_FORTIFY
+  result |= wcslcpy_chk_function == NULL || wcslcat_chk_function == NULL;
+#endif
+  return result;
+}
+
+#include <support/test-driver.c>
diff --git a/wcsmbs/tst-wchar-posix2024.c b/wcsmbs/tst-wchar-posix2024.c
new file mode 100644
index 0000000000..09f62fcac8
--- /dev/null
+++ b/wcsmbs/tst-wchar-posix2024.c
@@ -0,0 +1,5 @@
+/* Process tst-wchar-posix2024-main.c in POSIX.1-2024 mode.  */
+#undef _GNU_SOURCE
+#define _POSIX_C_SOURCE 202405L
+
+#include "tst-wchar-posix2024-main.c"
diff --git a/wcsmbs/tst-wchar-xopen2024.c b/wcsmbs/tst-wchar-xopen2024.c
new file mode 100644
index 0000000000..5ac3172b53
--- /dev/null
+++ b/wcsmbs/tst-wchar-xopen2024.c
@@ -0,0 +1,5 @@
+/* Process tst-wchar-posix2024-main.c in X/Open Issue 8 mode.  */
+#undef _GNU_SOURCE
+#define _XOPEN_SOURCE 800
+
+#include "tst-wchar-posix2024-main.c"
diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index 449f3b4eac..ec169ee67e 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -108,7 +108,7 @@ extern wchar_t *wcsncpy (wchar_t *__restrict __dest,
 			 const wchar_t *__restrict __src, size_t __n)
      __THROW __nonnull ((1, 2));
 
-#ifdef __USE_MISC
+#if defined __USE_MISC || defined __USE_XOPEN2K24
 /* Copy at most N - 1 characters from SRC to DEST.  */
 extern size_t wcslcpy (wchar_t *__restrict __dest,
 		       const wchar_t *__restrict __src, size_t __n)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.