bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'wcrtomb'


From: Bruno Haible
Subject: new module 'wcrtomb'
Date: Sun, 21 Dec 2008 16:58:11 +0100
User-agent: KMail/1.9.9

The next function is wcrtomb().

2008-12-21  Bruno Haible  <address@hidden>

        * lib/wchar.in.h (wcrtomb): New declaration.
        * lib/wcrtomb.c: New file.
        * m4/wcrtomb.m4: New file.
        * m4/wchar.m4 (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCRTOMB,
        HAVE_WCRTOMB.
        * modules/wchar (Makefile.am): Substitute GNULIB_WCRTOMB,
        HAVE_WCRTOMB.
        * modules/wcrtomb: New file.
        * doc/posix-functions/wcrtomb.texi: Mention the new module.

================================ lib/wcrtomb.c ================================
/* Convert wide character to multibyte character.
   Copyright (C) 2008 Free Software Foundation, Inc.
   Written by Bruno Haible <address@hidden>, 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>


size_t
wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
{
  /* This implementation of wcrtomb on top of wctomb() supports only
     stateless encodings.  ps must be in the initial state.  */
  if (ps != NULL && !mbsinit (ps))
    {
      errno = EINVAL;
      return (size_t)(-1);
    }

  if (s == NULL)
    /* We know the NUL wide character corresponds to the NUL character.  */
    return 1;
  else
    {
      int ret = wctomb (s, wc);

      if (ret >= 0)
        return ret;
      else
        {
          errno = EILSEQ;
          return (size_t)(-1);
        }
    }
}
================================ m4/wcrtomb.m4 ================================
# wcrtomb.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_WCRTOMB],
[
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])

  AC_REQUIRE([AC_TYPE_MBSTATE_T])
  AC_CHECK_FUNCS_ONCE([wcrtomb])
  if test $ac_cv_func_wcrtomb = no; then
    HAVE_WCRTOMB=0
    gl_REPLACE_WCHAR_H
    AC_LIBOBJ([wcrtomb])
    gl_PREREQ_WCRTOMB
  fi
])

# Prerequisites of lib/wcrtomb.c.
AC_DEFUN([gl_PREREQ_WCRTOMB], [
  :
])
=============================== modules/wcrtomb ===============================
Description:
wcrtomb() function: convert wide character to multibyte character.

Files:
lib/wcrtomb.c
m4/wcrtomb.m4
m4/mbstate_t.m4

Depends-on:
wchar
mbsinit

configure.ac:
gl_FUNC_WCRTOMB
gl_WCHAR_MODULE_INDICATOR([wcrtomb])

Makefile.am:

Include:
<wchar.h>

License:
LGPL

Maintainer:
Bruno Haible

===============================================================================
--- lib/wchar.in.h.orig 2008-12-21 16:57:07.000000000 +0100
+++ lib/wchar.in.h      2008-12-21 16:20:16.000000000 +0100
@@ -201,6 +201,20 @@
 #endif
 
 
+/* Convert a wide character to a multibyte character.  */
+#if @GNULIB_WCRTOMB@
+# if address@hidden@
+extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcrtomb
+# define wcrtomb(s,w,p) \
+    (GL_LINK_WARNING ("wcrtomb is unportable - " \
+                      "use gnulib module wcrtomb for portability"), \
+     wcrtomb (s, w, p))
+#endif
+
+
 /* Return the number of screen columns needed for WC.  */
 #if @GNULIB_WCWIDTH@
 # if @REPLACE_WCWIDTH@
--- m4/wchar.m4.orig    2008-12-21 16:57:07.000000000 +0100
+++ m4/wchar.m4 2008-12-21 16:20:16.000000000 +0100
@@ -7,7 +7,7 @@
 
 dnl Written by Eric Blake.
 
-# wchar.m4 serial 16
+# wchar.m4 serial 17
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -68,6 +68,7 @@
   GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
   GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
   GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
+  GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
   GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_BTOWC=1;        AC_SUBST([HAVE_BTOWC])
@@ -76,6 +77,7 @@
   HAVE_MBRLEN=1;       AC_SUBST([HAVE_MBRLEN])
   HAVE_MBSRTOWCS=1;    AC_SUBST([HAVE_MBSRTOWCS])
   HAVE_MBSNRTOWCS=1;   AC_SUBST([HAVE_MBSNRTOWCS])
+  HAVE_WCRTOMB=1;      AC_SUBST([HAVE_WCRTOMB])
   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])
--- modules/wchar.orig  2008-12-21 16:57:07.000000000 +0100
+++ modules/wchar       2008-12-21 16:20:16.000000000 +0100
@@ -32,6 +32,7 @@
              -e 's|@''GNULIB_MBRLEN''@|$(GNULIB_MBRLEN)|g' \
              -e 's|@''GNULIB_MBSRTOWCS''@|$(GNULIB_MBSRTOWCS)|g' \
              -e 's|@''GNULIB_MBSNRTOWCS''@|$(GNULIB_MBSNRTOWCS)|g' \
+             -e 's|@''GNULIB_WCRTOMB''@|$(GNULIB_WCRTOMB)|g' \
              -e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \
              -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
              -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
@@ -40,6 +41,7 @@
              -e 's|@''HAVE_MBRLEN''@|$(HAVE_MBRLEN)|g' \
              -e 's|@''HAVE_MBSRTOWCS''@|$(HAVE_MBSRTOWCS)|g' \
              -e 's|@''HAVE_MBSNRTOWCS''@|$(HAVE_MBSNRTOWCS)|g' \
+             -e 's|@''HAVE_WCRTOMB''@|$(HAVE_WCRTOMB)|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' \
--- doc/posix-functions/wcrtomb.texi.orig       2008-12-21 16:57:07.000000000 
+0100
+++ doc/posix-functions/wcrtomb.texi    2008-12-21 16:56:55.000000000 +0100
@@ -4,18 +4,18 @@
 
 POSIX specification: 
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcrtomb.html}
 
-Gnulib module: ---
+Gnulib module: wcrtomb
 
 Portability problems fixed by Gnulib:
 @itemize
address@hidden
+This function is missing on some platforms:
+HP-UX 11.00, IRIX 6.5, Solaris 2.6, mingw, Interix 3.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-HP-UX 11.00, IRIX 6.5, Solaris 2.6, mingw, Interix 3.5.
address@hidden
 On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore 
cannot
 accommodate all Unicode characters.
 @end itemize




reply via email to

[Prev in Thread] Current Thread [Next in Thread]