New module 'wcsdup'.
authorBruno Haible <bruno@clisp.org>
Sun, 6 Feb 2011 12:42:05 +0000 (13:42 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 7 Feb 2011 22:36:06 +0000 (23:36 +0100)
* 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.

ChangeLog
doc/posix-functions/wcsdup.texi
lib/wchar.in.h
lib/wcsdup-impl.h [new file with mode: 0644]
lib/wcsdup.c [new file with mode: 0644]
m4/wchar_h.m4
m4/wcsdup.m4 [new file with mode: 0644]
modules/wchar
modules/wcsdup [new file with mode: 0644]
tests/test-wchar-c++.cc

index 67791c2..8411e08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 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'.
        * modules/wcsxfrm: New file.
        * lib/wchar.in.h (wcsxfrm): New declaration.
index db92892..884549b 100644 (file)
@@ -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
index 71bb363..ff55f54 100644 (file)
@@ -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 (file)
index 0000000..f721ca1
--- /dev/null
@@ -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;
+}
diff --git a/lib/wcsdup.c b/lib/wcsdup.c
new file mode 100644 (file)
index 0000000..b55e630
--- /dev/null
@@ -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"
index 7905ce0..ab6f553 100644 (file)
@@ -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 (file)
index 0000000..f3a35df
--- /dev/null
@@ -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
+])
index aaacc22..ee967a5 100644 (file)
@@ -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 (file)
index 0000000..7e3cd66
--- /dev/null
@@ -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
index 5064f06..79c9b3b 100644 (file)
@@ -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 ()