>From 8208c314448c4a26beda29b9666a5626521b7312 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 5 Jan 2020 12:23:00 +0100 Subject: [PATCH 1/2] mbstoc32s: New module. * lib/uchar.in.h (mbstoc32s): New declaration. * lib/mbstoc32s.c: New file. * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_MBSTOC32S. * modules/uchar (Makefile.am): Substitute GNULIB_MBSTOC32S. * modules/mbstoc32s: New file. * tests/test-uchar-c++.cc: Test the signature of mbstoc32s. * doc/posix-functions/mbstowcs.texi: Mention the new module. --- ChangeLog | 11 +++++++++++ doc/posix-functions/mbstowcs.texi | 7 +++++-- lib/mbstoc32s.c | 33 +++++++++++++++++++++++++++++++++ lib/uchar.in.h | 11 +++++++++++ m4/uchar.m4 | 3 ++- modules/mbstoc32s | 28 ++++++++++++++++++++++++++++ modules/uchar | 1 + tests/test-uchar-c++.cc | 5 +++++ 8 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 lib/mbstoc32s.c create mode 100644 modules/mbstoc32s diff --git a/ChangeLog b/ChangeLog index 1a1d8b9..f2d507b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2020-01-05 Bruno Haible + mbstoc32s: New module. + * lib/uchar.in.h (mbstoc32s): New declaration. + * lib/mbstoc32s.c: New file. + * m4/uchar.m4 (gl_UCHAR_H_DEFAULTS): Initialize GNULIB_MBSTOC32S. + * modules/uchar (Makefile.am): Substitute GNULIB_MBSTOC32S. + * modules/mbstoc32s: New file. + * tests/test-uchar-c++.cc: Test the signature of mbstoc32s. + * doc/posix-functions/mbstowcs.texi: Mention the new module. + +2020-01-05 Bruno Haible + Tweak recently added tests. * tests/test-mbrtoc32.c: Make signature consistent with uchar.in.h. * tests/test-mbsrtoc32s.c: Likewise. diff --git a/doc/posix-functions/mbstowcs.texi b/doc/posix-functions/mbstowcs.texi index af6ea73..5d7dc4c 100644 --- a/doc/posix-functions/mbstowcs.texi +++ b/doc/posix-functions/mbstowcs.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{mbstoc32s}, provided by Gnulib module +@code{mbstoc32s}, operates on 32-bit wide characters and therefore does not +have this limitation. @end itemize diff --git a/lib/mbstoc32s.c b/lib/mbstoc32s.c new file mode 100644 index 0000000..ede2786 --- /dev/null +++ b/lib/mbstoc32s.c @@ -0,0 +1,33 @@ +/* Convert string to 32-bit wide 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 +mbstoc32s (char32_t *dest, const char *src, size_t len) +{ + mbstate_t state; + + memset (&state, '\0', sizeof (mbstate_t)); + return mbsrtoc32s (dest, &src, len, &state); +} diff --git a/lib/uchar.in.h b/lib/uchar.in.h index f31b18c..513fa8c 100644 --- a/lib/uchar.in.h +++ b/lib/uchar.in.h @@ -132,4 +132,15 @@ _GL_CXXALIASWARN (mbsrtoc32s); #endif +/* Convert a string to a 32-bit wide string. */ +#if @GNULIB_MBSTOC32S@ +_GL_FUNCDECL_SYS (mbstoc32s, size_t, + (char32_t *dest, const char *src, size_t len) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_SYS (mbstoc32s, size_t, + (char32_t *dest, const char *src, size_t len)); +_GL_CXXALIASWARN (mbstoc32s); +#endif + + #endif /* _@GUARD_PREFIX@_UCHAR_H */ diff --git a/m4/uchar.m4 b/m4/uchar.m4 index 4e0f43a..0b5c662 100644 --- a/m4/uchar.m4 +++ b/m4/uchar.m4 @@ -1,4 +1,4 @@ -# uchar.m4 serial 7 +# uchar.m4 serial 8 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, @@ -52,6 +52,7 @@ AC_DEFUN([gl_UCHAR_H_DEFAULTS], GNULIB_MBRTOC32=0; AC_SUBST([GNULIB_MBRTOC32]) GNULIB_MBSNRTOC32S=0; AC_SUBST([GNULIB_MBSNRTOC32S]) GNULIB_MBSRTOC32S=0; AC_SUBST([GNULIB_MBSRTOC32S]) + GNULIB_MBSTOC32S=0; AC_SUBST([GNULIB_MBSTOC32S]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_MBRTOC32=1; AC_SUBST([HAVE_MBRTOC32]) REPLACE_MBRTOC32=0; AC_SUBST([REPLACE_MBRTOC32]) diff --git a/modules/mbstoc32s b/modules/mbstoc32s new file mode 100644 index 0000000..e2b1662 --- /dev/null +++ b/modules/mbstoc32s @@ -0,0 +1,28 @@ +Description: +mbstoc32s() function: convert string to 32-bit wide string. + +Files: +lib/mbstoc32s.c + +Depends-on: +uchar +wchar +mbsrtoc32s + +configure.ac: +gl_UCHAR_MODULE_INDICATOR([mbstoc32s]) + +Makefile.am: +lib_SOURCES += mbstoc32s.c + +Include: + + +Link: +$(LIB_MBRTOWC) + +License: +LGPLv2+ + +Maintainer: +Bruno Haible diff --git a/modules/uchar b/modules/uchar index a50eb5a..29bc7ae 100644 --- a/modules/uchar +++ b/modules/uchar @@ -33,6 +33,7 @@ uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) -e 's/@''GNULIB_MBRTOC32''@/$(GNULIB_MBRTOC32)/g' \ -e 's/@''GNULIB_MBSNRTOC32S''@/$(GNULIB_MBSNRTOC32S)/g' \ -e 's/@''GNULIB_MBSRTOC32S''@/$(GNULIB_MBSRTOC32S)/g' \ + -e 's/@''GNULIB_MBSTOC32S''@/$(GNULIB_MBSTOC32S)/g' \ -e 's|@''HAVE_MBRTOC32''@|$(HAVE_MBRTOC32)|g' \ -e 's|@''REPLACE_MBRTOC32''@|$(REPLACE_MBRTOC32)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ diff --git a/tests/test-uchar-c++.cc b/tests/test-uchar-c++.cc index a630eec..3e71c89 100644 --- a/tests/test-uchar-c++.cc +++ b/tests/test-uchar-c++.cc @@ -48,6 +48,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::mbsrtoc32s, size_t, (char32_t *, const char **, size_t, mbstate_t *)); #endif +#if GNULIB_TEST_MBSTOC32S +SIGNATURE_CHECK (GNULIB_NAMESPACE::mbstoc32s, size_t, + (char32_t *, const char *, size_t)); +#endif + int main () -- 2.7.4