>From 68935ae95b339a42ee955be00aa7921bd37916ba Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 May 2020 02:42:47 +0200 Subject: [PATCH 1/2] wmempcpy: New module. Reported by Paul Eggert in . * 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 | 17 +++++++++++++++++ doc/glibc-functions/wmempcpy.texi | 8 ++++---- lib/wchar.in.h | 23 +++++++++++++++++++++++ lib/wmempcpy.c | 28 ++++++++++++++++++++++++++++ m4/wchar_h.m4 | 7 +++++-- m4/wmempcpy.m4 | 21 +++++++++++++++++++++ modules/mempcpy | 2 +- modules/wchar | 2 ++ modules/wmempcpy | 27 +++++++++++++++++++++++++++ tests/test-wchar-c++.cc | 5 +++++ 10 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 lib/wmempcpy.c create mode 100644 m4/wmempcpy.m4 create mode 100644 modules/wmempcpy diff --git a/ChangeLog b/ChangeLog index 4b39c3d3..b396b3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,22 @@ 2020-05-30 Bruno Haible + wmempcpy: New module. + Reported by Paul Eggert in + . + * 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 + crypto/gc-random: Fix list of crypto devices for NetBSD, OpenBSD. * m4/gc-random.m4 (gl_GC_RANDOM): Don't special-case NetBSD and OpenBSD. diff --git a/doc/glibc-functions/wmempcpy.texi b/doc/glibc-functions/wmempcpy.texi index da5b4d2..be7e782 100644 --- a/doc/glibc-functions/wmempcpy.texi +++ b/doc/glibc-functions/wmempcpy.texi @@ -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 diff --git a/lib/wchar.in.h b/lib/wchar.in.h index e1fa92f..bfcf611 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -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 index 0000000..9161c65 --- /dev/null +++ b/lib/wmempcpy.c @@ -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 . */ + +#include + +/* Specification. */ +#include + +/* 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; +} diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index be09020..6c4e8a6 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -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 ]], [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 index 0000000..1795fc8 --- /dev/null +++ b/m4/wmempcpy.m4 @@ -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 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 +]) diff --git a/modules/mempcpy b/modules/mempcpy index 9af4654..59009aa 100644 --- a/modules/mempcpy +++ b/modules/mempcpy @@ -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 diff --git a/modules/wchar b/modules/wchar index cd4464b..a028f65 100644 --- a/modules/wchar +++ b/modules/wchar @@ -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 index 0000000..edb4c5f --- /dev/null +++ b/modules/wmempcpy @@ -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: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc index 63480b1..3b9ba4b 100644 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -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)); -- 2.7.4