]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Update gnulib files.
authorSimon Josefsson <simon@josefsson.org>
Thu, 18 Jun 2009 20:30:54 +0000 (22:30 +0200)
committerSimon Josefsson <simon@josefsson.org>
Thu, 18 Jun 2009 20:30:54 +0000 (22:30 +0200)
21 files changed:
gl/Makefile.am
gl/errno.in.h
gl/getpagesize.c [moved from gl/tests/getpagesize.c with 100% similarity]
gl/m4/errno_h.m4
gl/m4/gnulib-comp.m4
gl/m4/memchr.m4
gl/m4/string_h.m4
gl/memchr.valgrind [new file with mode: 0644]
gl/strerror.c
gl/string.in.h
gl/tests/Makefile.am
lib/gl/Makefile.am
lib/gl/errno.in.h
lib/gl/getpagesize.c [moved from lib/gl/tests/getpagesize.c with 77% similarity]
lib/gl/m4/errno_h.m4
lib/gl/m4/gnulib-comp.m4
lib/gl/m4/memchr.m4
lib/gl/m4/string_h.m4
lib/gl/memchr.valgrind [new file with mode: 0644]
lib/gl/string.in.h
lib/gl/tests/Makefile.am

index 0ec3251f58a6c80fbfbd3c3305193afa7dcfd18f..b40d7bad8df6ed0255a3f4202daca0807c0331dc 100644 (file)
@@ -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' \
index 51ac66243ead3d4ed9e33d20805049eb2d740582..70c16b6903e28fd18d385c9bf8be255339742e79 100644 (file)
@@ -1,6 +1,6 @@
 /* A POSIX-like <errno.h>.
 
-   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
 #  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
similarity index 100%
rename from gl/tests/getpagesize.c
rename to gl/getpagesize.c
index 16188d9bc09af07a41d7e8d2961aa4cc4e39c3dc..4ce1ccbd9f4b1e6a9d4c06ce4d59d3fed48646eb 100644 (file)
@@ -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
index fec57a6ca00833f232776b77d0f8a728807bec0f..56d0e4a036a00cfaec8e5643d6eef01882258e8b 100644 (file)
@@ -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
index 53c5380281afb04b503e870dc4da648d01385185..1194bac2e81dbadeb030ed946d00f2304bd000c0 100644 (file)
@@ -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 <string.h>
+#if HAVE_SYS_MMAN_H
+# include <fcntl.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/mman.h>
+# 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
 ])
 
index 2d5553c37441e6a5e6c492c41aa3bccf31a863eb..11f09c8b8ff35601a7ea61791cb0fc6857e5f9c0 100644 (file)
@@ -1,11 +1,11 @@
 # Configure a GNU-like replacement for <string.h>.
 
-# 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 (file)
index 0000000..60f247e
--- /dev/null
@@ -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
+}
index 798d854005e99f46b0b8800f0ee654f04d4ac37e..dfe6c25f2faf121c921ee941bb802b68a90ba972 100644 (file)
@@ -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;
index f021a3ed9abd3333e2e4dbcaa4ca8f30860d1886..97da28fb7722cbcb3ce5d16fc2683207d59df0e8 100644 (file)
@@ -1,6 +1,6 @@
 /* A GNU-like <string.h>.
 
-   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@
index 698e89bd3d8c1facfd5f7fae944a80117220df0e..ecb33b656ee759c6a6e6699bba67557bcd479142 100644 (file)
@@ -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
 
 
index 7970631fca85cdc2d35c5d30970ae9c3c26f2f17..355f03686637a9f1f8a78c990d25bdb1aec83d2e 100644 (file)
@@ -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' \
index 1dd67a15e4030e40b61ed50428e83c88dc974517..f87c55d293f9f7a515cc1eeb036b81f115d8eaae 100644 (file)
@@ -1,6 +1,6 @@
 /* A POSIX-like <errno.h>.
 
-   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
 #  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
similarity index 77%
rename from lib/gl/tests/getpagesize.c
rename to lib/gl/getpagesize.c
index 5498aa9483312e814f8cd1c654be4ebefe07a5d9..febcbf34b5fd72acebee523c5d4955e926b8acb7 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.  */
 
 /* Written by Bruno Haible and Martin Lambers.  */
index 16188d9bc09af07a41d7e8d2961aa4cc4e39c3dc..4ce1ccbd9f4b1e6a9d4c06ce4d59d3fed48646eb 100644 (file)
@@ -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
index 8c820508d75d6480b658f5aa920bf210c46c3315..d11f04b93629132523ed2fee9f3246586f300c29 100644 (file)
@@ -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
 ])
index 53c5380281afb04b503e870dc4da648d01385185..1194bac2e81dbadeb030ed946d00f2304bd000c0 100644 (file)
@@ -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 <string.h>
+#if HAVE_SYS_MMAN_H
+# include <fcntl.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/mman.h>
+# 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
 ])
 
index 2d5553c37441e6a5e6c492c41aa3bccf31a863eb..11f09c8b8ff35601a7ea61791cb0fc6857e5f9c0 100644 (file)
@@ -1,11 +1,11 @@
 # Configure a GNU-like replacement for <string.h>.
 
-# 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 (file)
index 0000000..60f247e
--- /dev/null
@@ -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
+}
index 0a6fb85b393a68a3de9c2506e59f4bc6730aa143..64ebec91b057dbb102a10aabe3062b717cfb349b 100644 (file)
@@ -1,6 +1,6 @@
 /* A GNU-like <string.h>.
 
-   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@
index 848a4ecfabbae424b9f3845e3e5e10158be0e6b6..e171efc01650e66066b15685ac8af0543d6f1987 100644 (file)
@@ -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