# HG changeset patch # User Bruno Haible # Date 1298381004 -3600 # Node ID 479b128e79a2f9cf52e0b3b4360763bf5ad3282a # Parent c5f364db5d28aece613fdfdd098c3313ff85488e 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +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'. diff --git a/doc/posix-functions/wctomb.texi b/doc/posix-functions/wctomb.texi --- 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 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -738,6 +738,21 @@ # 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 --- /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 --- /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 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -63,6 +63,7 @@ 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 @@ 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 --- /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 --- a/modules/stdlib +++ b/modules/stdlib @@ -55,6 +55,7 @@ -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 @@ -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 --- a/modules/wctob +++ b/modules/wctob @@ -9,6 +9,7 @@ Depends-on: wchar +wctomb configure.ac: gl_FUNC_WCTOB diff --git a/modules/wctomb b/modules/wctomb new file mode 100644 --- /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 --- a/tests/test-stdlib-c++.cc +++ b/tests/test-stdlib-c++.cc @@ -152,6 +152,10 @@ 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 ()