+2008-12-21 Bruno Haible <bruno@clisp.org>
+
+ New module 'wcsnrtombs'.
+ * lib/wchar.in.h (wcsnrtombs): New declaration.
+ * lib/wcsnrtombs.c: New file.
+ * lib/wcsrtombs-state.c: New file.
+ * lib/wcsrtombs.c: Refer to _gl_wcsrtombs_state.
+ (internal_state): Remove variable.
+ * m4/wcsnrtombs.m4: New file.
+ * m4/wcsrtombs.m4 (gl_FUNC_WCSRTOMBS): Add wcsrtombs-state.c to the
+ compilation units.
+ * m4/wchar.m4 (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSNRTOMBS,
+ HAVE_WCSNRTOMBS.
+ * modules/wchar (Makefile.am): Substitute GNULIB_WCSNRTOMBS,
+ HAVE_WCSNRTOMBS.
+ * modules/wcsnrtombs: New file.
+ * modules/wcsrtombs (Files): Add lib/wcsrtombs-state.c.
+ * doc/posix-functions/wcsnrtombs.texi: Mention the new module.
+
2008-12-21 Bruno Haible <bruno@clisp.org>
* modules/wcsrtombs-tests: New file.
POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsnrtombs.html}
-Gnulib module: ---
+Gnulib module: wcsnrtombs
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+MacOS X 10.3, FreeBSD 5.2.1, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-MacOS X 10.3, FreeBSD 5.2.1, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS.
@end itemize
#endif
+/* Convert a wide string to a string. */
+#if @GNULIB_WCSNRTOMBS@
+# if !@HAVE_WCSNRTOMBS@
+extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsnrtombs
+# define wcsnrtombs(d,s,n,l,p) \
+ (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
+ "use gnulib module wcsnrtombs for portability"), \
+ wcsnrtombs (d, s, n, l, p))
+#endif
+
+
/* Return the number of screen columns needed for WC. */
#if @GNULIB_WCWIDTH@
# if @REPLACE_WCWIDTH@
--- /dev/null
+/* Convert wide string to string.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ 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 <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+# include <errno.h>
+# include <stdlib.h>
+# include <string.h>
+
+
+extern mbstate_t _gl_wcsrtombs_state;
+
+size_t
+wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps)
+{
+ if (ps == NULL)
+ ps = &_gl_wcsrtombs_state;
+ {
+ const wchar_t *src = *srcp;
+ size_t cur_max = MB_CUR_MAX;
+ char buf[64];
+
+ if (!(cur_max <= sizeof (buf)))
+ abort ();
+
+ if (dest != NULL)
+ {
+ char *destptr = dest;
+
+ for (; srclen > 0 && len > 0; src++, srclen--)
+ {
+ wchar_t wc = *src;
+ size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps);
+
+ if (ret == (size_t)(-1))
+ goto bad_input;
+ if (!(ret <= cur_max))
+ abort ();
+ if (len < ret)
+ break;
+ if (len < cur_max)
+ memcpy (destptr, buf, ret);
+ if (wc == 0)
+ {
+ src = NULL;
+ /* Here mbsinit (ps). */
+ break;
+ }
+ destptr += ret;
+ len -= ret;
+ }
+ *srcp = src;
+ return destptr - dest;
+ }
+ else
+ {
+ /* Ignore dest and len, don't store *srcp at the end, and
+ don't clobber *ps. */
+ mbstate_t state = *ps;
+ size_t totalcount = 0;
+
+ for (; srclen > 0; src++, srclen--)
+ {
+ wchar_t wc = *src;
+ size_t ret = wcrtomb (buf, wc, &state);
+
+ if (ret == (size_t)(-1))
+ goto bad_input2;
+ if (wc == 0)
+ {
+ /* Here mbsinit (&state). */
+ break;
+ }
+ totalcount += ret;
+ }
+ return totalcount;
+ }
+
+ bad_input:
+ *srcp = src;
+ bad_input2:
+ errno = EILSEQ;
+ return (size_t)(-1);
+ }
+}
+
+#endif
--- /dev/null
+/* Convert wide string to string.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ 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 <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <wchar.h>
+
+/* Internal state used by the functions wcsrtombs() and wcsnrtombs(). */
+mbstate_t _gl_wcsrtombs_state;
/* Specification. */
#include <wchar.h>
-static mbstate_t internal_state;
+extern mbstate_t _gl_wcsrtombs_state;
#if HAVE_WCSRTOMBS && !WCSRTOMBS_TERMINATION_BUG
/* Override the system's wcsrtombs() function. */
rpl_wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
{
if (ps == NULL)
- ps = &internal_state;
+ ps = &_gl_wcsrtombs_state;
# if WCSRTOMBS_NULL_ARG_BUG
if (dest == NULL)
{
wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
{
if (ps == NULL)
- ps = &internal_state;
+ ps = &_gl_wcsrtombs_state;
{
const wchar_t *src = *srcp;
size_t cur_max = MB_CUR_MAX;
dnl Written by Eric Blake.
-# wchar.m4 serial 20
+# wchar.m4 serial 21
AC_DEFUN([gl_WCHAR_H],
[
GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
+ GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
+ HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
--- /dev/null
+# wcsnrtombs.m4 serial 1
+dnl Copyright (C) 2008 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_WCSNRTOMBS],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+ AC_REQUIRE([AC_TYPE_MBSTATE_T])
+ AC_CHECK_FUNCS_ONCE([wcsnrtombs])
+ if test $ac_cv_func_wcsnrtombs = no; then
+ HAVE_WCSNRTOMBS=0
+ gl_REPLACE_WCHAR_H
+ AC_LIBOBJ([wcsnrtombs])
+ AC_LIBOBJ([wcsrtombs-state])
+ gl_PREREQ_WCSNRTOMBS
+ fi
+])
+
+# Prerequisites of lib/wcsnrtombs.c.
+AC_DEFUN([gl_PREREQ_WCSNRTOMBS], [
+ :
+])
-# wcsrtombs.m4 serial 1
+# wcsrtombs.m4 serial 2
dnl Copyright (C) 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
if test $HAVE_WCSRTOMBS = 0 || test $REPLACE_WCSRTOMBS = 1; then
gl_REPLACE_WCHAR_H
AC_LIBOBJ([wcsrtombs])
+ AC_LIBOBJ([wcsrtombs-state])
gl_PREREQ_WCSRTOMBS
fi
])
-e 's|@''GNULIB_MBSNRTOWCS''@|$(GNULIB_MBSNRTOWCS)|g' \
-e 's|@''GNULIB_WCRTOMB''@|$(GNULIB_WCRTOMB)|g' \
-e 's|@''GNULIB_WCSRTOMBS''@|$(GNULIB_WCSRTOMBS)|g' \
+ -e 's|@''GNULIB_WCSNRTOMBS''@|$(GNULIB_WCSNRTOMBS)|g' \
-e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \
-e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
-e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
-e 's|@''HAVE_MBSNRTOWCS''@|$(HAVE_MBSNRTOWCS)|g' \
-e 's|@''HAVE_WCRTOMB''@|$(HAVE_WCRTOMB)|g' \
-e 's|@''HAVE_WCSRTOMBS''@|$(HAVE_WCSRTOMBS)|g' \
+ -e 's|@''HAVE_WCSNRTOMBS''@|$(HAVE_WCSNRTOMBS)|g' \
-e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
-e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
-e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \
--- /dev/null
+Description:
+wcsnrtombs() function: convert wide string to string.
+
+Files:
+lib/wcsnrtombs.c
+lib/wcsrtombs-state.c
+m4/wcsnrtombs.m4
+m4/mbstate_t.m4
+
+Depends-on:
+wchar
+wcrtomb
+
+configure.ac:
+gl_FUNC_WCSNRTOMBS
+gl_WCHAR_MODULE_INDICATOR([wcsnrtombs])
+
+Makefile.am:
+
+Include:
+<wchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
Files:
lib/wcsrtombs.c
+lib/wcsrtombs-state.c
m4/wcsrtombs.m4
m4/mbstate_t.m4
m4/locale-fr.m4