* lib/c32tob.c: Include <stdio.h>, <string.h>, <wchar.h>.
(c32tob): If the char32_t encoding and the wchar_t encoding may differ,
use c32rtomb, not wctob.
* modules/c32tob (Files): Add m4/mbrtoc32.m4.
(Depends-on): Add c32rtomb.
(configure.ac): Require gl_MBRTOC32_SANITYCHECK.
+2020-01-08 Bruno Haible <bruno@clisp.org>
+
+ c32tob: Make consistent with mbrtoc32.
+ * lib/c32tob.c: Include <stdio.h>, <string.h>, <wchar.h>.
+ (c32tob): If the char32_t encoding and the wchar_t encoding may differ,
+ use c32rtomb, not wctob.
+ * modules/c32tob (Files): Add m4/mbrtoc32.m4.
+ (Depends-on): Add c32rtomb.
+ (configure.ac): Require gl_MBRTOC32_SANITYCHECK.
+
2020-01-08 Bruno Haible <bruno@clisp.org>
c32rtomb: Add tests.
/* Specification. */
#include <uchar.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
int
c32tob (wint_t wc)
{
-#if _GL_LARGE_CHAR32_T
+#if HAVE_WORKING_MBRTOC32 && !defined __GLIBC__
+ /* The char32_t encoding of a multibyte character may be different than its
+ wchar_t encoding. */
+ if (wc != WEOF)
+ {
+ mbstate_t state;
+ char buf[8];
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (c32rtomb (buf, wc, &state) == 1)
+ return (unsigned char) buf[0];
+ }
+ return EOF;
+#elif _GL_LARGE_CHAR32_T
/* In all known encodings, unibyte characters correspond only to
characters in the BMP. */
if (wc != WEOF && (wchar_t) wc == wc)
Files:
lib/c32tob.c
+m4/mbrtoc32.m4
Depends-on:
uchar
+c32rtomb
wctob
configure.ac:
+AC_REQUIRE([gl_MBRTOC32_SANITYCHECK])
gl_UCHAR_MODULE_INDICATOR([c32tob])
Makefile.am: