prelude-manager/master: Update GnuLib code

[email protected] Fri, 10 Jul 2009 14:05:27 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit b59edc7edeb13dd9fd95c6b74a20002c8d0d4d94
Author: Yoann Vandoorselaere <[email protected]>
Date:   Fri Jul 10 11:23:15 2009 +0200

    Update GnuLib code


========================================

 libmissing/Makefile.am             |   24 +++++
 libmissing/alignof.h               |   40 ++++++---
 libmissing/errno.in.h              |    7 ++-
 libmissing/getpagesize.c           |   39 ++++++++
 libmissing/m4/errno_h.m4           |    5 +-
 libmissing/m4/getpagesize.m4       |   29 ++++++
 libmissing/m4/gnulib-comp.m4       |   13 +++
 libmissing/m4/include_next.m4      |   32 +++++--
 libmissing/m4/lib-link.m4          |    7 +-
 libmissing/m4/memchr.m4            |   86 ++++++++++++++++++
 libmissing/m4/mmap-anon.m4         |   59 ++++++++++++
 libmissing/m4/size_max.m4          |   17 +++-
 libmissing/m4/stdio_h.m4           |    5 +-
 libmissing/m4/string_h.m4          |    6 +-
 libmissing/m4/sys_socket_h.m4      |    7 ++-
 libmissing/memchr.c                |  172 ++++++++++++++++++++++++++++++++++++
 libmissing/memchr.valgrind         |   14 +++
 libmissing/stdio.in.h              |   20 ++++-
 libmissing/string.in.h             |   17 ++++-
 libmissing/sys_socket.in.h         |    4 +
 libmissing/tests/Makefile.am       |   17 ++++
 libmissing/tests/strerror.c        |    8 ++-
 libmissing/tests/test-alignof.c    |   59 ++++++++++++
 libmissing/tests/test-memchr.c     |  130 +++++++++++++++++++++++++++
 libmissing/tests/test-stdio.c      |    8 ++-
 libmissing/tests/test-string.c     |    8 ++-
 libmissing/tests/test-sys_socket.c |    2 +
 libmissing/tests/test-unistd.c     |    6 ++
 libmissing/tests/zerosize-ptr.h    |   68 ++++++++++++++
 29 files changed, 869 insertions(+), 40 deletions(-)

========================================

diff --git a/libmissing/Makefile.am b/libmissing/Makefile.am
index 0b424d5..5ee41f8 100644
--- a/libmissing/Makefile.am
+++ b/libmissing/Makefile.am
@@ -188,6 +188,15 @@ EXTRA_libmissing_la_SOURCES += gai_strerror.c getaddrinfo.c
 
 ## end   gnulib module getaddrinfo
 
+## begin gnulib module getpagesize
+
+
+EXTRA_DIST += getpagesize.c
+
+EXTRA_libmissing_la_SOURCES += getpagesize.c
+
+## end   gnulib module getpagesize
+
 ## begin gnulib module gettext-h
 
 libmissing_la_SOURCES += gettext.h
@@ -233,6 +242,15 @@ libmissing_la_SOURCES += glthread/lock.h glthread/lock.c
 
 ## end   gnulib module lock
 
+## begin gnulib module memchr
+
+
+EXTRA_DIST += memchr.c memchr.valgrind
+
+EXTRA_libmissing_la_SOURCES += memchr.c
+
+## end   gnulib module memchr
+
 ## begin gnulib module memset
 
 
@@ -461,6 +479,7 @@ stdio.h: stdio.in.h
 	      -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
 	      -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
 	      -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
+	      -e 's|@''GNULIB_FPURGE''@|$(GNULIB_FPURGE)|g' \
 	      -e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
 	      -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
 	      -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
@@ -498,6 +517,8 @@ stdio.h: stdio.in.h
 	      -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
 	      -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
 	      -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
+	      -e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \
+	      -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
 	      -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
 	      -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
 	      -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
@@ -550,6 +571,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' \
@@ -586,6 +608,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' \
@@ -642,6 +665,7 @@ sys/socket.h: sys_socket.in.h
 	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
 	      -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
 	      -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
+	      -e 's|@''HAVE_SA_FAMILY_T''@|$(HAVE_SA_FAMILY_T)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/sys_socket.in.h; \
 	} > $@-t
diff --git a/libmissing/alignof.h b/libmissing/alignof.h
index d6aa4d1..28ce79c 100644
--- a/libmissing/alignof.h
+++ b/libmissing/alignof.h
@@ -20,22 +20,34 @@
 
 #include <stddef.h>
 
-/* Determine the alignment of a type at compile time.  */
-#if defined __GNUC__
-# define alignof __alignof__
-#elif defined __cplusplus
+/* Determine the alignment of a structure slot (field) of a given type,
+   at compile time.  Note that the result depends on the ABI.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#if defined __cplusplus
   template <class type> struct alignof_helper { char __slot1; type __slot2; };
-# define alignof(type) offsetof (alignof_helper<type>, __slot2)
-#elif defined __hpux
-  /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
-     values.  */
-# define alignof(type) (sizeof (type) <= 4 ? 4 : 8)
-#elif defined _AIX
-  /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
-     values.  */
-# define alignof(type) (sizeof (type) <= 4 ? 4 : 8)
+# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
+#else
+# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
+#endif
+
+/* Determine the good alignment of a object of the given type at compile time.
+   Note that this is not necessarily the same as alignof_slot(type).
+   For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
+   - when -malign-double is not specified:  alignof_slot(double) = 4,
+   - when -malign-double is specified:      alignof_slot(double) = 8.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#if defined __GNUC__
+# define alignof_type __alignof__
 #else
-# define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
+# define alignof_type alignof_slot
 #endif
 
+/* alignof is an alias for alignof_slot semantics, since that's what most
+   callers need.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#define alignof alignof_slot
+
 #endif /* _ALIGNOF_H */
diff --git a/libmissing/errno.in.h b/libmissing/errno.in.h
index 657f68e..a9b81d5 100644
--- a/libmissing/errno.in.h
+++ b/libmissing/errno.in.h
@@ -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
@@ -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/libmissing/getpagesize.c b/libmissing/getpagesize.c
new file mode 100644
index 0000000..82238df
--- /dev/null
+++ b/libmissing/getpagesize.c
@@ -0,0 +1,39 @@
+/* getpagesize emulation for systems where it cannot be done in a C macro.
+
+   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 Lesser 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 Lesser General Public License for more details.
+
+   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.  */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+/* This implementation is only for native Win32 systems.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+int
+getpagesize (void)
+{
+  SYSTEM_INFO system_info;
+  GetSystemInfo (&system_info);
+  return system_info.dwPageSize;
+}
+
+#endif
diff --git a/libmissing/m4/errno_h.m4 b/libmissing/m4/errno_h.m4
index 16188d9..4ce1ccb 100644
--- a/libmissing/m4/errno_h.m4
+++ b/libmissing/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/libmissing/m4/getpagesize.m4 b/libmissing/m4/getpagesize.m4
new file mode 100644
index 0000000..0d07a3a
--- /dev/null
+++ b/libmissing/m4/getpagesize.m4
@@ -0,0 +1,29 @@
+# getpagesize.m4 serial 7
+dnl Copyright (C) 2002, 2004-2005, 2007 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_GETPAGESIZE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CHECK_FUNCS([getpagesize])
+  if test $ac_cv_func_getpagesize = no; then
+    HAVE_GETPAGESIZE=0
+    AC_CHECK_HEADERS([OS.h])
+    if test $ac_cv_header_OS_h = yes; then
+      HAVE_OS_H=1
+    fi
+    AC_CHECK_HEADERS([sys/param.h])
+    if test $ac_cv_header_sys_param_h = yes; then
+      HAVE_SYS_PARAM_H=1
+    fi
+  fi
+  case "$host_os" in
+    mingw*)
+      REPLACE_GETPAGESIZE=1
+      AC_LIBOBJ([getpagesize])
+      ;;
+  esac
+])
diff --git a/libmissing/m4/gnulib-comp.m4 b/libmissing/m4/gnulib-comp.m4
index 39920a2..d3fb748 100644
--- a/libmissing/m4/gnulib-comp.m4
+++ b/libmissing/m4/gnulib-comp.m4
@@ -53,6 +53,8 @@ AC_DEFUN([gl_INIT],
   gl_FUNC_FTW
   gl_GETADDRINFO
   gl_NETDB_MODULE_INDICATOR([getaddrinfo])
+  gl_FUNC_GETPAGESIZE
+  gl_UNISTD_MODULE_INDICATOR([getpagesize])
   AC_SUBST([LIBINTL])
   AC_SUBST([LTLIBINTL])
   gl_FUNC_GETTIMEOFDAY
@@ -60,6 +62,8 @@ AC_DEFUN([gl_INIT],
   gl_INET_NTOP
   gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
   gl_LOCK
+  gl_FUNC_MEMCHR
+  gl_STRING_MODULE_INDICATOR([memchr])
   gl_FUNC_MEMSET
   gl_MULTIARCH
   gl_HEADER_NETDB
@@ -250,6 +254,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/ftw_.h
   lib/gai_strerror.c
   lib/getaddrinfo.c
+  lib/getpagesize.c
   lib/gettext.h
   lib/gettimeofday.c
   lib/glthread/cond.c
@@ -260,6 +265,8 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/glthread/thread.h
   lib/glthread/threadlib.c
   lib/inet_ntop.c
+  lib/memchr.c
+  lib/memchr.valgrind
   lib/memset.c
   lib/netdb.in.h
   lib/netinet_in.in.h
@@ -301,6 +308,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/float_h.m4
   m4/ftw.m4
   m4/getaddrinfo.m4
+  m4/getpagesize.m4
   m4/gettimeofday.m4
   m4/gnulib-common.m4
   m4/hostent.m4
@@ -313,7 +321,9 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/lib-prefix.m4
   m4/lock.m4
   m4/longlong.m4
+  m4/memchr.m4
   m4/memset.m4
+  m4/mmap-anon.m4
   m4/multiarch.m4
   m4/netdb_h.m4
   m4/netinet_in_h.m4
@@ -351,6 +361,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/wint_t.m4
   m4/xsize.m4
   m4/yield.m4
+  tests/test-alignof.c
   tests/test-alloca-opt.c
   tests/test-arpa_inet.c
   tests/test-cond.c
@@ -359,6 +370,7 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-getaddrinfo.c
   tests/test-gettimeofday.c
   tests/test-lock.c
+  tests/test-memchr.c
   tests/test-netdb.c
   tests/test-netinet_in.c
   tests/test-sigaction.c
@@ -377,6 +389,7 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-vasnprintf.c
   tests/test-vsnprintf.c
   tests/test-wchar.c
+  tests/zerosize-ptr.h
   tests=lib/dummy.c
   tests=lib/glthread/yield.h
   tests=lib/intprops.h
diff --git a/libmissing/m4/include_next.m4 b/libmissing/m4/include_next.m4
index d6101fe..5e22ded 100644
--- a/libmissing/m4/include_next.m4
+++ b/libmissing/m4/include_next.m4
@@ -1,4 +1,4 @@
-# include_next.m4 serial 12
+# include_next.m4 serial 14
 dnl Copyright (C) 2006-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,
@@ -104,8 +104,14 @@ EOF
 # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
 # '<foo.h>'; otherwise define it to be
 # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
+# Also, if #include_next works as first preprocessing directive in a file,
+# define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
+# be
+# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
 # That way, a header file with the following line:
 #	#@INCLUDE_NEXT@ @NEXT_FOO_H@
+# or
+#	#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
 # behaves (after sed substitution) as if it contained
 #	#include_next <foo.h>
 # even if the compiler does not support include_next.
@@ -123,15 +129,15 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS],
 
   m4_foreach_w([gl_HEADER_NAME], [$1],
     [AS_VAR_PUSHDEF([gl_next_header],
-		    [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
+		    [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
      if test $gl_cv_have_include_next = yes; then
        AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
      else
        AC_CACHE_CHECK(
-	 [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
-	 m4_quote(m4_defn([gl_next_header])),
+	 [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
+	 m4_defn([gl_next_header]),
 	 [AS_VAR_PUSHDEF([gl_header_exists],
-			 [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
+			 [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
 	  if test AS_VAR_GET(gl_header_exists) = yes; then
 	    AC_LANG_CONFTEST(
 	      [AC_LANG_SOURCE(
@@ -153,8 +159,8 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS],
 	    dnl so use subshell.
 	    AS_VAR_SET([gl_next_header],
 	      ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
-	       sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
-		 s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
+	       sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
+		 s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
 		 s#^/[^/]#//&#
 		 p
 		 q
@@ -165,7 +171,17 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS],
 	  AS_VAR_POPDEF([gl_header_exists])])
      fi
      AC_SUBST(
-       AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
+       AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
        [AS_VAR_GET([gl_next_header])])
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'gl_HEADER_NAME'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
+     fi
+     AC_SUBST(
+       AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
+       [$gl_next_as_first_directive])
      AS_VAR_POPDEF([gl_next_header])])
 ])
diff --git a/libmissing/m4/lib-link.m4 b/libmissing/m4/lib-link.m4
index 2144203..2f8b7ff 100644
--- a/libmissing/m4/lib-link.m4
+++ b/libmissing/m4/lib-link.m4
@@ -1,4 +1,4 @@
-# lib-link.m4 serial 19 (gettext-0.18)
+# lib-link.m4 serial 20 (gettext-0.18)
 dnl Copyright (C) 2001-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,
@@ -82,7 +82,7 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
   ])
   if test "$ac_cv_lib[]Name" = yes; then
     HAVE_LIB[]NAME=yes
-    AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib[]$1 library.])
+    AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.])
     AC_MSG_CHECKING([how to link with lib[]$1])
     AC_MSG_RESULT([$LIB[]NAME])
   else
@@ -210,6 +210,9 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
   LTLIB[]NAME=
   INC[]NAME=
   LIB[]NAME[]_PREFIX=
+  dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been
+  dnl computed. So it has to be reset here.
+  HAVE_LIB[]NAME=
   rpathdirs=
   ltrpathdirs=
   names_already_handled=
diff --git a/libmissing/m4/memchr.m4 b/libmissing/m4/memchr.m4
new file mode 100644
index 0000000..1194bac
--- /dev/null
+++ b/libmissing/m4/memchr.m4
@@ -0,0 +1,86 @@
+# 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_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
+])
+
+# Prerequisites of lib/memchr.c.
+AC_DEFUN([gl_PREREQ_MEMCHR], [
+  AC_CHECK_HEADERS([bp-sym.h])
+])
diff --git a/libmissing/m4/mmap-anon.m4 b/libmissing/m4/mmap-anon.m4
new file mode 100644
index 0000000..14b6270
--- /dev/null
+++ b/libmissing/m4/mmap-anon.m4
@@ -0,0 +1,59 @@
+# mmap-anon.m4 serial 8
+dnl Copyright (C) 2005, 2007, 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.
+
+# Detect how mmap can be used to create anonymous (not file-backed) memory
+# mappings.
+# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
+#   and MAP_ANON exist and have the same value.
+# - On HP-UX, only MAP_ANONYMOUS exists.
+# - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
+# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
+#   used.
+
+AC_DEFUN([gl_FUNC_MMAP_ANON],
+[
+  dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
+  AC_REQUIRE([AC_PROG_CPP])
+  AC_REQUIRE([AC_PROG_EGREP])
+
+  dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
+  # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
+  # irrelevant for anonymous mappings.
+  AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no])
+
+  # Try to allow MAP_ANONYMOUS.
+  gl_have_mmap_anonymous=no
+  if test $gl_have_mmap = yes; then
+    AC_MSG_CHECKING([for MAP_ANONYMOUS])
+    AC_EGREP_CPP([I cant identify this map.], [
+#include <sys/mman.h>
+#ifdef MAP_ANONYMOUS
+    I cant identify this map.
+#endif
+],
+      [gl_have_mmap_anonymous=yes])
+    if test $gl_have_mmap_anonymous != yes; then
+      AC_EGREP_CPP([I cant identify this map.], [
+#include <sys/mman.h>
+#ifdef MAP_ANON
+    I cant identify this map.
+#endif
+],
+        [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
+          [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.])
+         gl_have_mmap_anonymous=yes])
+    fi
+    AC_MSG_RESULT([$gl_have_mmap_anonymous])
+    if test $gl_have_mmap_anonymous = yes; then
+      AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
+        [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
+         config.h and <sys/mman.h>.])
+    fi
+  fi
+])
diff --git a/libmissing/m4/size_max.m4 b/libmissing/m4/size_max.m4
index e0e7b3f..35bd3d6 100644
--- a/libmissing/m4/size_max.m4
+++ b/libmissing/m4/size_max.m4
@@ -1,5 +1,5 @@
-# size_max.m4 serial 7
-dnl Copyright (C) 2003, 2005-2006, 2008 Free Software Foundation, Inc.
+# size_max.m4 serial 9
+dnl Copyright (C) 2003, 2005-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,
 dnl with or without modifications, as long as this notice is preserved.
@@ -10,8 +10,7 @@ AC_DEFUN([gl_SIZE_MAX],
 [
   AC_CHECK_HEADERS([stdint.h])
   dnl First test whether the system already has SIZE_MAX.
-  AC_MSG_CHECKING([for SIZE_MAX])
-  AC_CACHE_VAL([gl_cv_size_max], [
+  AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [
     gl_cv_size_max=
     AC_EGREP_CPP([Found it], [
 #include <limits.h>
@@ -54,11 +53,19 @@ Found it
       fi
     fi
   ])
-  AC_MSG_RESULT([$gl_cv_size_max])
   if test "$gl_cv_size_max" != yes; then
     AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max],
       [Define as the maximum value of type 'size_t', if the system doesn't define it.])
   fi
+  dnl Don't redefine SIZE_MAX in config.h if config.h is re-included after
+  dnl <stdint.h>. Remember that the #undef in AH_VERBATIM gets replaced with
+  dnl #define by AC_DEFINE_UNQUOTED.
+  AH_VERBATIM([SIZE_MAX],
+[/* Define as the maximum value of type 'size_t', if the system doesn't define
+   it. */
+#ifndef SIZE_MAX
+# undef SIZE_MAX
+#endif])
 ])
 
 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
diff --git a/libmissing/m4/stdio_h.m4 b/libmissing/m4/stdio_h.m4
index 846b65d..fcbe68f 100644
--- a/libmissing/m4/stdio_h.m4
+++ b/libmissing/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 15
+# stdio_h.m4 serial 16
 dnl Copyright (C) 2007-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,
@@ -65,6 +65,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_FTELL=0;                AC_SUBST([GNULIB_FTELL])
   GNULIB_FTELLO=0;               AC_SUBST([GNULIB_FTELLO])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
+  GNULIB_FPURGE=0;               AC_SUBST([GNULIB_FPURGE])
   GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
   GNULIB_FPUTC=0;                AC_SUBST([GNULIB_FPUTC])
   GNULIB_PUTC=0;                 AC_SUBST([GNULIB_PUTC])
@@ -105,6 +106,8 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   REPLACE_FTELLO=0;              AC_SUBST([REPLACE_FTELLO])
   REPLACE_FTELL=0;               AC_SUBST([REPLACE_FTELL])
   REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
+  REPLACE_FPURGE=0;              AC_SUBST([REPLACE_FPURGE])
+  HAVE_DECL_FPURGE=1;            AC_SUBST([HAVE_DECL_FPURGE])
   REPLACE_FCLOSE=0;              AC_SUBST([REPLACE_FCLOSE])
   HAVE_DECL_GETDELIM=1;          AC_SUBST([HAVE_DECL_GETDELIM])
   HAVE_DECL_GETLINE=1;           AC_SUBST([HAVE_DECL_GETLINE])
diff --git a/libmissing/m4/string_h.m4 b/libmissing/m4/string_h.m4
index 2d5553c..11f09c8 100644
--- a/libmissing/m4/string_h.m4
+++ b/libmissing/m4/string_h.m4
@@ -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/libmissing/m4/sys_socket_h.m4 b/libmissing/m4/sys_socket_h.m4
index d1cb9c2..74e8110 100644
--- a/libmissing/m4/sys_socket_h.m4
+++ b/libmissing/m4/sys_socket_h.m4
@@ -42,7 +42,7 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
   fi
   # We need to check for ws2tcpip.h now.
   gl_PREREQ_SYS_H_SOCKET
-  AC_CHECK_TYPES([struct sockaddr_storage],,,[
+  AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and
      powerpc-apple-darwin5.5 required it. */
@@ -58,6 +58,10 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
     HAVE_STRUCT_SOCKADDR_STORAGE=0
     SYS_SOCKET_H='sys/socket.h'
   fi
+  if test $ac_cv_type_sa_family_t = no; then
+    HAVE_SA_FAMILY_T=0
+    SYS_SOCKET_H='sys/socket.h'
+  fi
   if test -n "$SYS_SOCKET_H"; then
     gl_PREREQ_SYS_H_WINSOCK2
   fi
@@ -137,4 +141,5 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
   GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
   GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
   HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
+  HAVE_SA_FAMILY_T=1;   AC_SUBST([HAVE_SA_FAMILY_T])
 ])
diff --git a/libmissing/memchr.c b/libmissing/memchr.c
new file mode 100644
index 0000000..3ea1d5b
--- /dev/null
+++ b/libmissing/memchr.c
@@ -0,0 +1,172 @@
+/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006, 2008
+   Free Software Foundation, Inc.
+
+   Based on strlen implementation by Torbjorn Granlund ([email protected]),
+   with help from Dan Sahlin ([email protected]) and
+   commentary by Jim Blandy ([email protected]);
+   adaptation to memchr suggested by Dick Karpinski ([email protected]),
+   and implemented by Roland McGrath ([email protected]).
+
+NOTE: The canonical source of this file is maintained with the GNU C Library.
+Bugs can be reported to [email protected].
+
+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 the
+Free Software Foundation; either version 3 of the License, or 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 Lesser General Public License for more details.
+
+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/>.  */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#include <stddef.h>
+
+#if defined _LIBC
+# include <memcopy.h>
+#else
+# define reg_char char
+#endif
+
+#include <limits.h>
+
+#if HAVE_BP_SYM_H || defined _LIBC
+# include <bp-sym.h>
+#else
+# define BP_SYM(sym) sym
+#endif
+
+#undef __memchr
+#ifdef _LIBC
+# undef memchr
+#endif
+
+#ifndef weak_alias
+# define __memchr memchr
+#endif
+
+/* Search no more than N bytes of S for C.  */
+void *
+__memchr (void const *s, int c_in, size_t n)
+{
+  /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
+     long instead of a 64-bit uintmax_t tends to give better
+     performance.  On 64-bit hardware, unsigned long is generally 64
+     bits already.  Change this typedef to experiment with
+     performance.  */
+  typedef unsigned long int longword;
+
+  const unsigned char *char_ptr;
+  const longword *longword_ptr;
+  longword repeated_one;
+  longword repeated_c;
+  unsigned reg_char c;
+
+  c = (unsigned char) c_in;
+
+  /* Handle the first few bytes by reading one byte at a time.
+     Do this until CHAR_PTR is aligned on a longword boundary.  */
+  for (char_ptr = (const unsigned char *) s;
+       n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
+       --n, ++char_ptr)
+    if (*char_ptr == c)
+      return (void *) char_ptr;
+
+  longword_ptr = (const longword *) char_ptr;
+
+  /* All these elucidatory comments refer to 4-byte longwords,
+     but the theory applies equally well to any size longwords.  */
+
+  /* Compute auxiliary longword values:
+     repeated_one is a value which has a 1 in every byte.
+     repeated_c has c in every byte.  */
+  repeated_one = 0x01010101;
+  repeated_c = c | (c << 8);
+  repeated_c |= repeated_c << 16;
+  if (0xffffffffU < (longword) -1)
+    {
+      repeated_one |= repeated_one << 31 << 1;
+      repeated_c |= repeated_c << 31 << 1;
+      if (8 < sizeof (longword))
+	{
+	  size_t i;
+
+	  for (i = 64; i < sizeof (longword) * 8; i *= 2)
+	    {
+	      repeated_one |= repeated_one << i;
+	      repeated_c |= repeated_c << i;
+	    }
+	}
+    }
+
+  /* Instead of the traditional loop which tests each byte, we will test a
+     longword at a time.  The tricky part is testing if *any of the four*
+     bytes in the longword in question are equal to c.  We first use an xor
+     with repeated_c.  This reduces the task to testing whether *any of the
+     four* bytes in longword1 is zero.
+
+     We compute tmp =
+       ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+     That is, we perform the following operations:
+       1. Subtract repeated_one.
+       2. & ~longword1.
+       3. & a mask consisting of 0x80 in every byte.
+     Consider what happens in each byte:
+       - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+         and step 3 transforms it into 0x80.  A carry can also be propagated
+         to more significant bytes.
+       - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+         position k (0 <= k <= 7); so the lowest k bits are 0.  After step 1,
+         the byte ends in a single bit of value 0 and k bits of value 1.
+         After step 2, the result is just k bits of value 1: 2^k - 1.  After
+         step 3, the result is 0.  And no carry is produced.
+     So, if longword1 has only non-zero bytes, tmp is zero.
+     Whereas if longword1 has a zero byte, call j the position of the least
+     significant zero byte.  Then the result has a zero at positions 0, ...,
+     j-1 and a 0x80 at position j.  We cannot predict the result at the more
+     significant bytes (positions j+1..3), but it does not matter since we
+     already have a non-zero bit at position 8*j+7.
+
+     So, the test whether any byte in longword1 is zero is equivalent to
+     testing whether tmp is nonzero.  */
+
+  while (n >= sizeof (longword))
+    {
+      longword longword1 = *longword_ptr ^ repeated_c;
+
+      if ((((longword1 - repeated_one) & ~longword1)
+	   & (repeated_one << 7)) != 0)
+	break;
+      longword_ptr++;
+      n -= sizeof (longword);
+    }
+
+  char_ptr = (const unsigned char *) longword_ptr;
+
+  /* At this point, we know that either n < sizeof (longword), or one of the
+     sizeof (longword) bytes starting at char_ptr is == c.  On little-endian
+     machines, we could determine the first such byte without any further
+     memory accesses, just by looking at the tmp result from the last loop
+     iteration.  But this does not work on big-endian machines.  Choose code
+     that works in both cases.  */
+
+  for (; n > 0; --n, ++char_ptr)
+    {
+      if (*char_ptr == c)
+	return (void *) char_ptr;
+    }
+
+  return NULL;
+}
+#ifdef weak_alias
+weak_alias (__memchr, BP_SYM (memchr))
+#endif
diff --git a/libmissing/memchr.valgrind b/libmissing/memchr.valgrind
new file mode 100644
index 0000000..60f247e
--- /dev/null
+++ b/libmissing/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/libmissing/stdio.in.h b/libmissing/stdio.in.h
index 9570e50..ae681fc 100644
--- a/libmissing/stdio.in.h
+++ b/libmissing/stdio.in.h
@@ -1,6 +1,6 @@
 /* A GNU-like <stdio.h>.
 
-   Copyright (C) 2004, 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007-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
@@ -407,6 +407,24 @@ extern long rpl_ftell (FILE *fp);
     fflush (f))
 #endif
 
+#if @GNULIB_FPURGE@
+# if @REPLACE_FPURGE@
+#  define fpurge rpl_fpurge
+# endif
+# if @REPLACE_FPURGE@ || !@HAVE_DECL_FPURGE@
+  /* Discard all pending buffered I/O data on STREAM.
+     STREAM must not be wide-character oriented.
+     Return 0 if successful.  Upon error, return -1 and set errno.  */
+  extern int fpurge (FILE *gl_stream);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef fpurge
+# define fpurge(f) \
+   (GL_LINK_WARNING ("fpurge is not always present - " \
+                     "use gnulib module fpurge for portability"), \
+    fpurge (f))
+#endif
+
 #if @GNULIB_FCLOSE@
 # if @REPLACE_FCLOSE@
 #  define fclose rpl_fclose
diff --git a/libmissing/string.in.h b/libmissing/string.in.h
index ca029d7..fe11425 100644
--- a/libmissing/string.in.h
+++ b/libmissing/string.in.h
@@ -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@
diff --git a/libmissing/sys_socket.in.h b/libmissing/sys_socket.in.h
index 50940a0..67b926e 100644
--- a/libmissing/sys_socket.in.h
+++ b/libmissing/sys_socket.in.h
@@ -43,6 +43,10 @@
 #ifndef _GL_SYS_SOCKET_H
 #define _GL_SYS_SOCKET_H
 
+#if !@HAVE_SA_FAMILY_T@
+typedef unsigned short  sa_family_t;
+#endif
+
 #if !@HAVE_STRUCT_SOCKADDR_STORAGE@
 # include <alignof.h>
 /* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
diff --git a/libmissing/tests/Makefile.am b/libmissing/tests/Makefile.am
index 71a8828..898f6ed 100644
--- a/libmissing/tests/Makefile.am
+++ b/libmissing/tests/Makefile.am
@@ -42,6 +42,15 @@ libtests_a_DEPENDENCIES = $(gltests_LIBOBJS)
 EXTRA_libtests_a_SOURCES =
 AM_LIBTOOLFLAGS = --preserve-dup-deps
 
+## begin gnulib module alignof-tests
+
+TESTS += test-alignof
+check_PROGRAMS += test-alignof
+
+EXTRA_DIST += test-alignof.c
+
+## end   gnulib module alignof-tests
+
 ## begin gnulib module alloca-opt-tests
 
 TESTS += test-alloca-opt
@@ -122,6 +131,14 @@ EXTRA_DIST += test-lock.c
 
 ## end   gnulib module lock-tests
 
+## begin gnulib module memchr-tests
+
+TESTS += test-memchr
+check_PROGRAMS += test-memchr
+EXTRA_DIST += test-memchr.c zerosize-ptr.h
+
+## end   gnulib module memchr-tests
+
 ## begin gnulib module netdb-tests
 
 TESTS += test-netdb
diff --git a/libmissing/tests/strerror.c b/libmissing/tests/strerror.c
index 798d854..dfe6c25 100644
--- a/libmissing/tests/strerror.c
+++ b/libmissing/tests/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/libmissing/tests/test-alignof.c b/libmissing/tests/test-alignof.c
new file mode 100644
index 0000000..d42bdf5
--- /dev/null
+++ b/libmissing/tests/test-alignof.c
@@ -0,0 +1,59 @@
+/* Test of <alignof.h>.
+   Copyright (C) 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
+   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 <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <[email protected]>, 2009.  */
+
+#include <config.h>
+
+#include <alignof.h>
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "verify.h"
+
+typedef long double longdouble;
+typedef struct { char a[1]; } struct1;
+typedef struct { char a[2]; } struct2;
+typedef struct { char a[3]; } struct3;
+typedef struct { char a[4]; } struct4;
+
+#define CHECK(type) \
+  typedef struct { char slot1; type slot2; } type##_helper; \
+  verify (alignof_slot (type) == offsetof (type##_helper, slot2)); \
+  const int type##_slot_alignment = alignof_slot (type); \
+  const int type##_type_alignment = alignof_type (type);
+
+CHECK (char)
+CHECK (short)
+CHECK (int)
+CHECK (long)
+CHECK (float)
+CHECK (double)
+CHECK (longdouble)
+#ifdef INT64_MAX
+CHECK (int64_t)
+#endif
+CHECK (struct1)
+CHECK (struct2)
+CHECK (struct3)
+CHECK (struct4)
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/libmissing/tests/test-memchr.c b/libmissing/tests/test-memchr.c
new file mode 100644
index 0000000..1124f8b
--- /dev/null
+++ b/libmissing/tests/test-memchr.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2008-2009 Free Software Foundation
+ * Written by Eric Blake and Bruno Haible
+ *
+ * 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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "zerosize-ptr.h"
+
+#define ASSERT(expr) \
+  do									     \
+    {									     \
+      if (!(expr))							     \
+	{								     \
+	  fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+	  fflush (stderr);						     \
+	  abort ();							     \
+	}								     \
+    }									     \
+  while (0)
+
+/* Calculating void * + int is not portable, so this wrapper converts
+   to char * to make the tests easier to write.  */
+#define MEMCHR (char *) memchr
+
+int
+main ()
+{
+  size_t n = 0x100000;
+  char *input = malloc (n);
+  ASSERT (input);
+
+  input[0] = 'a';
+  input[1] = 'b';
+  memset (input + 2, 'c', 1024);
+  memset (input + 1026, 'd', n - 1028);
+  input[n - 2] = 'e';
+  input[n - 1] = 'a';
+
+  /* Basic behavior tests.  */
+  ASSERT (MEMCHR (input, 'a', n) == input);
+
+  ASSERT (MEMCHR (input, 'a', 0) == NULL);
+  ASSERT (MEMCHR (zerosize_ptr (), 'a', 0) == NULL);
+
+  ASSERT (MEMCHR (input, 'b', n) == input + 1);
+  ASSERT (MEMCHR (input, 'c', n) == input + 2);
+  ASSERT (MEMCHR (input, 'd', n) == input + 1026);
+
+  ASSERT (MEMCHR (input + 1, 'a', n - 1) == input + n - 1);
+  ASSERT (MEMCHR (input + 1, 'e', n - 1) == input + n - 2);
+
+  ASSERT (MEMCHR (input, 'f', n) == NULL);
+  ASSERT (MEMCHR (input, '\0', n) == NULL);
+
+  /* Check that a very long haystack is handled quickly if the byte is
+     found near the beginning.  */
+  {
+    size_t repeat = 10000;
+    for (; repeat > 0; repeat--)
+      {
+	ASSERT (MEMCHR (input, 'c', n) == input + 2);
+      }
+  }
+
+  /* Alignment tests.  */
+  {
+    int i, j;
+    for (i = 0; i < 32; i++)
+      {
+	for (j = 0; j < 256; j++)
+	  input[i + j] = j;
+	for (j = 0; j < 256; j++)
+	  {
+	    ASSERT (MEMCHR (input + i, j, 256) == input + i + j);
+	  }
+      }
+  }
+
+  /* Check that memchr() does not read past the first occurrence of the
+     byte being searched.  See the Austin Group's clarification
+     <http://www.opengroup.org/austin/docs/austin_454.txt>.  */
+  {
+    char *page_boundary = (char *) zerosize_ptr ();
+
+    if (page_boundary != NULL)
+      {
+	int n;
+
+	for (n = 1; n <= 500; n++)
+	  {
+	    char *mem = page_boundary - n;
+	    memset (mem, 'X', n);
+	    ASSERT (MEMCHR (mem, 'U', n) == NULL);
+
+	    {
+	      int i;
+
+	      for (i = 0; i < n; i++)
+		{
+		  mem[i] = 'U';
+		  ASSERT (MEMCHR (mem, 'U', 4000) == mem + i);
+		  mem[i] = 'X';
+		}
+	    }
+	  }
+      }
+  }
+
+  free (input);
+
+  return 0;
+}
diff --git a/libmissing/tests/test-stdio.c b/libmissing/tests/test-stdio.c
index a5efa32..dcfe38d 100644
--- a/libmissing/tests/test-stdio.c
+++ b/libmissing/tests/test-stdio.c
@@ -1,5 +1,5 @@
 /* Test of <stdio.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 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
@@ -20,9 +20,15 @@
 
 #include <stdio.h>
 
+#include "verify.h"
+
 /* Check that the various SEEK_* macros are defined.  */
 int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
 
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 int
 main ()
 {
diff --git a/libmissing/tests/test-string.c b/libmissing/tests/test-string.c
index 68014f5..fe53cd9 100644
--- a/libmissing/tests/test-string.c
+++ b/libmissing/tests/test-string.c
@@ -1,5 +1,5 @@
 /* Test of <string.h> substitute.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 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
@@ -20,6 +20,12 @@
 
 #include <string.h>
 
+#include "verify.h"
+
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 int
 main ()
 {
diff --git a/libmissing/tests/test-sys_socket.c b/libmissing/tests/test-sys_socket.c
index fe7688e..3d946a8 100644
--- a/libmissing/tests/test-sys_socket.c
+++ b/libmissing/tests/test-sys_socket.c
@@ -31,6 +31,7 @@ int
 main ()
 {
   struct sockaddr_storage x;
+  sa_family_t i;
 
   /* Check some errno values.  */
   switch (0)
@@ -46,6 +47,7 @@ main ()
     }
 
   x.ss_family = 42;
+  i = 4711;
 
   return 0;
 }
diff --git a/libmissing/tests/test-unistd.c b/libmissing/tests/test-unistd.c
index 5fed15c..129367b 100644
--- a/libmissing/tests/test-unistd.c
+++ b/libmissing/tests/test-unistd.c
@@ -20,6 +20,12 @@
 
 #include <unistd.h>
 
+#include "verify.h"
+
+/* Check that NULL can be passed through varargs as a pointer type,
+   per POSIX 2008.  */
+verify (sizeof NULL == sizeof (void *));
+
 /* Check that the various SEEK_* macros are defined.  */
 int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET };
 
diff --git a/libmissing/tests/zerosize-ptr.h b/libmissing/tests/zerosize-ptr.h
new file mode 100644
index 0000000..a38a2cf
--- /dev/null
+++ b/libmissing/tests/zerosize-ptr.h
@@ -0,0 +1,68 @@
+/* Return a pointer to a zero-size object in memory.
+   Copyright (C) 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
+   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 <http://www.gnu.org/licenses/>.  */
+
+/* ISO C 99 does not allow memcmp(), memchr() etc. to be invoked with a NULL
+   argument.  Therefore this file produces a non-NULL pointer which cannot
+   be dereferenced, if possible.  */
+
+#include <stdlib.h>
+
+/* Test whether mmap() and mprotect() are available.
+   We don't use HAVE_MMAP, because AC_FUNC_MMAP would not define it on HP-UX.
+   HAVE_MPROTECT is not enough, because mingw does not have mmap() but has an
+   mprotect() function in libgcc.a.  */
+#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
+# include <fcntl.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/mman.h>
+/* Define MAP_FILE when it isn't otherwise.  */
+# ifndef MAP_FILE
+#  define MAP_FILE 0
+# endif
+#endif
+
+/* Return a pointer to a zero-size object in memory (that is, actually, a
+   pointer to a page boundary where the previous page is readable and writable
+   and the next page is neither readable not writable), if possible.
+   Return NULL otherwise.  */
+
+static void *
+zerosize_ptr (void)
+{
+/* Use mmap and mprotect when they exist.  Don't test HAVE_MMAP, because it is
+   not defined on HP-UX 11 (since it does not support MAP_FIXED).  */
+#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)
+	return two_pages + pagesize;
+    }
+#endif
+  return NULL;
+}
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog