Mercurial > hg > octave-nkf > gnulib-hg
changeset 14295:34809a158a33
New module 'wcsdup'.
* modules/wcsdup: New file.
* lib/wchar.in.h (wcsdup): New declaration.
* lib/wcsdup.c: New file.
* lib/wcsdup-impl.h: New file, from libutf8 with modifications.
* m4/wcsdup.m4: New file.
* m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsdup is declared.
(gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSDUP, HAVE_WCSDUP.
* modules/wchar (Makefile.am): Substitute GNULIB_WCSDUP, HAVE_WCSDUP.
* tests/test-wchar-c++.cc: Test the declaration of wcsdup.
* doc/posix-functions/wcsdup.texi: Mention the new module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 06 Feb 2011 13:42:05 +0100 |
parents | b19db9397852 |
children | 932d02b6b200 |
files | ChangeLog doc/posix-functions/wcsdup.texi lib/wchar.in.h lib/wcsdup-impl.h lib/wcsdup.c m4/wchar_h.m4 m4/wcsdup.m4 modules/wchar modules/wcsdup tests/test-wchar-c++.cc |
diffstat | 10 files changed, 140 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-02-06 Bruno Haible <bruno@clisp.org> + + New module 'wcsdup'. + * modules/wcsdup: New file. + * lib/wchar.in.h (wcsdup): New declaration. + * lib/wcsdup.c: New file. + * lib/wcsdup-impl.h: New file, from libutf8 with modifications. + * m4/wcsdup.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsdup is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSDUP, HAVE_WCSDUP. + * modules/wchar (Makefile.am): Substitute GNULIB_WCSDUP, HAVE_WCSDUP. + * tests/test-wchar-c++.cc: Test the declaration of wcsdup. + * doc/posix-functions/wcsdup.texi: Mention the new module. + 2011-02-06 Bruno Haible <bruno@clisp.org> New module 'wcsxfrm'.
--- a/doc/posix-functions/wcsdup.texi +++ b/doc/posix-functions/wcsdup.texi @@ -4,19 +4,19 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsdup.html} -Gnulib module: --- +Gnulib module: wcsdup Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +MacOS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX 11, +IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -MacOS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX -11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, BeOS. -@item On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot accommodate all Unicode characters. @end itemize
--- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -755,6 +755,22 @@ #endif +/* Duplicate S, returning an identical malloc'd string. */ +#if @GNULIB_WCSDUP@ +# if !@HAVE_WCSDUP@ +_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s)); +# endif +_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); +_GL_CXXALIASWARN (wcsdup); +#elif defined GNULIB_POSIXCHECK +# undef wcsdup +# if HAVE_RAW_DECL_WCSDUP +_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - " + "use gnulib module wcsdup for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif
new file mode 100644 --- /dev/null +++ b/lib/wcsdup-impl.h @@ -0,0 +1,29 @@ +/* Duplicate a wide string. + Copyright (C) 1999, 2011 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 1999. + + 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/>. */ + +wchar_t * +wcsdup (const wchar_t *s) +{ + size_t n = wcslen (s) + 1; + wchar_t *copy = (wchar_t *) malloc (n * sizeof (wchar_t)); + if (copy != NULL) + return wmemcpy (copy, s, n); + else + /* The glibc documentation does not say that errno should be set to ENOMEM + here. */ + return NULL; +}
new file mode 100644 --- /dev/null +++ b/lib/wcsdup.c @@ -0,0 +1,25 @@ +/* Duplicate a wide string. + 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> + +/* Specification. */ +#include <wchar.h> + +#include <stdlib.h> + +#include "wcsdup-impl.h"
--- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -52,7 +52,7 @@ [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp - wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm + wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup ]) ]) @@ -166,6 +166,7 @@ GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP]) GNULIB_WCSCOLL=0; AC_SUBST([GNULIB_WCSCOLL]) GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM]) + GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -195,6 +196,7 @@ HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP]) HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL]) HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM]) + HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP]) 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])
new file mode 100644 --- /dev/null +++ b/m4/wcsdup.m4 @@ -0,0 +1,15 @@ +# wcsdup.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_WCSDUP], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([wcsdup]) + if test $ac_cv_func_wcsdup = no; then + HAVE_WCSDUP=0 + AC_LIBOBJ([wcsdup]) + fi +])
--- a/modules/wchar +++ b/modules/wchar @@ -60,6 +60,7 @@ -e 's|@''GNULIB_WCSNCASECMP''@|$(GNULIB_WCSNCASECMP)|g' \ -e 's|@''GNULIB_WCSCOLL''@|$(GNULIB_WCSCOLL)|g' \ -e 's|@''GNULIB_WCSXFRM''@|$(GNULIB_WCSXFRM)|g' \ + -e 's|@''GNULIB_WCSDUP''@|$(GNULIB_WCSDUP)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -89,6 +90,7 @@ -e 's|@''HAVE_WCSNCASECMP''@|$(HAVE_WCSNCASECMP)|g' \ -e 's|@''HAVE_WCSCOLL''@|$(HAVE_WCSCOLL)|g' \ -e 's|@''HAVE_WCSXFRM''@|$(HAVE_WCSXFRM)|g' \ + -e 's|@''HAVE_WCSDUP''@|$(HAVE_WCSDUP)|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' \
new file mode 100644 --- /dev/null +++ b/modules/wcsdup @@ -0,0 +1,27 @@ +Description: +wcsdup() function: duplicate a wide string. + +Files: +lib/wcsdup.c +lib/wcsdup-impl.h +m4/wcsdup.m4 + +Depends-on: +wchar +wcslen +wmemcpy + +configure.ac: +gl_FUNC_WCSDUP +gl_WCHAR_MODULE_INDICATOR([wcsdup]) + +Makefile.am: + +Include: +<wchar.h> + +License: +LGPL + +Maintainer: +Bruno Haible