* lib/stdlib.in.h (mbstowcs): New declaration.
* lib/mbstowcs.c: New file, based on lib/mbstoc32s.c.
* m4/mbstowcs.m4: New file.
* m4/stdlib_h.m4 (gl_STDLIB_H): Test whether mbstowcs is declared.
(gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize GNULIB_MBSTOWCS.
(gl_STDLIB_H_DEFAULTS): Initialize REPLACE_MBSTOWCS.
* modules/stdlib (Makefile.am): Substitute GNULIB_MBSTOWCS,
REPLACE_MBSTOWCS.
* modules/mbstowcs: New file.
* tests/test-stdlib-c++.cc (mbstowcs): Check signature.
* doc/posix-functions/mbstowcs.texi: Mention the C locale behaviour bug
and the new module.
+2023-03-30 Bruno Haible <bruno@clisp.org>
+
+ mbstowcs: New module.
+ * lib/stdlib.in.h (mbstowcs): New declaration.
+ * lib/mbstowcs.c: New file, based on lib/mbstoc32s.c.
+ * m4/mbstowcs.m4: New file.
+ * m4/stdlib_h.m4 (gl_STDLIB_H): Test whether mbstowcs is declared.
+ (gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize GNULIB_MBSTOWCS.
+ (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_MBSTOWCS.
+ * modules/stdlib (Makefile.am): Substitute GNULIB_MBSTOWCS,
+ REPLACE_MBSTOWCS.
+ * modules/mbstowcs: New file.
+ * tests/test-stdlib-c++.cc (mbstowcs): Check signature.
+ * doc/posix-functions/mbstowcs.texi: Mention the C locale behaviour bug
+ and the new module.
+
2023-03-30 Bruno Haible <bruno@clisp.org>
mbsnrtowcs: Fix behaviour in the C locale.
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbstowcs.html}
-Gnulib module: ---
+Gnulib module: mbstowcs
Portability problems fixed by Gnulib:
@itemize
+@item
+In the C or POSIX locales, this function can return @code{(size_t) -1}
+and set @code{errno} to @code{EILSEQ}:
+glibc 2.35.
@end itemize
Portability problems not fixed by Gnulib:
--- /dev/null
+/* Convert string to wide string.
+ Copyright (C) 2020-2023 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2020.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ This file 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdlib.h>
+
+#include <string.h>
+#include <wchar.h>
+
+size_t
+mbstowcs (wchar_t *dest, const char *src, size_t len)
+{
+ mbstate_t state;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ return mbsrtowcs (dest, &src, len, &state);
+}
# endif
#endif
+/* Convert a string to a wide string. */
+#if @GNULIB_MBSTOWCS@
+# if @REPLACE_MBSTOWCS@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef mbstowcs
+# define mbstowcs rpl_mbstowcs
+# endif
+_GL_FUNCDECL_RPL (mbstowcs, size_t,
+ (wchar_t *restrict dest, const char *restrict src,
+ size_t len)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (mbstowcs, size_t,
+ (wchar_t *restrict dest, const char *restrict src,
+ size_t len));
+# else
+_GL_CXXALIAS_SYS (mbstowcs, size_t,
+ (wchar_t *restrict dest, const char *restrict src,
+ size_t len));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (mbstowcs);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbstowcs
+# if HAVE_RAW_DECL_MBSTOWCS
+_GL_WARN_ON_USE (mbstowcs, "mbstowcs is unportable - "
+ "use gnulib module mbstowcs for portability");
+# endif
+#endif
+
/* Convert a multibyte character to a wide character. */
#if @GNULIB_MBTOWC@
# if @REPLACE_MBTOWC@
--- /dev/null
+# mbstowcs.m4 serial 1
+dnl Copyright (C) 2023 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBSTOWCS],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+ gl_MBRTOWC_C_LOCALE
+ case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in
+ *yes) ;;
+ *) REPLACE_MBSTOWCS=1 ;;
+ esac
+])
+
+# Prerequisites of lib/mbstowcs.c.
+AC_DEFUN([gl_PREREQ_MBSTOWCS], [
+ :
+])
-# stdlib_h.m4 serial 71
+# stdlib_h.m4 serial 72
dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
#endif
]], [_Exit aligned_alloc atoll canonicalize_file_name free
getloadavg getprogname getsubopt grantpt
- initstate initstate_r mbtowc mkdtemp mkostemp mkostemps mkstemp mkstemps
- posix_memalign posix_openpt ptsname ptsname_r qsort_r
+ initstate initstate_r mbstowcs mbtowc mkdtemp mkostemp mkostemps mkstemp
+ mkstemps posix_memalign posix_openpt ptsname ptsname_r qsort_r
random random_r reallocarray realpath rpmatch secure_getenv setenv
setstate setstate_r srandom srandom_r
strtod strtol strtold strtoll strtoul strtoull unlockpt unsetenv])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GRANTPT])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_GNU])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_POSIX])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSTOWCS])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBTOWC])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDTEMP])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKOSTEMP])
REPLACE_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE])
REPLACE_MALLOC_FOR_MALLOC_GNU=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_GNU])
REPLACE_MALLOC_FOR_MALLOC_POSIX=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_POSIX])
+ REPLACE_MBSTOWCS=0; AC_SUBST([REPLACE_MBSTOWCS])
REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC])
REPLACE_MKOSTEMP=0; AC_SUBST([REPLACE_MKOSTEMP])
REPLACE_MKOSTEMPS=0; AC_SUBST([REPLACE_MKOSTEMPS])
--- /dev/null
+Description:
+mbstowcs() function: convert string to wide string.
+
+Files:
+lib/mbstowcs.c
+m4/mbstowcs.m4
+m4/mbrtowc.m4
+
+Depends-on:
+stdlib
+mbsrtowcs [test $REPLACE_MBSTOWCS = 1]
+
+configure.ac:
+gl_FUNC_MBSTOWCS
+gl_CONDITIONAL([GL_COND_OBJ_MBSTOWCS], [test $REPLACE_MBSTOWCS = 1])
+AM_COND_IF([GL_COND_OBJ_MBSTOWCS], [
+ gl_PREREQ_MBSTOWCS
+])
+gl_STDLIB_MODULE_INDICATOR([mbstowcs])
+
+Makefile.am:
+if GL_COND_OBJ_MBSTOWCS
+lib_SOURCES += mbstowcs.c
+endif
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \
-e 's/@''GNULIB_MALLOC_GNU''@/$(GNULIB_MALLOC_GNU)/g' \
-e 's/@''GNULIB_MALLOC_POSIX''@/$(GNULIB_MALLOC_POSIX)/g' \
+ -e 's/@''GNULIB_MBSTOWCS''@/$(GNULIB_MBSTOWCS)/g' \
-e 's/@''GNULIB_MBTOWC''@/$(GNULIB_MBTOWC)/g' \
-e 's/@''GNULIB_MKDTEMP''@/$(GNULIB_MKDTEMP)/g' \
-e 's/@''GNULIB_MKOSTEMP''@/$(GNULIB_MKOSTEMP)/g' \
-e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
-e 's|@''REPLACE_MALLOC_FOR_MALLOC_GNU''@|$(REPLACE_MALLOC_FOR_MALLOC_GNU)|g' \
-e 's|@''REPLACE_MALLOC_FOR_MALLOC_POSIX''@|$(REPLACE_MALLOC_FOR_MALLOC_POSIX)|g' \
+ -e 's|@''REPLACE_MBSTOWCS''@|$(REPLACE_MBSTOWCS)|g' \
-e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
-e 's|@''REPLACE_MKOSTEMP''@|$(REPLACE_MKOSTEMP)|g' \
-e 's|@''REPLACE_MKOSTEMPS''@|$(REPLACE_MKOSTEMPS)|g' \
(wchar_t *, const char *, size_t));
#endif
+#if GNULIB_TEST_MBSTOWCS
+SIGNATURE_CHECK (GNULIB_NAMESPACE::mbstowcs, size_t,
+ (wchar_t *, const char *, size_t));
+#endif
+
#if GNULIB_TEST_MKDTEMP
SIGNATURE_CHECK (GNULIB_NAMESPACE::mkdtemp, char *, (char *));
#endif