From: Bruno Haible Date: Sun, 6 Feb 2011 12:42:05 +0000 (+0100) Subject: New module 'wcsdup'. X-Git-Tag: v0.1~3228 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=5768aa52f6dd4fe3266bfa42f6a58f26b89c6c89;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 67791c22e..8411e083e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-02-06 Bruno Haible + 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 + New module 'wcsxfrm'. * modules/wcsxfrm: New file. * lib/wchar.in.h (wcsxfrm): New declaration. diff --git a/doc/posix-functions/wcsdup.texi b/doc/posix-functions/wcsdup.texi index db9289217..884549bae 100644 --- 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 diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 71bb363c3..ff55f5479 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -755,6 +755,22 @@ _GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - " #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 diff --git a/lib/wcsdup-impl.h b/lib/wcsdup-impl.h new file mode 100644 index 000000000..f721ca166 --- /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 , 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 . */ + +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; +} diff --git a/lib/wcsdup.c b/lib/wcsdup.c new file mode 100644 index 000000000..b55e63055 --- /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 , 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 + +/* Specification. */ +#include + +#include + +#include "wcsdup-impl.h" diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index 7905ce0d9..ab6f553c5 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -52,7 +52,7 @@ AC_DEFUN([gl_WCHAR_H], [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 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], 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 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], 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]) diff --git a/m4/wcsdup.m4 b/m4/wcsdup.m4 new file mode 100644 index 000000000..f3a35df54 --- /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 +]) diff --git a/modules/wchar b/modules/wchar index aaacc2276..ee967a5c2 100644 --- a/modules/wchar +++ b/modules/wchar @@ -60,6 +60,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -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 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -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' \ diff --git a/modules/wcsdup b/modules/wcsdup new file mode 100644 index 000000000..7e3cd6617 --- /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: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc index 5064f06a8..79c9b3bc6 100644 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -168,6 +168,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsxfrm, size_t, (wchar_t *, const wchar_t *, size_t)); #endif +#if GNULIB_TEST_WCSDUP +SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsdup, wchar_t *, (const wchar_t *)); +#endif + int main ()