>From 0296188c2fea8f448b846e5510b8f7873bb79b53 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 13 Jan 2020 00:16:48 +0100 Subject: [PATCH 1/2] 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. --- ChangeLog | 11 +++++++++++ doc/posix-functions/wcstombs.texi | 7 +++++-- lib/c32stombs.c | 33 +++++++++++++++++++++++++++++++++ lib/uchar.in.h | 11 +++++++++++ m4/uchar.m4 | 3 ++- modules/c32stombs | 25 +++++++++++++++++++++++++ modules/uchar | 1 + tests/test-uchar-c++.cc | 5 +++++ 8 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 lib/c32stombs.c create mode 100644 modules/c32stombs diff --git a/ChangeLog b/ChangeLog index 9d90e3c..c2f4f24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2020-01-12 Bruno Haible + + 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 perl: require the "warnings" module diff --git a/doc/posix-functions/wcstombs.texi b/doc/posix-functions/wcstombs.texi index 2bca1cc..dd8492e 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 0000000..01f7081 --- /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 , 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 . */ + +#include + +/* Specification. */ +#include + +#include +#include + +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 a149f5a..5cf573d 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 2a84bd1..b5edc8c 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 0000000..2741877 --- /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: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/uchar b/modules/uchar index c7e86ed..595bac5 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 ae97d9c..1855b7e 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 -- 2.7.4