From 994d0a366350f2a8f2f54d5dcd2c0a7d3de9a904 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 5 Feb 2011 13:07:51 +0100 Subject: [PATCH] New module 'wmemmove'. * modules/wmemmove: New file. * lib/wchar.in.h (wmemmove): New declaration. * lib/wmemmove.c: New file. * lib/wmemmove-impl.h: New file, from libutf8 with modifications. * m4/wmemmove.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wmemmove is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WMEMMOVE, HAVE_WMEMMOVE. * modules/wchar (Makefile.am): Substitute GNULIB_WMEMMOVE, HAVE_WMEMMOVE. * tests/test-wchar-c++.cc: Test the declaration of wmemmove. * doc/posix-functions/wmemmove.texi: Mention the new module. --- ChangeLog | 15 +++++++++++++ doc/posix-functions/wmemmove.texi | 8 +++---- lib/wchar.in.h | 19 ++++++++++++++++ lib/wmemmove-impl.h | 36 +++++++++++++++++++++++++++++++ lib/wmemmove.c | 23 ++++++++++++++++++++ m4/wchar_h.m4 | 4 +++- m4/wmemmove.m4 | 15 +++++++++++++ modules/wchar | 2 ++ modules/wmemmove | 25 +++++++++++++++++++++ tests/test-wchar-c++.cc | 5 +++++ 10 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 lib/wmemmove-impl.h create mode 100644 lib/wmemmove.c create mode 100644 m4/wmemmove.m4 create mode 100644 modules/wmemmove diff --git a/ChangeLog b/ChangeLog index 6fc04860c8..b431bb36f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-02-05 Bruno Haible + + New module 'wmemmove'. + * modules/wmemmove: New file. + * lib/wchar.in.h (wmemmove): New declaration. + * lib/wmemmove.c: New file. + * lib/wmemmove-impl.h: New file, from libutf8 with modifications. + * m4/wmemmove.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wmemmove is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WMEMMOVE, HAVE_WMEMMOVE. + * modules/wchar (Makefile.am): Substitute GNULIB_WMEMMOVE, + HAVE_WMEMMOVE. + * tests/test-wchar-c++.cc: Test the declaration of wmemmove. + * doc/posix-functions/wmemmove.texi: Mention the new module. + 2011-02-05 Bruno Haible New module 'wmemcpy'. diff --git a/doc/posix-functions/wmemmove.texi b/doc/posix-functions/wmemmove.texi index fe6a7c56df..ae4a08ecda 100644 --- a/doc/posix-functions/wmemmove.texi +++ b/doc/posix-functions/wmemmove.texi @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wmemmove.html} -Gnulib module: --- +Gnulib module: wmemmove Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +HP-UX 11.00, IRIX 6.5, Solaris 2.6, Interix 3.5. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -HP-UX 11.00, IRIX 6.5, Solaris 2.6, Interix 3.5. -@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 3ec14cc6c1..89031ecf5a 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -482,6 +482,25 @@ _GL_WARN_ON_USE (wmemcpy, "wmemcpy is unportable - " #endif +/* Copy N wide characters of SRC to DEST, guaranteeing correct behavior for + overlapping memory areas. */ +#if @GNULIB_WMEMMOVE@ +# if !@HAVE_WMEMMOVE@ +_GL_FUNCDECL_SYS (wmemmove, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +# endif +_GL_CXXALIAS_SYS (wmemmove, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +_GL_CXXALIASWARN (wmemmove); +#elif defined GNULIB_POSIXCHECK +# undef wmemmove +# if HAVE_RAW_DECL_WMEMMOVE +_GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - " + "use gnulib module wmemmove for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif diff --git a/lib/wmemmove-impl.h b/lib/wmemmove-impl.h new file mode 100644 index 0000000000..4ecdcbed06 --- /dev/null +++ b/lib/wmemmove-impl.h @@ -0,0 +1,36 @@ +/* Copy wide character array. + 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 * +wmemmove (wchar_t *dest, const wchar_t *src, size_t n) +{ + if (dest < src) + { + wchar_t *destptr = dest; + const wchar_t *srcptr = src; + for (; n > 0; n--) + *destptr++ = *srcptr++; + } + else if (dest > src) + { + wchar_t *destptr = dest + n - 1; + const wchar_t *srcptr = src + n - 1; + for (; n > 0; n--) + *destptr-- = *srcptr--; + } + return dest; +} diff --git a/lib/wmemmove.c b/lib/wmemmove.c new file mode 100644 index 0000000000..3edaa0c8df --- /dev/null +++ b/lib/wmemmove.c @@ -0,0 +1,23 @@ +/* Copy wide character array. + 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 "wmemmove-impl.h" diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index f5222475e5..591c2fc244 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -50,7 +50,7 @@ AC_DEFUN([gl_WCHAR_H], #include ]], [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb - wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy + wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove ]) ]) @@ -148,6 +148,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR]) GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP]) GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY]) + GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -161,6 +162,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR]) HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP]) HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY]) + HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE]) 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/wmemmove.m4 b/m4/wmemmove.m4 new file mode 100644 index 0000000000..2b4daad195 --- /dev/null +++ b/m4/wmemmove.m4 @@ -0,0 +1,15 @@ +# wmemmove.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_WMEMMOVE], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([wmemmove]) + if test $ac_cv_func_wmemmove = no; then + HAVE_WMEMMOVE=0 + AC_LIBOBJ([wmemmove]) + fi +]) diff --git a/modules/wchar b/modules/wchar index fbe9e469d1..8789cdf626 100644 --- a/modules/wchar +++ b/modules/wchar @@ -44,6 +44,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_WMEMCHR''@|$(GNULIB_WMEMCHR)|g' \ -e 's|@''GNULIB_WMEMCMP''@|$(GNULIB_WMEMCMP)|g' \ -e 's|@''GNULIB_WMEMCPY''@|$(GNULIB_WMEMCPY)|g' \ + -e 's|@''GNULIB_WMEMMOVE''@|$(GNULIB_WMEMMOVE)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -57,6 +58,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_WMEMCHR''@|$(HAVE_WMEMCHR)|g' \ -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \ -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \ + -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|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/wmemmove b/modules/wmemmove new file mode 100644 index 0000000000..ac03e77dc5 --- /dev/null +++ b/modules/wmemmove @@ -0,0 +1,25 @@ +Description: +wmemmove() function: copy wide character array. + +Files: +lib/wmemmove.c +lib/wmemmove-impl.h +m4/wmemmove.m4 + +Depends-on: +wchar + +configure.ac: +gl_FUNC_WMEMMOVE +gl_WCHAR_MODULE_INDICATOR([wmemmove]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc index d8dc18b798..bdab18a50e 100644 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -90,6 +90,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wmemcpy, wchar_t *, (wchar_t *, const wchar_t *, size_t)); #endif +#if GNULIB_TEST_WMEMMOVE +SIGNATURE_CHECK (GNULIB_NAMESPACE::wmemmove, wchar_t *, + (wchar_t *, const wchar_t *, size_t)); +#endif + int main () -- 2.30.2