* lib/uchar.in.h (c32snrtombs): New declaration.
* lib/wcsnrtombs-impl.h: Parameterize: Use macros FUNC, SCHAR_T,
INTERNAL_STATE, WCRTOMB.
* lib/wcsnrtombs.c (FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB): New macros.
* lib/c32snrtombs.c: New file.
* m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_C32SNRTOMBS.
* modules/uchar (Makefile.am): Substitute GNULIB_C32SNRTOMBS.
* modules/c32snrtombs: New file.
* tests/test-uchar-c++.cc: Test the signature of c32snrtombs.
* doc/posix-functions/wcsnrtombs.texi: Mention the new module.
+2020-01-10 Bruno Haible <bruno@clisp.org>
+
+ c32snrtombs: New module.
+ * lib/uchar.in.h (c32snrtombs): New declaration.
+ * lib/wcsnrtombs-impl.h: Parameterize: Use macros FUNC, SCHAR_T,
+ INTERNAL_STATE, WCRTOMB.
+ * lib/wcsnrtombs.c (FUNC, SCHAR_T, INTERNAL_STATE, WCRTOMB): New macros.
+ * lib/c32snrtombs.c: New file.
+ * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_C32SNRTOMBS.
+ * modules/uchar (Makefile.am): Substitute GNULIB_C32SNRTOMBS.
+ * modules/c32snrtombs: New file.
+ * tests/test-uchar-c++.cc: Test the signature of c32snrtombs.
+ * doc/posix-functions/wcsnrtombs.texi: Mention the new module.
+
2020-01-09 Bruno Haible <bruno@clisp.org>
c32srtombs: Add tests.
Portability problems not fixed by Gnulib:
@itemize
@item
-On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
-accommodate all Unicode characters.
+On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and
+therefore cannot accommodate all Unicode characters.
+However, the Gnulib function @code{c32snrtombs}, provided by Gnulib module
+@code{c32snrtombs}, operates on 32-bit wide characters and therefore does not
+have this limitation.
@end itemize
--- /dev/null
+/* Convert 32-bit wide string to string.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU 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>
+
+/* Specification. */
+#include <uchar.h>
+
+#include <wchar.h>
+
+#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_LARGE_CHAR32_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. */
+
+# include "verify.h"
+
+verify (sizeof (char32_t) == sizeof (wchar_t));
+
+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
#endif
+/* Convert a 32-bit wide string to a string. */
+#if @GNULIB_C32SNRTOMBS@
+_GL_FUNCDECL_SYS (c32snrtombs, size_t,
+ (char *dest, const char32_t **srcp, size_t srclen, size_t len,
+ mbstate_t *ps)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_SYS (c32snrtombs, size_t,
+ (char *dest, const char32_t **srcp, size_t srclen, size_t len,
+ mbstate_t *ps));
+_GL_CXXALIASWARN (c32snrtombs);
+#endif
+
+
/* Convert a 32-bit wide string to a string. */
#if @GNULIB_C32SRTOMBS@
_GL_FUNCDECL_SYS (c32srtombs, size_t,
along with this program. If not, see <https://www.gnu.org/licenses/>. */
size_t
-wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps)
+FUNC (char *dest, const SCHAR_T **srcp, size_t srclen, size_t len, mbstate_t *ps)
{
if (ps == NULL)
- ps = &_gl_wcsrtombs_state;
+ ps = &INTERNAL_STATE;
{
- const wchar_t *src = *srcp;
+ const SCHAR_T *src = *srcp;
size_t cur_max = MB_CUR_MAX;
char buf[64];
for (; srclen > 0 && len > 0; src++, srclen--)
{
- wchar_t wc = *src;
- size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps);
+ SCHAR_T wc = *src;
+ size_t ret = WCRTOMB (len >= cur_max ? destptr : buf, wc, ps);
if (ret == (size_t)(-1))
goto bad_input;
for (; srclen > 0; src++, srclen--)
{
- wchar_t wc = *src;
- size_t ret = wcrtomb (buf, wc, &state);
+ SCHAR_T wc = *src;
+ size_t ret = WCRTOMB (buf, wc, &state);
if (ret == (size_t)(-1))
goto bad_input2;
extern mbstate_t _gl_wcsrtombs_state;
+#define FUNC wcsnrtombs
+#define SCHAR_T wchar_t
+#define INTERNAL_STATE _gl_wcsrtombs_state
+#define WCRTOMB wcrtomb
#include "wcsnrtombs-impl.h"
-# uchar.m4 serial 10
+# uchar.m4 serial 11
dnl Copyright (C) 2019-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
[
GNULIB_BTOC32=0; AC_SUBST([GNULIB_BTOC32])
GNULIB_C32RTOMB=0; AC_SUBST([GNULIB_C32RTOMB])
+ GNULIB_C32SNRTOMBS=0; AC_SUBST([GNULIB_C32SNRTOMBS])
GNULIB_C32SRTOMBS=0; AC_SUBST([GNULIB_C32SRTOMBS])
GNULIB_C32TOB=0; AC_SUBST([GNULIB_C32TOB])
GNULIB_MBRTOC32=0; AC_SUBST([GNULIB_MBRTOC32])
--- /dev/null
+Description:
+c32snrtombs() function: convert 32-bit wide string to string.
+
+Files:
+lib/c32snrtombs.c
+lib/wcsnrtombs-impl.h
+lib/c32srtombs-state.c
+
+Depends-on:
+uchar
+wchar
+verify
+c32rtomb
+wcsnrtombs [test $SMALL_WCHAR_T = 0]
+
+configure.ac:
+AC_REQUIRE([gl_UCHAR_H])
+AC_LIBOBJ([c32srtombs-state])
+gl_UCHAR_MODULE_INDICATOR([c32snrtombs])
+
+Makefile.am:
+lib_SOURCES += c32snrtombs.c
+
+Include:
+<uchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
-e 's|@''SMALL_WCHAR_T''@|$(SMALL_WCHAR_T)|g' \
-e 's/@''GNULIB_BTOC32''@/$(GNULIB_BTOC32)/g' \
-e 's/@''GNULIB_C32RTOMB''@/$(GNULIB_C32RTOMB)/g' \
+ -e 's/@''GNULIB_C32SNRTOMBS''@/$(GNULIB_C32SNRTOMBS)/g' \
-e 's/@''GNULIB_C32SRTOMBS''@/$(GNULIB_C32SRTOMBS)/g' \
-e 's/@''GNULIB_C32TOB''@/$(GNULIB_C32TOB)/g' \
-e 's/@''GNULIB_MBRTOC32''@/$(GNULIB_MBRTOC32)/g' \
(char *, char32_t , mbstate_t *));
#endif
+#if GNULIB_TEST_C32SNRTOMBS
+SIGNATURE_CHECK (GNULIB_NAMESPACE::c32snrtombs, size_t,
+ (char *, const char32_t **, size_t, size_t, mbstate_t *));
+#endif
+
#if GNULIB_TEST_C32SRTOMBS
SIGNATURE_CHECK (GNULIB_NAMESPACE::c32srtombs, size_t,
(char *, const char32_t **, size_t, mbstate_t *));