Mercurial > hg > octave-lojdl > gnulib-hg
changeset 14378:479b128e79a2
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 22 Feb 2011 14:23:24 +0100 |
parents | c5f364db5d28 |
children | 2330aac2ae54 |
files | ChangeLog doc/posix-functions/wctomb.texi lib/stdlib.in.h lib/wctomb-impl.h lib/wctomb.c m4/stdlib_h.m4 m4/wctomb.m4 modules/stdlib modules/wctob modules/wctomb tests/test-stdlib-c++.cc |
diffstat | 11 files changed, 149 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +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'.
--- 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
--- 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 */
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 <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; + } +}
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 <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"
--- 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]) ])
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], [ + : +])
--- 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)'; \
--- a/modules/wctob +++ b/modules/wctob @@ -9,6 +9,7 @@ Depends-on: wchar +wctomb configure.ac: gl_FUNC_WCTOB
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: +<stdlib.h> + +License: +LGPLv2+ + +Maintainer: +Bruno Haible