]> Savannah Git Hosting - gnulib.git/commitdiff
mbstoc32s: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 5 Jan 2020 11:23:00 +0000 (12:23 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Jan 2020 11:23:00 +0000 (12:23 +0100)
* 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
doc/posix-functions/mbstowcs.texi
lib/mbstoc32s.c [new file with mode: 0644]
lib/uchar.in.h
m4/uchar.m4
modules/mbstoc32s [new file with mode: 0644]
modules/uchar
tests/test-uchar-c++.cc

index 1a1d8b915c1dc875696873d4dcecf3b39b271c01..f2d507b1b942bdaad427047c246652e5d17c811c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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.
index af6ea731f6dc4a721aaa8d6c5e797c6e802cc3e2..5d7dc4ca62e8f585b578f3196437cee4ab30d868 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{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 (file)
index 0000000..ede2786
--- /dev/null
@@ -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);
+}
index f31b18c50a59768f74f3df034033c1ade7a0694f..513fa8c0baaa41eac7547095a10d3574be5f74c2 100644 (file)
@@ -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 */
index 4e0f43a5e2652776a701a4e9a36aa17bb6703333..0b5c6629533510cfd2a5fe720891162afcbf8c47 100644 (file)
@@ -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 (file)
index 0000000..e2b1662
--- /dev/null
@@ -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
index a50eb5af7d75d2323f1d153dfc1ee40e8cb32969..29bc7ae3ea7bf973410db7550fa758a0ed92373a 100644 (file)
@@ -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)' \
index a630eec0e6de354b6df32047f6ce7afa06197531..3e71c89c8299133d4971c86cba04c53e75ade300 100644 (file)
@@ -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 ()