# HG changeset patch # User Bruno Haible # Date 1296907671 -3600 # Node ID 2a7d15223d398fb7942ef6df067d27efb6ee3cae # Parent fe53823759927a60f5d7f86474e99e7ffca1e015 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. diff --git a/ChangeLog b/ChangeLog --- 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 --- 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 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -482,6 +482,25 @@ #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 --- /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 --- /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 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -50,7 +50,7 @@ #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 @@ 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 @@ 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 --- /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 --- a/modules/wchar +++ b/modules/wchar @@ -44,6 +44,7 @@ -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 @@ -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 --- /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 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -90,6 +90,11 @@ (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 ()