summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--doc/posix-functions/wctomb.texi2
-rw-r--r--lib/stdlib.in.h15
-rw-r--r--lib/wctomb-impl.h34
-rw-r--r--lib/wctomb.c25
-rw-r--r--m4/stdlib_h.m42
-rw-r--r--m4/wctomb.m423
-rw-r--r--modules/stdlib2
-rw-r--r--modules/wctob1
-rw-r--r--modules/wctomb26
-rw-r--r--tests/test-stdlib-c++.cc4
11 files changed, 149 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index bfda52a39c..a9d060b38f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2011-02-22 Bruno Haible <bruno@clisp.org>
+ New module 'wctomb'.
+ * lib/stdlib.in.h (wctomb): New declaration.
+ * lib/wctomb.c: New file.
+ * lib/wctomb-impl.h: New file.
+ * m4/wctomb.m4: New file.
+ * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_WCTOMB,
+ REPLACE_WCTOMB.
+ * modules/stdlib (Makefile.am): Substitute GNULIB_WCTOMB,
+ REPLACE_WCTOMB.
+ * modules/wctomb: New file.
+ * tests/test-stdlib-c++.cc: Test signature of wctomb.
+ * doc/posix-functions/wctomb.texi: Mention the new module.
+ * modules/wctob (Depends-on): Add wctomb.
+
+2011-02-22 Bruno Haible <bruno@clisp.org>
+
New module 'mbtowc'.
* lib/stdlib.in.h (mbtowc): New declaration.
* lib/mbtowc.c: New file.
diff --git a/doc/posix-functions/wctomb.texi b/doc/posix-functions/wctomb.texi
index 9106cce7aa..2f8cfce847 100644
--- a/doc/posix-functions/wctomb.texi
+++ b/doc/posix-functions/wctomb.texi
@@ -4,7 +4,7 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wctomb.html}
-Gnulib module: ---
+Gnulib module: wctomb
Portability problems fixed by Gnulib:
@itemize
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 91eb4d68c1..2697a4bd1d 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -738,6 +738,21 @@ _GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - "
# endif
#endif
+/* Convert a wide character to a multibyte character. */
+#if @GNULIB_WCTOMB@
+# if @REPLACE_WCTOMB@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef wctomb
+# define wctomb rpl_wctomb
+# endif
+_GL_FUNCDECL_RPL (wctomb, int, (char *s, wchar_t wc));
+_GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc));
+# else
+_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc));
+# endif
+_GL_CXXALIASWARN (wctomb);
+#endif
+
#endif /* _GL_STDLIB_H */
#endif /* _GL_STDLIB_H */
diff --git a/lib/wctomb-impl.h b/lib/wctomb-impl.h
new file mode 100644
index 0000000000..4e95de6383
--- /dev/null
+++ b/lib/wctomb-impl.h
@@ -0,0 +1,34 @@
+/* Convert wide character to multibyte character.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ 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/>. */
+
+int
+wctomb (char *s, wchar_t wc)
+{
+ if (s == NULL)
+ return 0;
+ else
+ {
+ mbstate_t state;
+ size_t result;
+
+ memset (&state, 0, sizeof (mbstate_t));
+ result = wcrtomb (s, wc, &state);
+ if (result == (size_t)-1)
+ return -1;
+ return result;
+ }
+}
diff --git a/lib/wctomb.c b/lib/wctomb.c
new file mode 100644
index 0000000000..889a3c6fff
--- /dev/null
+++ b/lib/wctomb.c
@@ -0,0 +1,25 @@
+/* Convert wide character to multibyte character.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ 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 <stdlib.h>
+
+#include <string.h>
+#include <wchar.h>
+
+#include "wctomb-impl.h"
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index 7fa7d311db..25fdada0de 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -63,6 +63,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
GNULIB_SYSTEM_POSIX=0; AC_SUBST([GNULIB_SYSTEM_POSIX])
GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
+ GNULIB_WCTOMB=0; AC_SUBST([GNULIB_WCTOMB])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
@@ -100,4 +101,5 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV])
+ REPLACE_WCTOMB=0; AC_SUBST([REPLACE_WCTOMB])
])
diff --git a/m4/wctomb.m4 b/m4/wctomb.m4
new file mode 100644
index 0000000000..bc21b5b19f
--- /dev/null
+++ b/m4/wctomb.m4
@@ -0,0 +1,23 @@
+# wctomb.m4 serial 1
+dnl Copyright (C) 2011 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_WCTOMB],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+ if false; then
+ REPLACE_WCTOMB=1
+ fi
+ if test $REPLACE_WCTOMB = 1; then
+ AC_LIBOBJ([wctomb])
+ gl_PREREQ_WCTOMB
+ fi
+])
+
+# Prerequisites of lib/wctomb.c.
+AC_DEFUN([gl_PREREQ_WCTOMB], [
+ :
+])
diff --git a/modules/stdlib b/modules/stdlib
index c870e4d9f9..d666be7f89 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -55,6 +55,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_SYSTEM_POSIX''@|$(GNULIB_SYSTEM_POSIX)|g' \
-e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \
-e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+ -e 's|@''GNULIB_WCTOMB''@|$(GNULIB_WCTOMB)|g' \
< $(srcdir)/stdlib.in.h | \
sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
-e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
@@ -91,6 +92,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
-e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
-e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
+ -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
-e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
-e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
diff --git a/modules/wctob b/modules/wctob
index 500ce6cdf7..eba2ebf293 100644
--- a/modules/wctob
+++ b/modules/wctob
@@ -9,6 +9,7 @@ m4/codeset.m4
Depends-on:
wchar
+wctomb
configure.ac:
gl_FUNC_WCTOB
diff --git a/modules/wctomb b/modules/wctomb
new file mode 100644
index 0000000000..33a785ee13
--- /dev/null
+++ b/modules/wctomb
@@ -0,0 +1,26 @@
+Description:
+wctomb() function: convert wide character to multibyte character.
+
+Files:
+lib/wctomb.c
+lib/wctomb-impl.h
+m4/wctomb.m4
+
+Depends-on:
+stdlib
+wcrtomb
+
+configure.ac:
+gl_FUNC_WCTOMB
+gl_STDLIB_MODULE_INDICATOR([wctomb])
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Bruno Haible
diff --git a/tests/test-stdlib-c++.cc b/tests/test-stdlib-c++.cc
index 419e547002..9010c1c725 100644
--- a/tests/test-stdlib-c++.cc
+++ b/tests/test-stdlib-c++.cc
@@ -152,6 +152,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::unlockpt, int, (int));
SIGNATURE_CHECK (GNULIB_NAMESPACE::unsetenv, int, (const char *));
#endif
+#if GNULIB_TEST_WCTOMB
+SIGNATURE_CHECK (GNULIB_NAMESPACE::wctomb, int, (char *, wchar_t));
+#endif
+
int
main ()