summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--doc/posix-functions/wcstombs.texi7
-rw-r--r--lib/c32stombs.c33
-rw-r--r--lib/uchar.in.h11
-rw-r--r--m4/uchar.m43
-rw-r--r--modules/c32stombs25
-rw-r--r--modules/uchar1
-rw-r--r--tests/test-uchar-c++.cc5
8 files changed, 93 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d90e3c30c..c2f4f249a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-01-12 Bruno Haible <bruno@clisp.org>
+
+ c32stombs: New module.
+ * lib/uchar.in.h (c32stombs): New declaration.
+ * lib/c32stombs.c: New file.
+ * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_C32STOMBS.
+ * modules/uchar (Makefile.am): Substitute GNULIB_C32STOMBS.
+ * modules/c32stombs: New file.
+ * tests/test-uchar-c++.cc: Test the signature of c32stombs.
+ * doc/posix-functions/wcstombs.texi: Mention the new module.
+
2020-01-11 Jim Meyering <meyering@fb.com>
perl: require the "warnings" module
diff --git a/doc/posix-functions/wcstombs.texi b/doc/posix-functions/wcstombs.texi
index 2bca1cc884..dd8492ee83 100644
--- a/doc/posix-functions/wcstombs.texi
+++ b/doc/posix-functions/wcstombs.texi
@@ -13,6 +13,9 @@ Portability problems fixed by Gnulib:
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{c32stombs}, provided by Gnulib module
+@code{c32stombs}, operates on 32-bit wide characters and therefore does not
+have this limitation.
@end itemize
diff --git a/lib/c32stombs.c b/lib/c32stombs.c
new file mode 100644
index 0000000000..01f7081e6f
--- /dev/null
+++ b/lib/c32stombs.c
@@ -0,0 +1,33 @@
+/* Convert 32-bit wide string to string.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2020.
+
+ 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/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <uchar.h>
+
+#include <string.h>
+#include <wchar.h>
+
+size_t
+c32stombs (char *dest, const char32_t *src, size_t len)
+{
+ mbstate_t state;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ return c32srtombs (dest, &src, len, &state);
+}
diff --git a/lib/uchar.in.h b/lib/uchar.in.h
index a149f5aa30..5cf573d792 100644
--- a/lib/uchar.in.h
+++ b/lib/uchar.in.h
@@ -118,6 +118,17 @@ _GL_CXXALIASWARN (c32srtombs);
#endif
+/* Convert a 32-bit wide string to a string. */
+#if @GNULIB_C32STOMBS@
+_GL_FUNCDECL_SYS (c32stombs, size_t,
+ (char *dest, const char32_t *src, size_t len)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_SYS (c32stombs, size_t,
+ (char *dest, const char32_t *src, size_t len));
+_GL_CXXALIASWARN (c32stombs);
+#endif
+
+
/* Converts a 32-bit wide character to unibyte character.
Returns the single-byte representation of WC if it exists,
or EOF otherwise. */
diff --git a/m4/uchar.m4 b/m4/uchar.m4
index 2a84bd1659..b5edc8cf93 100644
--- a/m4/uchar.m4
+++ b/m4/uchar.m4
@@ -1,4 +1,4 @@
-# uchar.m4 serial 11
+# uchar.m4 serial 12
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,
@@ -51,6 +51,7 @@ AC_DEFUN([gl_UCHAR_H_DEFAULTS],
GNULIB_C32RTOMB=0; AC_SUBST([GNULIB_C32RTOMB])
GNULIB_C32SNRTOMBS=0; AC_SUBST([GNULIB_C32SNRTOMBS])
GNULIB_C32SRTOMBS=0; AC_SUBST([GNULIB_C32SRTOMBS])
+ GNULIB_C32STOMBS=0; AC_SUBST([GNULIB_C32STOMBS])
GNULIB_C32TOB=0; AC_SUBST([GNULIB_C32TOB])
GNULIB_MBRTOC32=0; AC_SUBST([GNULIB_MBRTOC32])
GNULIB_MBSNRTOC32S=0; AC_SUBST([GNULIB_MBSNRTOC32S])
diff --git a/modules/c32stombs b/modules/c32stombs
new file mode 100644
index 0000000000..274187778b
--- /dev/null
+++ b/modules/c32stombs
@@ -0,0 +1,25 @@
+Description:
+c32stombs() function: convert 32-bit wide string to string.
+
+Files:
+lib/c32stombs.c
+
+Depends-on:
+uchar
+wchar
+c32srtombs
+
+configure.ac:
+gl_UCHAR_MODULE_INDICATOR([c32stombs])
+
+Makefile.am:
+lib_SOURCES += c32stombs.c
+
+Include:
+<uchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
diff --git a/modules/uchar b/modules/uchar
index c7e86edd4c..595bac5486 100644
--- a/modules/uchar
+++ b/modules/uchar
@@ -32,6 +32,7 @@ uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H)
-e 's/@''GNULIB_C32RTOMB''@/$(GNULIB_C32RTOMB)/g' \
-e 's/@''GNULIB_C32SNRTOMBS''@/$(GNULIB_C32SNRTOMBS)/g' \
-e 's/@''GNULIB_C32SRTOMBS''@/$(GNULIB_C32SRTOMBS)/g' \
+ -e 's/@''GNULIB_C32STOMBS''@/$(GNULIB_C32STOMBS)/g' \
-e 's/@''GNULIB_C32TOB''@/$(GNULIB_C32TOB)/g' \
-e 's/@''GNULIB_MBRTOC32''@/$(GNULIB_MBRTOC32)/g' \
-e 's/@''GNULIB_MBSNRTOC32S''@/$(GNULIB_MBSNRTOC32S)/g' \
diff --git a/tests/test-uchar-c++.cc b/tests/test-uchar-c++.cc
index ae97d9c11d..1855b7eb7a 100644
--- a/tests/test-uchar-c++.cc
+++ b/tests/test-uchar-c++.cc
@@ -43,6 +43,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::c32srtombs, size_t,
(char *, const char32_t **, size_t, mbstate_t *));
#endif
+#if GNULIB_TEST_C32STOMBS
+SIGNATURE_CHECK (GNULIB_NAMESPACE::c32stombs, size_t,
+ (char *, const char32_t *, size_t));
+#endif
+
#if GNULIB_TEST_C32TOB
SIGNATURE_CHECK (GNULIB_NAMESPACE::c32tob, int, (wint_t));
#endif