]> Savannah Git Hosting - gnulib.git/commitdiff
c32stombs: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 12 Jan 2020 23:16:48 +0000 (00:16 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 12 Jan 2020 23:16:48 +0000 (00:16 +0100)
* 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.

ChangeLog
doc/posix-functions/wcstombs.texi
lib/c32stombs.c [new file with mode: 0644]
lib/uchar.in.h
m4/uchar.m4
modules/c32stombs [new file with mode: 0644]
modules/uchar
tests/test-uchar-c++.cc

index 9d90e3c30c35fe69ae27f4555eb1ea7d92fd077d..c2f4f249a2f878dcf7dc73088019ea80323df77b 100644 (file)
--- 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
index 2bca1cc8843bafa47d3249cd3497b6c687320821..dd8492ee83127db91799aac0752814c3ae225911 100644 (file)
@@ -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 (file)
index 0000000..01f7081
--- /dev/null
@@ -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);
+}
index a149f5aa30f2ec40480be655a7984b5871d86b23..5cf573d79279addc59f5796eb0cda747e66bfcfe 100644 (file)
@@ -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.  */
index 2a84bd16595897ef5fc67c7ca4f2b447057b621d..b5edc8cf93850904afb457a52b088e4e1b3d43fe 100644 (file)
@@ -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 (file)
index 0000000..2741877
--- /dev/null
@@ -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
index c7e86edd4cfc47d344592bcf2ff075033e38e96b..595bac5486e789aa7075c1692b652b39debe6ba6 100644 (file)
@@ -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' \
index ae97d9c11d76b775f009f897454dd67ca5f3b557..1855b7eb7ac1ae31d5c36ba3736691c84a1aa39a 100644 (file)
@@ -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