]> Savannah Git Hosting - gnulib.git/commitdiff
wmempcpy: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 31 May 2020 00:42:47 +0000 (02:42 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 31 May 2020 00:47:49 +0000 (02:47 +0200)
Reported by Paul Eggert in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00387.html>.

* lib/wchar.in.h (wmempcpy): New declaration.
* lib/wmempcpy.c: New file.
* m4/wmempcpy.m4: New file.
* m4/wchar_h.m4 (gl_WCHAR_H): Test whether wmempcpy is declared.
(gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WMEMPCPY, HAVE_WMEMPCPY.
* modules/wchar (Makefile.am): Substitute GNULIB_WMEMPCPY,
HAVE_WMEMPCPY.
* modules/wmempcpy: New file.
* tests/test-wchar-c++.cc: Check the signature of wmempcpy.
* doc/glibc-functions/wmempcpy.texi: Mention the new module.
* modules/mempcpy (Description): Fix typo.

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

index 4b39c3d378ec303969a81b09c361a59670cabcd1..b396b3c1955be75ffb9797022111afd5c2707718 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2020-05-30  Bruno Haible  <bruno@clisp.org>
+
+       wmempcpy: New module.
+       Reported by Paul Eggert in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00387.html>.
+       * lib/wchar.in.h (wmempcpy): New declaration.
+       * lib/wmempcpy.c: New file.
+       * m4/wmempcpy.m4: New file.
+       * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wmempcpy is declared.
+       (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WMEMPCPY, HAVE_WMEMPCPY.
+       * modules/wchar (Makefile.am): Substitute GNULIB_WMEMPCPY,
+       HAVE_WMEMPCPY.
+       * modules/wmempcpy: New file.
+       * tests/test-wchar-c++.cc: Check the signature of wmempcpy.
+       * doc/glibc-functions/wmempcpy.texi: Mention the new module.
+       * modules/mempcpy (Description): Fix typo.
+
 2020-05-30  Bruno Haible  <bruno@clisp.org>
 
        crypto/gc-random: Fix list of crypto devices for NetBSD, OpenBSD.
index da5b4d2cf46cd8e2a578b3ffa554f754bb58a0bb..be7e782d5bae2e62ed165c4597371d1aa5913c32 100644 (file)
@@ -15,18 +15,18 @@ Documentation:
 @uref{https://www.kernel.org/doc/man-pages/online/pages/man3/wmempcpy.3.html,,man wmempcpy}.
 @end itemize
 
-Gnulib module: ---
+Gnulib module: wmempcpy
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on many non-glibc platforms:
+Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin, mingw, MSVC 14, Android 5.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on many non-glibc platforms:
-Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin, mingw, MSVC 14, Android 5.1.
-@item
 On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
 @end itemize
index e1fa92f27b5b18636605bba32f4a0068de6b8e93..bfcf611df64801d694beebb4ada4c3bf9472984d 100644 (file)
@@ -624,6 +624,29 @@ _GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - "
 #endif
 
 
+/* Copy N wide characters of SRC to DEST.
+   Return pointer to wide characters after the last written wide character.  */
+#if @GNULIB_WMEMPCPY@
+# if !@HAVE_WMEMPCPY@
+_GL_FUNCDECL_SYS (wmempcpy, wchar_t *,
+                  (wchar_t *restrict dest,
+                   const wchar_t *restrict src, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wmempcpy, wchar_t *,
+                  (wchar_t *restrict dest,
+                   const wchar_t *restrict src, size_t n));
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (wmempcpy);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wmempcpy
+# if HAVE_RAW_DECL_WMEMPCPY
+_GL_WARN_ON_USE (wmempcpy, "wmempcpy is unportable - "
+                 "use gnulib module wmempcpy for portability");
+# endif
+#endif
+
+
 /* Set N wide characters of S to C.  */
 #if @GNULIB_WMEMSET@
 # if !@HAVE_WMEMSET@
diff --git a/lib/wmempcpy.c b/lib/wmempcpy.c
new file mode 100644 (file)
index 0000000..9161c65
--- /dev/null
@@ -0,0 +1,28 @@
+/* Copy wide character array, return pointer after last written wide character.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   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 2, 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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+/* Copy N wide characters of SRC to DEST.
+   Return pointer to wide characters after the last written wide character.  */
+wchar_t *
+wmempcpy (wchar_t *dest, const wchar_t *src, size_t n)
+{
+  return wmemcpy (dest, src, n) + n;
+}
index be09020b17cf317da222cf93e2d734dfc79c61ca..6c4e8a6c4aff3930693ea2e432192967aa8e1d2f 100644 (file)
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 dnl Written by Eric Blake.
 
-# wchar_h.m4 serial 45
+# wchar_h.m4 serial 46
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -52,7 +52,8 @@ AC_DEFUN([gl_WCHAR_H],
 #include <wchar.h>
     ]],
     [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
-     wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset
+     wcsrtombs wcsnrtombs wcwidth
+     wmemchr wmemcmp wmemcpy wmemmove wmempcpy wmemset
      wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
      wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
      wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
@@ -159,6 +160,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   GNULIB_WMEMCMP=0;     AC_SUBST([GNULIB_WMEMCMP])
   GNULIB_WMEMCPY=0;     AC_SUBST([GNULIB_WMEMCPY])
   GNULIB_WMEMMOVE=0;    AC_SUBST([GNULIB_WMEMMOVE])
+  GNULIB_WMEMPCPY=0;    AC_SUBST([GNULIB_WMEMPCPY])
   GNULIB_WMEMSET=0;     AC_SUBST([GNULIB_WMEMSET])
   GNULIB_WCSLEN=0;      AC_SUBST([GNULIB_WCSLEN])
   GNULIB_WCSNLEN=0;     AC_SUBST([GNULIB_WCSNLEN])
@@ -198,6 +200,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   HAVE_WMEMCMP=1;       AC_SUBST([HAVE_WMEMCMP])
   HAVE_WMEMCPY=1;       AC_SUBST([HAVE_WMEMCPY])
   HAVE_WMEMMOVE=1;      AC_SUBST([HAVE_WMEMMOVE])
+  HAVE_WMEMPCPY=1;      AC_SUBST([HAVE_WMEMPCPY])
   HAVE_WMEMSET=1;       AC_SUBST([HAVE_WMEMSET])
   HAVE_WCSLEN=1;        AC_SUBST([HAVE_WCSLEN])
   HAVE_WCSNLEN=1;       AC_SUBST([HAVE_WCSNLEN])
diff --git a/m4/wmempcpy.m4 b/m4/wmempcpy.m4
new file mode 100644 (file)
index 0000000..1795fc8
--- /dev/null
@@ -0,0 +1,21 @@
+# wmempcpy.m4 serial 1
+dnl Copyright (C) 2020 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_WMEMPCPY],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  dnl Persuade glibc <wchar.h> to declare wmempcpy().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  dnl The wmempcpy() declaration in lib/wchar.in.h uses 'restrict'.
+  AC_REQUIRE([AC_C_RESTRICT])
+
+  AC_CHECK_FUNCS_ONCE([wmempcpy])
+  if test $ac_cv_func_wmempcpy = no; then
+    HAVE_WMEMPCPY=0
+  fi
+])
index 9af465493c5ae188db9ec3498baff701cb68d075..59009aaeb05f44d8c42622c1b37c397573f23617 100644 (file)
@@ -1,5 +1,5 @@
 Description:
-mempcpy() function: copy memory area, return point after last written byte.
+mempcpy() function: copy memory area, return pointer after last written byte.
 
 Files:
 lib/mempcpy.c
index cd4464b069a9b2cc039177def7bfbbc5f46bc7cd..a028f65cfd5b20c546cc8881c04d9808e31fbad2 100644 (file)
@@ -50,6 +50,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's/@''GNULIB_WMEMCMP''@/$(GNULIB_WMEMCMP)/g' \
              -e 's/@''GNULIB_WMEMCPY''@/$(GNULIB_WMEMCPY)/g' \
              -e 's/@''GNULIB_WMEMMOVE''@/$(GNULIB_WMEMMOVE)/g' \
+             -e 's/@''GNULIB_WMEMPCPY''@/$(GNULIB_WMEMPCPY)/g' \
              -e 's/@''GNULIB_WMEMSET''@/$(GNULIB_WMEMSET)/g' \
              -e 's/@''GNULIB_WCSLEN''@/$(GNULIB_WCSLEN)/g' \
              -e 's/@''GNULIB_WCSNLEN''@/$(GNULIB_WCSNLEN)/g' \
@@ -90,6 +91,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \
              -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \
              -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \
+             -e 's|@''HAVE_WMEMPCPY''@|$(HAVE_WMEMPCPY)|g' \
              -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \
              -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \
              -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \
diff --git a/modules/wmempcpy b/modules/wmempcpy
new file mode 100644 (file)
index 0000000..edb4c5f
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+wmempcpy() function: copy wide character array, return pointer after last written wide character.
+
+Files:
+lib/wmempcpy.c
+m4/wmempcpy.m4
+
+Depends-on:
+wchar
+
+configure.ac:
+gl_FUNC_WMEMPCPY
+if test $HAVE_WMEMPCPY = 0; then
+  AC_LIBOBJ([wmempcpy])
+fi
+gl_WCHAR_MODULE_INDICATOR([wmempcpy])
+
+Makefile.am:
+
+Include:
+<wchar.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index 63480b1e5b97e28b2f03d80c89f4b3cb077d078d..3b9ba4be02d2f38453aaeee91acc84e7209f8020 100644 (file)
@@ -95,6 +95,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wmemmove, wchar_t *,
                  (wchar_t *, const wchar_t *, size_t));
 #endif
 
+#if GNULIB_TEST_WMEMPCPY
+SIGNATURE_CHECK (GNULIB_NAMESPACE::wmempcpy, wchar_t *,
+                 (wchar_t *, const wchar_t *, size_t));
+#endif
+
 #if GNULIB_TEST_WMEMSET
 SIGNATURE_CHECK (GNULIB_NAMESPACE::wmemset, wchar_t *,
                  (wchar_t *, wchar_t, size_t));