diff --git a/gl/Makefile.am b/gl/Makefile.am index 0ec3251f5..b40d7bad8 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -262,6 +262,15 @@ EXTRA_libgnu_la_SOURCES += getline.c ## end gnulib module getline +## begin gnulib module getpagesize + + +EXTRA_DIST += getpagesize.c + +EXTRA_libgnu_la_SOURCES += getpagesize.c + +## end gnulib module getpagesize + ## begin gnulib module getpass-gnu @@ -361,7 +370,7 @@ EXTRA_DIST += $(top_srcdir)/maint.mk ## begin gnulib module memchr -EXTRA_DIST += memchr.c +EXTRA_DIST += memchr.c memchr.valgrind EXTRA_libgnu_la_SOURCES += memchr.c @@ -816,6 +825,7 @@ string.h: string.in.h -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \ -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \ -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \ + -e 's|@''GNULIB_MEMCHR''@|$(GNULIB_MEMCHR)|g' \ -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \ -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \ -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \ @@ -852,6 +862,7 @@ string.h: string.in.h -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \ -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ + -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ diff --git a/gl/errno.in.h b/gl/errno.in.h index 51ac66243..70c16b690 100644 --- a/gl/errno.in.h +++ b/gl/errno.in.h @@ -1,6 +1,6 @@ /* A POSIX-like . - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 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 @@ -145,6 +145,11 @@ # define GNULIB_defined_ENOTSUP 1 # endif +# ifndef ESTALE +# define ESTALE 2009 +# define GNULIB_defined_ESTALE 1 +# endif + # ifndef ECANCELED # define ECANCELED 2008 # define GNULIB_defined_ECANCELED 1 diff --git a/gl/tests/getpagesize.c b/gl/getpagesize.c similarity index 100% rename from gl/tests/getpagesize.c rename to gl/getpagesize.c diff --git a/gl/m4/errno_h.m4 b/gl/m4/errno_h.m4 index 16188d9bc..4ce1ccbd9 100644 --- a/gl/m4/errno_h.m4 +++ b/gl/m4/errno_h.m4 @@ -1,4 +1,4 @@ -# errno_h.m4 serial 5 +# errno_h.m4 serial 6 dnl Copyright (C) 2004, 2006, 2008, 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,6 +34,9 @@ booboo #if !defined ENOTSUP booboo #endif +#if !defined ESTALE +booboo +#endif #if !defined ECANCELED booboo #endif diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index fec57a6ca..56d0e4a03 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -88,6 +88,8 @@ AC_SUBST([LTALLOCA]) gl_STDIO_MODULE_INDICATOR([getdelim]) gl_FUNC_GETLINE gl_STDIO_MODULE_INDICATOR([getline]) + gl_FUNC_GETPAGESIZE + gl_UNISTD_MODULE_INDICATOR([getpagesize]) gl_FUNC_GETPASS_GNU AC_SUBST([LIBINTL]) AC_SUBST([LTLIBINTL]) @@ -114,6 +116,7 @@ AC_SUBST([LTALLOCA]) gl_FUNC_LSEEK gl_UNISTD_MODULE_INDICATOR([lseek]) gl_FUNC_MEMCHR + gl_STRING_MODULE_INDICATOR([memchr]) gl_MINMAX gl_MULTIARCH gl_HEADER_NETDB @@ -221,8 +224,6 @@ AC_SUBST([LTALLOCA]) gl_COMMON gl_source_base='gl/tests' gl_FUNC_UNGETC_WORKS - gl_FUNC_GETPAGESIZE - gl_UNISTD_MODULE_INDICATOR([getpagesize]) gl_FUNC_GETTIMEOFDAY AC_REQUIRE([gl_HEADER_SYS_SOCKET]) if test "$ac_cv_header_winsock2_h" = yes; then @@ -231,9 +232,6 @@ AC_SUBST([LTALLOCA]) fi gl_SYS_IOCTL_MODULE_INDICATOR([ioctl]) gl_MODULE_INDICATOR([ioctl]) - gl_FUNC_MMAP_ANON - AC_CHECK_HEADERS_ONCE([sys/mman.h]) - AC_CHECK_FUNCS_ONCE([mprotect]) AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h]) gt_TYPE_WCHAR_T gt_TYPE_WINT_T @@ -369,6 +367,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/getaddrinfo.c lib/getdelim.c lib/getline.c + lib/getpagesize.c lib/getpass.c lib/getpass.h lib/gettext.h @@ -378,6 +377,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/listen.c lib/lseek.c lib/memchr.c + lib/memchr.valgrind lib/minmax.h lib/netdb.in.h lib/netinet_in.in.h @@ -541,7 +541,6 @@ AC_DEFUN([gl_FILE_LIST], [ tests/test-wchar.c tests/zerosize-ptr.h tests=lib/dummy.c - tests=lib/getpagesize.c tests=lib/gettimeofday.c tests=lib/ioctl.c tests=lib/sys_ioctl.in.h diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4 index 53c538028..1194bac2e 100644 --- a/gl/m4/memchr.m4 +++ b/gl/m4/memchr.m4 @@ -1,14 +1,82 @@ -# memchr.m4 serial 5 +# memchr.m4 serial 7 dnl Copyright (C) 2002, 2003, 2004, 2009 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_MEMCHR], +AC_DEFUN_ONCE([gl_FUNC_MEMCHR], [ + dnl Check for prerequisites for memory fence checks. + gl_FUNC_MMAP_ANON + AC_CHECK_HEADERS_ONCE([sys/mman.h]) + AC_CHECK_FUNCS_ONCE([mprotect]) + + dnl These days, we assume memchr is present. But just in case... + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) AC_REPLACE_FUNCS([memchr]) if test $ac_cv_func_memchr = no; then gl_PREREQ_MEMCHR + REPLACE_MEMCHR=1 + fi + + if test $ac_cv_func_memchr = yes; then + # Detect platform-specific bugs in some versions of glibc: + # memchr should not dereference anything with length 0 + # http://bugzilla.redhat.com/499689 + # memchr should not dereference overestimated length after a match + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737 + # http://sourceware.org/bugzilla/show_bug.cgi?id=10162 + # Assume that memchr works on platforms that lack mprotect. + AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#if HAVE_SYS_MMAN_H +# include +# include +# include +# include +# ifndef MAP_FILE +# define MAP_FILE 0 +# endif +#endif +]], [[ + char *fence = NULL; +#if HAVE_SYS_MMAN_H && HAVE_MPROTECT +# if HAVE_MAP_ANONYMOUS + const int flags = MAP_ANONYMOUS | MAP_PRIVATE; + const int fd = -1; +# else /* !HAVE_MAP_ANONYMOUS */ + const int flags = MAP_FILE | MAP_PRIVATE; + int fd = open ("/dev/zero", O_RDONLY, 0666); + if (fd >= 0) +# endif + { + int pagesize = getpagesize (); + char *two_pages = + (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, + flags, fd, 0); + if (two_pages != (char *)(-1) + && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) + fence = two_pages + pagesize; + } +#endif + if (fence) + { + if (memchr (fence, 0, 0)) + return 1; + strcpy (fence - 9, "12345678"); + if (memchr (fence - 9, 0, 79) != fence - 1) + return 2; + } + return 0; +]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], + [dnl Be pessimistic for now. + gl_cv_func_memchr_works="guessing no"])]) + if test "$gl_cv_func_memchr_works" != yes; then + gl_PREREQ_MEMCHR + REPLACE_MEMCHR=1 + AC_LIBOBJ([memchr]) + fi fi ]) diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4 index 2d5553c37..11f09c8b8 100644 --- a/gl/m4/string_h.m4 +++ b/gl/m4/string_h.m4 @@ -1,11 +1,11 @@ # Configure a GNU-like replacement for . -# Copyright (C) 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 6 +# serial 7 # Written by Paul Eggert. @@ -32,6 +32,7 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR], AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], [ + GNULIB_MEMCHR=0; AC_SUBST([GNULIB_MEMCHR]) GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) @@ -83,6 +84,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) + REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) diff --git a/gl/memchr.valgrind b/gl/memchr.valgrind new file mode 100644 index 000000000..60f247e10 --- /dev/null +++ b/gl/memchr.valgrind @@ -0,0 +1,14 @@ +# Suppress a valgrind message about use of uninitialized memory in memchr(). +# POSIX states that when the character is found, memchr must not read extra +# bytes in an overestimated length (for example, where memchr is used to +# implement strnlen). However, we use a safe word read to provide a speedup. +{ + memchr-value4 + Memcheck:Value4 + fun:rpl_memchr +} +{ + memchr-value8 + Memcheck:Value8 + fun:rpl_memchr +} diff --git a/gl/strerror.c b/gl/strerror.c index 798d85400..dfe6c25f2 100644 --- a/gl/strerror.c +++ b/gl/strerror.c @@ -313,7 +313,13 @@ rpl_strerror (int n) break; # endif -# if GNULIB_defined_ +# if GNULIB_defined_ESTALE + case ESTALE: + msg = "Stale NFS file handle"; + break; +# endif + +# if GNULIB_defined_ECANCELED case ECANCELED: msg = "Operation canceled"; break; diff --git a/gl/string.in.h b/gl/string.in.h index f021a3ed9..97da28fb7 100644 --- a/gl/string.in.h +++ b/gl/string.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001-2009 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 @@ -49,6 +49,21 @@ extern "C" { #endif +/* Return the first instance of C within N bytes of S, or NULL. */ +#if @GNULIB_MEMCHR@ +# if @REPLACE_MEMCHR@ +# define memchr rpl_memchr +extern void *memchr (void const *__s, int __c, size_t __n) + __attribute__ ((__pure__)); +# endif +#elif defined GNULIB_POSIXCHECK +# undef memchr +# define memchr(s,c,n) \ + (GL_LINK_WARNING ("memchr has platform-specific bugs - " \ + "use gnulib module memchr for portability" ), \ + memchr (s, c, n)) +#endif + /* Return the first occurrence of NEEDLE in HAYSTACK. */ #if @GNULIB_MEMMEM@ # if @REPLACE_MEMMEM@ diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am index 698e89bd3..ecb33b656 100644 --- a/gl/tests/Makefile.am +++ b/gl/tests/Makefile.am @@ -124,15 +124,6 @@ EXTRA_DIST += test-getline.c ## end gnulib module getline-tests -## begin gnulib module getpagesize - - -EXTRA_DIST += getpagesize.c - -EXTRA_libtests_a_SOURCES += getpagesize.c - -## end gnulib module getpagesize - ## begin gnulib module gettimeofday diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am index 7970631fc..355f03686 100644 --- a/lib/gl/Makefile.am +++ b/lib/gl/Makefile.am @@ -151,6 +151,15 @@ EXTRA_liblgnu_la_SOURCES += fseeko.c ## end gnulib module fseeko +## begin gnulib module getpagesize + + +EXTRA_DIST += getpagesize.c + +EXTRA_liblgnu_la_SOURCES += getpagesize.c + +## end gnulib module getpagesize + ## begin gnulib module gettext # This is for those projects which use "gettextize --intl" to put a source-code @@ -200,7 +209,7 @@ EXTRA_liblgnu_la_SOURCES += lseek.c ## begin gnulib module memchr -EXTRA_DIST += memchr.c +EXTRA_DIST += memchr.c memchr.valgrind EXTRA_liblgnu_la_SOURCES += memchr.c @@ -543,6 +552,7 @@ string.h: string.in.h -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \ -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \ -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \ + -e 's|@''GNULIB_MEMCHR''@|$(GNULIB_MEMCHR)|g' \ -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \ -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \ -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \ @@ -579,6 +589,7 @@ string.h: string.in.h -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \ -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ + -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ diff --git a/lib/gl/errno.in.h b/lib/gl/errno.in.h index 1dd67a15e..f87c55d29 100644 --- a/lib/gl/errno.in.h +++ b/lib/gl/errno.in.h @@ -1,6 +1,6 @@ /* A POSIX-like . - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -145,6 +145,11 @@ # define GNULIB_defined_ENOTSUP 1 # endif +# ifndef ESTALE +# define ESTALE 2009 +# define GNULIB_defined_ESTALE 1 +# endif + # ifndef ECANCELED # define ECANCELED 2008 # define GNULIB_defined_ECANCELED 1 diff --git a/lib/gl/tests/getpagesize.c b/lib/gl/getpagesize.c similarity index 77% rename from lib/gl/tests/getpagesize.c rename to lib/gl/getpagesize.c index 5498aa948..febcbf34b 100644 --- a/lib/gl/tests/getpagesize.c +++ b/lib/gl/getpagesize.c @@ -3,16 +3,16 @@ Copyright (C) 2007 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 3 of the License, or + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 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. + GNU Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ /* Written by Bruno Haible and Martin Lambers. */ diff --git a/lib/gl/m4/errno_h.m4 b/lib/gl/m4/errno_h.m4 index 16188d9bc..4ce1ccbd9 100644 --- a/lib/gl/m4/errno_h.m4 +++ b/lib/gl/m4/errno_h.m4 @@ -1,4 +1,4 @@ -# errno_h.m4 serial 5 +# errno_h.m4 serial 6 dnl Copyright (C) 2004, 2006, 2008, 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,6 +34,9 @@ booboo #if !defined ENOTSUP booboo #endif +#if !defined ESTALE +booboo +#endif #if !defined ECANCELED booboo #endif diff --git a/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4 index 8c820508d..d11f04b93 100644 --- a/lib/gl/m4/gnulib-comp.m4 +++ b/lib/gl/m4/gnulib-comp.m4 @@ -49,6 +49,8 @@ AC_DEFUN([lgl_INIT], gl_FUNC_FSEEKO gl_STDIO_MODULE_INDICATOR([fseeko]) gl_FUNC + gl_FUNC_GETPAGESIZE + gl_UNISTD_MODULE_INDICATOR([getpagesize]) dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. AM_GNU_GETTEXT_VERSION([0.17]) AC_SUBST([LIBINTL]) @@ -58,6 +60,7 @@ AC_DEFUN([lgl_INIT], gl_FUNC_LSEEK gl_UNISTD_MODULE_INDICATOR([lseek]) gl_FUNC_MEMCHR + gl_STRING_MODULE_INDICATOR([memchr]) gl_FUNC_MEMMEM_SIMPLE gl_STRING_MODULE_INDICATOR([memmem]) gl_FUNC_MEMMOVE @@ -138,11 +141,6 @@ AC_DEFUN([lgl_INIT], gl_COMMON gl_source_base='gl/tests' gl_FUNC_UNGETC_WORKS - gl_FUNC_GETPAGESIZE - gl_UNISTD_MODULE_INDICATOR([getpagesize]) - gl_FUNC_MMAP_ANON - AC_CHECK_HEADERS_ONCE([sys/mman.h]) - AC_CHECK_FUNCS_ONCE([mprotect]) gt_TYPE_WCHAR_T gt_TYPE_WINT_T AC_CHECK_FUNCS([shutdown]) @@ -252,9 +250,11 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/float+.h lib/float.in.h lib/fseeko.c + lib/getpagesize.c lib/gettext.h lib/lseek.c lib/memchr.c + lib/memchr.valgrind lib/memmem.c lib/memmove.c lib/minmax.h @@ -402,7 +402,6 @@ AC_DEFUN([lgl_FILE_LIST], [ tests/test-wchar.c tests/zerosize-ptr.h tests=lib/dummy.c - tests=lib/getpagesize.c tests=lib/intprops.h tests=lib/verify.h ]) diff --git a/lib/gl/m4/memchr.m4 b/lib/gl/m4/memchr.m4 index 53c538028..1194bac2e 100644 --- a/lib/gl/m4/memchr.m4 +++ b/lib/gl/m4/memchr.m4 @@ -1,14 +1,82 @@ -# memchr.m4 serial 5 +# memchr.m4 serial 7 dnl Copyright (C) 2002, 2003, 2004, 2009 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_MEMCHR], +AC_DEFUN_ONCE([gl_FUNC_MEMCHR], [ + dnl Check for prerequisites for memory fence checks. + gl_FUNC_MMAP_ANON + AC_CHECK_HEADERS_ONCE([sys/mman.h]) + AC_CHECK_FUNCS_ONCE([mprotect]) + + dnl These days, we assume memchr is present. But just in case... + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) AC_REPLACE_FUNCS([memchr]) if test $ac_cv_func_memchr = no; then gl_PREREQ_MEMCHR + REPLACE_MEMCHR=1 + fi + + if test $ac_cv_func_memchr = yes; then + # Detect platform-specific bugs in some versions of glibc: + # memchr should not dereference anything with length 0 + # http://bugzilla.redhat.com/499689 + # memchr should not dereference overestimated length after a match + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737 + # http://sourceware.org/bugzilla/show_bug.cgi?id=10162 + # Assume that memchr works on platforms that lack mprotect. + AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#if HAVE_SYS_MMAN_H +# include +# include +# include +# include +# ifndef MAP_FILE +# define MAP_FILE 0 +# endif +#endif +]], [[ + char *fence = NULL; +#if HAVE_SYS_MMAN_H && HAVE_MPROTECT +# if HAVE_MAP_ANONYMOUS + const int flags = MAP_ANONYMOUS | MAP_PRIVATE; + const int fd = -1; +# else /* !HAVE_MAP_ANONYMOUS */ + const int flags = MAP_FILE | MAP_PRIVATE; + int fd = open ("/dev/zero", O_RDONLY, 0666); + if (fd >= 0) +# endif + { + int pagesize = getpagesize (); + char *two_pages = + (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, + flags, fd, 0); + if (two_pages != (char *)(-1) + && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) + fence = two_pages + pagesize; + } +#endif + if (fence) + { + if (memchr (fence, 0, 0)) + return 1; + strcpy (fence - 9, "12345678"); + if (memchr (fence - 9, 0, 79) != fence - 1) + return 2; + } + return 0; +]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], + [dnl Be pessimistic for now. + gl_cv_func_memchr_works="guessing no"])]) + if test "$gl_cv_func_memchr_works" != yes; then + gl_PREREQ_MEMCHR + REPLACE_MEMCHR=1 + AC_LIBOBJ([memchr]) + fi fi ]) diff --git a/lib/gl/m4/string_h.m4 b/lib/gl/m4/string_h.m4 index 2d5553c37..11f09c8b8 100644 --- a/lib/gl/m4/string_h.m4 +++ b/lib/gl/m4/string_h.m4 @@ -1,11 +1,11 @@ # Configure a GNU-like replacement for . -# Copyright (C) 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 6 +# serial 7 # Written by Paul Eggert. @@ -32,6 +32,7 @@ AC_DEFUN([gl_STRING_MODULE_INDICATOR], AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], [ + GNULIB_MEMCHR=0; AC_SUBST([GNULIB_MEMCHR]) GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) @@ -83,6 +84,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) + REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) diff --git a/lib/gl/memchr.valgrind b/lib/gl/memchr.valgrind new file mode 100644 index 000000000..60f247e10 --- /dev/null +++ b/lib/gl/memchr.valgrind @@ -0,0 +1,14 @@ +# Suppress a valgrind message about use of uninitialized memory in memchr(). +# POSIX states that when the character is found, memchr must not read extra +# bytes in an overestimated length (for example, where memchr is used to +# implement strnlen). However, we use a safe word read to provide a speedup. +{ + memchr-value4 + Memcheck:Value4 + fun:rpl_memchr +} +{ + memchr-value8 + Memcheck:Value8 + fun:rpl_memchr +} diff --git a/lib/gl/string.in.h b/lib/gl/string.in.h index 0a6fb85b3..64ebec91b 100644 --- a/lib/gl/string.in.h +++ b/lib/gl/string.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -49,6 +49,21 @@ extern "C" { #endif +/* Return the first instance of C within N bytes of S, or NULL. */ +#if @GNULIB_MEMCHR@ +# if @REPLACE_MEMCHR@ +# define memchr rpl_memchr +extern void *memchr (void const *__s, int __c, size_t __n) + __attribute__ ((__pure__)); +# endif +#elif defined GNULIB_POSIXCHECK +# undef memchr +# define memchr(s,c,n) \ + (GL_LINK_WARNING ("memchr has platform-specific bugs - " \ + "use gnulib module memchr for portability" ), \ + memchr (s, c, n)) +#endif + /* Return the first occurrence of NEEDLE in HAYSTACK. */ #if @GNULIB_MEMMEM@ # if @REPLACE_MEMMEM@ diff --git a/lib/gl/tests/Makefile.am b/lib/gl/tests/Makefile.am index 848a4ecfa..e171efc01 100644 --- a/lib/gl/tests/Makefile.am +++ b/lib/gl/tests/Makefile.am @@ -95,15 +95,6 @@ EXTRA_DIST += test-func.c ## end gnulib module func-tests -## begin gnulib module getpagesize - - -EXTRA_DIST += getpagesize.c - -EXTRA_libtests_a_SOURCES += getpagesize.c - -## end gnulib module getpagesize - ## begin gnulib module intprops