summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-01-05 12:23:00 +0100
committerBruno Haible <bruno@clisp.org>2020-01-05 12:23:00 +0100
commit8208c314448c4a26beda29b9666a5626521b7312 (patch)
treecb678a59f8406d24f9c7dc919f90afb412086d72
parent888c04969a2a067ad6a4ed75cf3461e34765ee51 (diff)
downloadgnulib-8208c314448c4a26beda29b9666a5626521b7312.tar.gz
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.
-rw-r--r--ChangeLog11
-rw-r--r--doc/posix-functions/mbstowcs.texi7
-rw-r--r--lib/mbstoc32s.c33
-rw-r--r--lib/uchar.in.h11
-rw-r--r--m4/uchar.m43
-rw-r--r--modules/mbstoc32s28
-rw-r--r--modules/uchar1
-rw-r--r--tests/test-uchar-c++.cc5
8 files changed, 96 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 1a1d8b915c..f2d507b1b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2020-01-05 Bruno Haible <bruno@clisp.org>
+ 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 <bruno@clisp.org>
+
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 af6ea731f6..5d7dc4ca62 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 0000000000..ede2786628
--- /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 <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
+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 f31b18c50a..513fa8c0ba 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 4e0f43a5e2..0b5c662953 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 0000000000..e2b166294c
--- /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:
+<uchar.h>
+
+Link:
+$(LIB_MBRTOWC)
+
+License:
+LGPLv2+
+
+Maintainer:
+Bruno Haible
diff --git a/modules/uchar b/modules/uchar
index a50eb5af7d..29bc7ae3ea 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 a630eec0e6..3e71c89c82 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 ()