From f1eb357fab17482b2d19f12fc731673acead4922 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 22 Feb 2011 14:23:24 +0100 Subject: [PATCH] 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. --- ChangeLog | 16 ++++++++++++++++ doc/posix-functions/wctomb.texi | 2 +- lib/stdlib.in.h | 15 +++++++++++++++ lib/wctomb-impl.h | 34 ++++++++++++++++++++++++++++++++++ lib/wctomb.c | 25 +++++++++++++++++++++++++ m4/stdlib_h.m4 | 2 ++ m4/wctomb.m4 | 23 +++++++++++++++++++++++ modules/stdlib | 2 ++ modules/wctob | 1 + modules/wctomb | 26 ++++++++++++++++++++++++++ tests/test-stdlib-c++.cc | 4 ++++ 11 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 lib/wctomb-impl.h create mode 100644 lib/wctomb.c create mode 100644 m4/wctomb.m4 create mode 100644 modules/wctomb diff --git a/ChangeLog b/ChangeLog index bfda52a39..a9d060b38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2011-02-22 Bruno Haible + 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 + 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 9106cce7a..2f8cfce84 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 91eb4d68c..2697a4bd1 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 000000000..4e95de638 --- /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 , 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 . */ + +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 000000000..889a3c6ff --- /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 , 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 . */ + +#include + +#include + +#include +#include + +#include "wctomb-impl.h" diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 7fa7d311d..25fdada0d 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 000000000..bc21b5b19 --- /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 c870e4d9f..d666be7f8 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 500ce6cdf..eba2ebf29 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 000000000..33a785ee1 --- /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: + + +License: +LGPLv2+ + +Maintainer: +Bruno Haible diff --git a/tests/test-stdlib-c++.cc b/tests/test-stdlib-c++.cc index 419e54700..9010c1c72 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 () -- 2.11.0