Hash :
c39d83dd
Author :
Date :
2023-06-27T11:28:26
c32*: Optionally enforce ISO C 23 semantics of char32_t. * lib/lc-charset-unicode.h: New file. * lib/lc-charset-unicode.c: New file. * modules/uchar-c23: New file. * lib/uchar.in.h (char32_t): Add comment. * lib/mbrtoc32.c: Include lc-charset-unicode.h. (mbrtoc32): If char32_t is Unicode and wchar_t is not, invoke locale_encoding_to_unicode. * lib/btoc32.c: Include lc-charset-unicode.h. (btoc32): If char32_t is Unicode and wchar_t is not, invoke locale_encoding_to_unicode. * lib/c32rtomb.c: Include lc-charset-unicode.h. (c32rtomb): If char32_t is Unicode and wchar_t is not, invoke unicode_to_locale_encoding. * lib/c32tob.c: Include lc-charset-unicode.h. (c32tob): If char32_t is Unicode and wchar_t is not, invoke unicode_to_locale_encoding. * lib/mbsnrtoc32s.c: If char32_t is Unicode and wchar_t is not, don't use mbsnrtowcs. * lib/mbsrtoc32s.c: If char32_t is Unicode and wchar_t is not, don't use mbsrtowcs. * lib/c32snrtombs.c: If char32_t is Unicode and wchar_t is not, don't use wcsnrtombs. * lib/c32srtombs.c: If char32_t is Unicode and wchar_t is not, don't use wcsrtombs. * lib/c32is-impl.h: Include lc-charset-unicode.h. (FUNC): If char32_t is Unicode and wchar_t is not, use UCS_FUNC. * lib/c32to-impl.h: Include lc-charset-unicode.h. (FUNC): If char32_t is Unicode and wchar_t is not, use UCS_FUNC. * lib/c32width.c: Include lc-charset-unicode.h. (c32width): If char32_t is Unicode and wchar_t is not, use uc_width. * tests/test-mbrtoc32.c: Include <wchar.h>. (main): Skip GB18030 tests on NetBSD and Solaris. If GL_CHAR32_T_IS_UNICODE, expect Unicode encoding for the char32_t values. * tests/test-mbrtoc32-w32.c: Include <wchar.h>. (test_one_locale): Simplify. * tests/test-c32rtomb.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32rtomb.sh: Update. * tests/test-mbsnrtoc32s.c: Include <wchar.h>. (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-mbsrtoc32s.c: Include <wchar.h>. (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-mbstoc32s.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32snrtombs.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32srtombs.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32stombs.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isalnum.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isalnum.sh: Update. * tests/test-c32isalpha.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32isalpha.sh: Update. * tests/test-c32isblank.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isblank.sh: Update. * tests/test-c32iscntrl.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32iscntrl.sh: Update. * tests/test-c32isdigit.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isdigit.sh: Update. * tests/test-c32isgraph.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32isgraph.sh: Update. * tests/test-c32islower.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32islower.sh: Update. * tests/test-c32isprint.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32isprint.sh: Update. * tests/test-c32ispunct.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32ispunct.sh: Update. * tests/test-c32isspace.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isspace.sh: Update. * tests/test-c32isupper.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isupper.sh: Update. * tests/test-c32isxdigit.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32isxdigit.sh: Update. * tests/test-c32tolower.c (main): Skip GB18030 tests on NetBSD and Solaris. * tests/test-c32tolower.sh: Update. * tests/test-c32toupper.c (main): Skip GB18030 tests on NetBSD and Solaris. Disable tests that would fail on macOS, FreeBSD, NetBSD, Solaris. * tests/test-c32toupper.sh: Update. * modules/mbrtoc32 (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/mbrtoc32-tests (Makefile.am): Link test-mbrtoc32 with $(LIBUNISTRING) $(LIBC32CONV). * modules/btoc32 (Link): New section. * modules/btoc32-tests (Makefile.am): Link test-btoc32 with $(LIBUNISTRING) $(LIBC32CONV). * modules/c32rtomb (Link): New section. * modules/c32rtomb-tests (Makefile.am): Link test-c32rtomb with $(LIBUNISTRING) $(LIBC32CONV). * modules/c32tob (Link): New section. * modules/mbsnrtoc32s (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/mbsnrtoc32s-tests (Makefile.am): Link test-mbsnrtoc32s with $(LIBUNISTRING) $(LIBC32CONV). * modules/mbsrtoc32s (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/mbsrtoc32s-tests (Makefile.am): Link test-mbsrtoc32s with $(LIBUNISTRING) $(LIBC32CONV). * modules/mbstoc32s (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/mbstoc32s-tests (Makefile.am): Link test-mbstoc32s with $(LIBUNISTRING) $(LIBC32CONV). * modules/c32snrtombs (Link): New section. * modules/c32snrtombs-tests (Makefile.am): Link test-c32snrtombs with $(LIBUNISTRING) $(LIBC32CONV). * modules/c32srtombs (Link): New section. * modules/c32srtombs-tests (Makefile.am): Link test-c32srtombs with $(LIBUNISTRING) $(LIBC32CONV). * modules/c32stombs (Link): New section. * modules/c32stombs-tests (Makefile.am): Link test-c32stombs with $(LIBUNISTRING) $(LIBC32CONV). * modules/c32isalnum (Link): Add $(LIBC32CONV). * modules/c32isalnum-tests (Makefile.am): Link test-c32isalnum with $(LIBC32CONV). * modules/c32isalpha (Link): Add $(LIBC32CONV). * modules/c32isalpha-tests (Makefile.am): Link test-c32isalpha with $(LIBC32CONV). * modules/c32isblank (Link): Add $(LIBC32CONV). * modules/c32isblank-tests (Makefile.am): Link test-c32isblank with $(LIBC32CONV). * modules/c32iscntrl (Link): Add $(LIBC32CONV). * modules/c32iscntrl-tests (Makefile.am): Link test-c32iscntrl with $(LIBC32CONV). * modules/c32isdigit (Link): Add $(LIBC32CONV). * modules/c32isdigit-tests (Makefile.am): Link test-c32isdigit with $(LIBC32CONV). * modules/c32isgraph (Link): Add $(LIBC32CONV). * modules/c32isgraph-tests (Makefile.am): Link test-c32isgraph with $(LIBC32CONV). * modules/c32islower (Link): Add $(LIBC32CONV). * modules/c32islower-tests (Makefile.am): Link test-c32islower with $(LIBC32CONV). * modules/c32isprint (Link): Add $(LIBC32CONV). * modules/c32isprint-tests (Makefile.am): Link test-c32isprint with $(LIBC32CONV). * modules/c32ispunct (Link): Add $(LIBC32CONV). * modules/c32ispunct-tests (Makefile.am): Link test-c32ispunct with $(LIBC32CONV). * modules/c32isspace (Link): Add $(LIBC32CONV). * modules/c32isspace-tests (Makefile.am): Link test-c32isspace with $(LIBC32CONV). * modules/c32isupper (Link): Add $(LIBC32CONV). * modules/c32isupper-tests (Makefile.am): Link test-c32isupper with $(LIBC32CONV). * modules/c32isxdigit (Link): Add $(LIBC32CONV). * modules/c32isxdigit-tests (Makefile.am): Link test-c32isxdigit with $(LIBC32CONV). * modules/c32tolower (Link): Add $(LIBC32CONV). * modules/c32tolower-tests (Makefile.am): Link test-c32tolower with $(LIBC32CONV). * modules/c32toupper (Link): Add $(LIBC32CONV). * modules/c32toupper-tests (Makefile.am): Link test-c32toupper with $(LIBC32CONV). * modules/c32width (Link): Add $(LIBC32CONV). * modules/c32width-tests (Makefile.am): Link test-c32width with $(LIBC32CONV). * modules/c32swidth (Link): Add $(LIBC32CONV). * modules/c32swidth-tests (Makefile.am): Link test-c32swidth with $(LIBC32CONV). * modules/mbchar (Link): Add $(LIBC32CONV). * modules/mbiter (Link): Add $(LIBC32CONV). * modules/mbuiter (Link): Add $(LIBC32CONV). * modules/mbfile (Link): Add $(LIBC32CONV). * modules/mbmemcasecmp (Link): Add $(LIBC32CONV). * modules/mbmemcasecmp-tests (Makefile.am): Link test-mbmemcasecmp with $(LIBC32CONV). * modules/mbscasecmp (Link): Add $(LIBC32CONV). * modules/mbscasecmp-tests (Makefile.am): Link test-mbscasecmp with $(LIBC32CONV). * modules/mbscasestr (Link): Add $(LIBC32CONV). * modules/mbscasestr-tests (Makefile.am): Link test-mbscasestr1, test-mbscasestr2, test-mbscasestr3, test-mbscasestr4 with $(LIBC32CONV). * modules/mbschr (Link): Add $(LIBC32CONV). * modules/mbschr-tests (Makefile.am): Link test-mbschr with $(LIBC32CONV). * modules/mbscspn (Link): Add $(LIBC32CONV). * modules/mbscspn-tests (Makefile.am): Link test-mbscspn with $(LIBC32CONV). * modules/mbslen (Link): Add $(LIBC32CONV). * modules/mbsncasecmp (Link): Add $(LIBC32CONV). * modules/mbsncasecmp-tests (Makefile.am): Link test-mbsncasecmp with $(LIBC32CONV). * modules/mbsnlen (Link): Add $(LIBC32CONV). * modules/mbspbrk (Link): Add $(LIBC32CONV). * modules/mbspbrk-tests (Makefile.am): Link test-mbspbrk with $(LIBC32CONV). * modules/mbspcasecmp (Link): Add $(LIBC32CONV). * modules/mbspcasecmp-tests (Makefile.am): Link test-mbspcasecmp with $(LIBC32CONV). * modules/mbsrchr (Link): Add $(LIBC32CONV). * modules/mbsrchr-tests (Makefile.am): Link test-mbsrchr with $(LIBC32CONV). * modules/mbssep (Link): Add $(LIBC32CONV). * modules/mbsspn (Link): Add $(LIBC32CONV). * modules/mbsspn-tests (Makefile.am): Link test-mbsspn with $(LIBC32CONV). * modules/mbsstr (Link): Add $(LIBC32CONV). * modules/mbsstr-tests (Makefile.am): Link test-mbsstr1, test-mbsstr2, test-mbsstr3 with $(LIBC32CONV). * modules/mbstok_r (Link): Add $(LIBC32CONV). * modules/propername (Link): Add $(LIBC32CONV). * modules/regex-quote (Link): Add $(LIBC32CONV). * modules/regex-quote-tests (Makefile.am): Link test-regex-quote with $(LIBC32CONV). * modules/trim (Link): Add $(LIBC32CONV). * modules/trim-tests (Makefile.am): Link test-trim with $(LIBC32CONV). * modules/exclude (Link): Add $(LIBC32CONV). * modules/exclude-tests (Makefile.am): Link test-exclude with $(LIBC32CONV). * doc/posix-headers/uchar.texi: Mention the uchar-c23 module. * doc/posix-functions/mbrtoc32.texi: Likewise. * doc/strings.texi (The char32_t type): Likewise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/* Convert 32-bit wide string to string.
Copyright (C) 2020-2023 Free Software Foundation, Inc.
This file 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 3 of the
License, or (at your option) any later version.
This file 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 this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>, 2020. */
#include <config.h>
#define IN_C32SNRTOMBS
/* Specification. */
#include <uchar.h>
#include <wchar.h>
#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || (GL_CHAR32_T_IS_UNICODE && GL_CHAR32_T_VS_WCHAR_T_NEEDS_CONVERSION) || _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. */
# include <errno.h>
# include <stdlib.h>
# include <string.h>
extern mbstate_t _gl_c32srtombs_state;
# define FUNC c32snrtombs
# define SCHAR_T char32_t
# define INTERNAL_STATE _gl_c32srtombs_state
# define WCRTOMB c32rtomb
# include "wcsnrtombs-impl.h"
#else
/* char32_t and wchar_t are equivalent. */
static_assert (sizeof (char32_t) == sizeof (wchar_t));
# if _GL_WCHAR_T_IS_UCS4
_GL_EXTERN_INLINE
# endif
size_t
c32snrtombs (char *dest, const char32_t **srcp, size_t srclen, size_t len,
mbstate_t *ps)
{
return wcsnrtombs (dest, (const wchar_t **) srcp, srclen, len, ps);
}
#endif