git: 13d25dc29879 - stable/15 - libc: Add WCHAR_WIDTH in <wchar.h> as well

From: Faraz Vahedi <kfv_at_FreeBSD.org>
Date: Tue, 20 Oct 2026 08:12:11 UTC
The branch stable/15 has been updated by kfv:

URL: https://cgit.FreeBSD.org/src/commit/?id=13d25dc298793e333ca2efff85711b2406c09858

commit 13d25dc298793e333ca2efff85711b2406c09858
Author:     Faraz Vahedi <kfv@FreeBSD.org>
AuthorDate: 2026-09-05 10:41:22 +0000
Commit:     Faraz Vahedi <kfv@FreeBSD.org>
CommitDate: 2026-10-20 08:09:36 +0000

    libc: Add WCHAR_WIDTH in <wchar.h> as well
    
    Define __WCHAR_WIDTH in sys/_types.h and derive WCHAR_WIDTH from
    that, the same way as WCHAR_MIN and WCHAR_MAX, in both <wchar.h>
    and <stdint.h> as per C23 §7.31.1 and §7.22.3.4, respectively.
    
    Reviewed by:    fuz
    Approved by:    fuz (mentor)
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D59385
    
    (cherry picked from commit 72ed6f9c9dc95124cd81158d1c4437484a1b951e)
---
 include/wchar.h               | 3 +++
 sys/arm/include/_stdint.h     | 1 -
 sys/arm64/include/_stdint.h   | 1 -
 sys/powerpc/include/_stdint.h | 1 -
 sys/riscv/include/_stdint.h   | 1 -
 sys/sys/_types.h              | 2 ++
 sys/sys/stdint.h              | 3 +++
 sys/x86/include/_stdint.h     | 1 -
 8 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/wchar.h b/include/wchar.h
index 1447d083a889..d191981be5ff 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -97,6 +97,9 @@ typedef	__wint_t	wint_t;
 
 #define	WCHAR_MIN	__WCHAR_MIN
 #define	WCHAR_MAX	__WCHAR_MAX
+#if __ISO_C_VISIBLE >= 2023
+#define	WCHAR_WIDTH	__WCHAR_WIDTH
+#endif
 
 #ifndef WEOF
 #define	WEOF 	((wint_t)-1)
diff --git a/sys/arm/include/_stdint.h b/sys/arm/include/_stdint.h
index 9f9b7eb8a554..b0b92f8de72f 100644
--- a/sys/arm/include/_stdint.h
+++ b/sys/arm/include/_stdint.h
@@ -166,7 +166,6 @@
 #define PTRDIFF_WIDTH		INT32_WIDTH
 #define SIG_ATOMIC_WIDTH	INT32_WIDTH
 #define SIZE_WIDTH		INT32_WIDTH
-#define WCHAR_WIDTH		INT32_WIDTH
 #define WINT_WIDTH		INT32_WIDTH
 #endif /* __ISO_C_VISIBLE >= 2023 */
 
diff --git a/sys/arm64/include/_stdint.h b/sys/arm64/include/_stdint.h
index 621e5ce53721..1088ab383a35 100644
--- a/sys/arm64/include/_stdint.h
+++ b/sys/arm64/include/_stdint.h
@@ -168,7 +168,6 @@
 #define PTRDIFF_WIDTH           INT64_WIDTH
 #define SIG_ATOMIC_WIDTH        INT64_WIDTH
 #define SIZE_WIDTH              INT64_WIDTH
-#define WCHAR_WIDTH             INT32_WIDTH
 #define WINT_WIDTH              INT32_WIDTH
 #endif /* __ISO_C_VISIBLE >= 2023 */
 
diff --git a/sys/powerpc/include/_stdint.h b/sys/powerpc/include/_stdint.h
index 68ae89e23cdc..5423badb25a6 100644
--- a/sys/powerpc/include/_stdint.h
+++ b/sys/powerpc/include/_stdint.h
@@ -213,7 +213,6 @@
 #define SIZE_WIDTH		INT32_WIDTH
 #endif
 #define SIG_ATOMIC_WIDTH	INT32_WIDTH
-#define WCHAR_WIDTH		INT32_WIDTH
 #define WINT_WIDTH		INT32_WIDTH
 #endif /* __ISO_C_VISIBLE >= 2023 */
 
diff --git a/sys/riscv/include/_stdint.h b/sys/riscv/include/_stdint.h
index 9afe01c8a318..3cfb78208aec 100644
--- a/sys/riscv/include/_stdint.h
+++ b/sys/riscv/include/_stdint.h
@@ -164,7 +164,6 @@
 #define PTRDIFF_WIDTH		INT64_WIDTH
 #define SIG_ATOMIC_WIDTH	INT64_WIDTH
 #define SIZE_WIDTH		INT64_WIDTH
-#define WCHAR_WIDTH		INT32_WIDTH
 #define WINT_WIDTH		INT32_WIDTH
 #endif /* __ISO_C_VISIBLE >= 2023 */
 
diff --git a/sys/sys/_types.h b/sys/sys/_types.h
index 02d01f86b298..1b69152fd2e3 100644
--- a/sys/sys/_types.h
+++ b/sys/sys/_types.h
@@ -108,6 +108,8 @@ typedef	__int32_t	__ptrdiff_t;	/* ptr1 - ptr2 */
  */
 #include <machine/_types.h>
 
+#define	__WCHAR_WIDTH	32		/* number of bits in a wchar_t */
+
 /*
  * Standard type definitions.
  */
diff --git a/sys/sys/stdint.h b/sys/sys/stdint.h
index dccc5a8e6a6d..661945c18281 100644
--- a/sys/sys/stdint.h
+++ b/sys/sys/stdint.h
@@ -68,6 +68,9 @@ typedef	__uint_fast64_t		uint_fast64_t;
 /* Limits of wchar_t. */
 #define	WCHAR_MIN	__WCHAR_MIN
 #define	WCHAR_MAX	__WCHAR_MAX
+#if __ISO_C_VISIBLE >= 2023
+#define	WCHAR_WIDTH	__WCHAR_WIDTH
+#endif
 
 #if __EXT1_VISIBLE
 /* ISO/IEC 9899:2011 K.3.4.4 */
diff --git a/sys/x86/include/_stdint.h b/sys/x86/include/_stdint.h
index 4c65b0f095ea..fa51cd27b8a8 100644
--- a/sys/x86/include/_stdint.h
+++ b/sys/x86/include/_stdint.h
@@ -207,7 +207,6 @@
 #define SIG_ATOMIC_WIDTH	INT32_WIDTH
 #define SIZE_WIDTH		INT32_WIDTH
 #endif
-#define WCHAR_WIDTH		INT32_WIDTH
 #define WINT_WIDTH		INT32_WIDTH
 #endif /* __ISO_C_VISIBLE >= 2023 */