summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-04-04 12:34:12 +0200
committerBruno Haible <bruno@clisp.org>2023-04-04 12:34:12 +0200
commit6b4ef50c64e606f11afcd9e8a063f05c835bb4a6 (patch)
treec8226ef51c1b403627eeb17e0f9ae3ce9cf664b2 /lib
parent4fab8907555510129a2190bb0268cd1525491e0f (diff)
downloadgnulib-6b4ef50c64e606f11afcd9e8a063f05c835bb4a6.tar.gz
*c32*: Optimize on musl libc like on glibc.
* lib/uchar.in.h (_GL_WCHAR_T_IS_UCS4): New macro. * lib/btoc32.c (btoc32): Test _GL_WCHAR_T_IS_UCS4 instead of __GLIBC__. * lib/mbsrtoc32s.c: Likewise. * lib/mbsnrtoc32s.c: Likewise. * lib/c32tob.c (c32tob): Likewise. * lib/c32srtombs.c: Likewise. * lib/c32snrtombs.c: Likewise. * lib/c32is-impl.h (FUNC): Likewise.
Diffstat (limited to 'lib')
-rw-r--r--lib/btoc32.c2
-rw-r--r--lib/c32is-impl.h2
-rw-r--r--lib/c32snrtombs.c2
-rw-r--r--lib/c32srtombs.c2
-rw-r--r--lib/c32tob.c2
-rw-r--r--lib/mbsnrtoc32s.c2
-rw-r--r--lib/mbsrtoc32s.c2
-rw-r--r--lib/uchar.in.h16
8 files changed, 23 insertions, 7 deletions
diff --git a/lib/btoc32.c b/lib/btoc32.c
index 45313819b9..9ba8fb5a5e 100644
--- a/lib/btoc32.c
+++ b/lib/btoc32.c
@@ -27,7 +27,7 @@
wint_t
btoc32 (int c)
{
-#if HAVE_WORKING_MBRTOC32 && !defined __GLIBC__
+#if HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4
/* The char32_t encoding of a multibyte character may be different than its
wchar_t encoding. */
if (c != EOF)
diff --git a/lib/c32is-impl.h b/lib/c32is-impl.h
index 13a7dff58c..d5e5362c0b 100644
--- a/lib/c32is-impl.h
+++ b/lib/c32is-impl.h
@@ -61,7 +61,7 @@ FUNC (wint_t wc)
#elif HAVE_WORKING_MBRTOC32 /* glibc */
/* mbrtoc32() is essentially defined by the system libc. */
-# if defined __GLIBC__
+# if _GL_WCHAR_T_IS_UCS4
/* The char32_t encoding of a multibyte character is known to be the same as
the wchar_t encoding. */
return WCHAR_FUNC (wc);
diff --git a/lib/c32snrtombs.c b/lib/c32snrtombs.c
index 644e171afe..fd10fc1595 100644
--- a/lib/c32snrtombs.c
+++ b/lib/c32snrtombs.c
@@ -23,7 +23,7 @@
#include <wchar.h>
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
/* The char32_t encoding of a multibyte character may be different than its
wchar_t encoding, or char32_t is wider than wchar_t. */
diff --git a/lib/c32srtombs.c b/lib/c32srtombs.c
index 093d151483..50db58c3d3 100644
--- a/lib/c32srtombs.c
+++ b/lib/c32srtombs.c
@@ -23,7 +23,7 @@
#include <wchar.h>
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
/* The char32_t encoding of a multibyte character may be different than its
wchar_t encoding, or char32_t is wider than wchar_t. */
diff --git a/lib/c32tob.c b/lib/c32tob.c
index 75c46c1dcd..a18aac6efc 100644
--- a/lib/c32tob.c
+++ b/lib/c32tob.c
@@ -28,7 +28,7 @@
int
c32tob (wint_t wc)
{
-#if HAVE_WORKING_MBRTOC32 && !defined __GLIBC__
+#if HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4
/* The char32_t encoding of a multibyte character may be different than its
wchar_t encoding. */
if (wc != WEOF)
diff --git a/lib/mbsnrtoc32s.c b/lib/mbsnrtoc32s.c
index 81125fdc54..c8084da3d9 100644
--- a/lib/mbsnrtoc32s.c
+++ b/lib/mbsnrtoc32s.c
@@ -22,7 +22,7 @@
#include <wchar.h>
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
/* The char32_t encoding of a multibyte character may be different than its
wchar_t encoding, or char32_t is wider than wchar_t. */
diff --git a/lib/mbsrtoc32s.c b/lib/mbsrtoc32s.c
index b5f2523990..9c5a5d096a 100644
--- a/lib/mbsrtoc32s.c
+++ b/lib/mbsrtoc32s.c
@@ -22,7 +22,7 @@
#include <wchar.h>
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
/* The char32_t encoding of a multibyte character may be different than its
wchar_t encoding, or char32_t is wider than wchar_t. */
diff --git a/lib/uchar.in.h b/lib/uchar.in.h
index adf9c551eb..46b4be4f6d 100644
--- a/lib/uchar.in.h
+++ b/lib/uchar.in.h
@@ -107,6 +107,22 @@ typedef uint_least32_t gl_char32_t;
# define _GL_SMALL_WCHAR_T 1
#endif
+/* Define if 'wchar_t', like 'char32_t',
+ - is a 32-bit type, and
+ - represents Unicode code points.
+ For this test, we can use __STDC_ISO_10646__ (defined by glibc, musl libc,
+ Cygwin) but need to consider _GL_SMALL_WCHAR_T, so as to exclude Cygwin.
+ We cannot use __STDC_UTF_16__ or __STDC_UTF_32__
+ - because these macros provide info about char16_t and char32_t (not
+ wchar_t!), and
+ - because GCC >= 4.9 defines these macros on all platforms, even on
+ FreeBSD and Solaris.
+ We should better not use __STD_UTF_16__, __STD_UTF_32__ either, because
+ these macros are misspellings, only defined by Android's <uchar.h>. */
+#if defined __STDC_ISO_10646__ && !_GL_SMALL_WCHAR_T
+/* glibc, musl libc */
+# define _GL_WCHAR_T_IS_UCS4 1
+#endif
/* Convert a single-byte character to a 32-bit wide character. */
#if @GNULIB_BTOC32@