libprelude/master: GnuLib code update.

[email protected] Fri, 5 Jun 2009 18:45:48 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 1790a0a63829f17431362fad8d081ee4bfd9e3a9
Author: Yoann Vandoorselaere <[email protected]>
Date:   Tue Jun 2 13:28:04 2009 +0200

    GnuLib code update.


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

 libmissing/Makefile.am             |    1 +
 libmissing/alignof.h               |    8 ----
 libmissing/getdelim.c              |    8 ++---
 libmissing/m4/getpagesize.m4       |   29 ++++++++++++++++
 libmissing/m4/gnulib-comp.m4       |   10 +++++
 libmissing/m4/include_next.m4      |   32 +++++++++++++----
 libmissing/m4/mmap-anon.m4         |   59 ++++++++++++++++++++++++++++++++
 libmissing/m4/size_max.m4          |   17 ++++++---
 libmissing/m4/sys_socket_h.m4      |    7 +++-
 libmissing/sys_socket.in.h         |    4 ++
 libmissing/tests/Makefile.am       |   20 ++++++++++-
 libmissing/tests/getpagesize.c     |   39 +++++++++++++++++++++
 libmissing/tests/test-alignof.c    |   51 +++++++++++++++++++++++++++
 libmissing/tests/test-memmem.c     |    8 +++--
 libmissing/tests/test-sys_socket.c |    2 +
 libmissing/tests/zerosize-ptr.h    |   66 ++++++++++++++++++++++++++++++++++++
 16 files changed, 330 insertions(+), 31 deletions(-)

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

diff --git a/libmissing/Makefile.am b/libmissing/Makefile.am
index b9e3416..eba4298 100644
--- a/libmissing/Makefile.am
+++ b/libmissing/Makefile.am
@@ -1281,6 +1281,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..3ef287b 100644
--- a/libmissing/alignof.h
+++ b/libmissing/alignof.h
@@ -26,14 +26,6 @@
 #elif 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)
 #else
 # define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
 #endif
diff --git a/libmissing/getdelim.c b/libmissing/getdelim.c
index 732e724..0d24b07 100644
--- a/libmissing/getdelim.c
+++ b/libmissing/getdelim.c
@@ -1,6 +1,6 @@
 /* getdelim.c --- Implementation of replacement getdelim function.
-   Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008 Free
-   Software Foundation, Inc.
+   Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007,
+   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
@@ -24,12 +24,10 @@
 #include <stdio.h>
 
 #include <limits.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <errno.h>
 
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
 #ifndef SSIZE_MAX
 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
 #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 adc4b96..c97f596 100644
--- a/libmissing/m4/gnulib-comp.m4
+++ b/libmissing/m4/gnulib-comp.m4
@@ -261,11 +261,16 @@ AC_SUBST([LTALLOCA])
   gt_LOCALE_FR
   gt_LOCALE_FR_UTF8
   gl_FUNC_UNGETC_WORKS
+  gl_FUNC_GETPAGESIZE
+  gl_UNISTD_MODULE_INDICATOR([getpagesize])
   gt_LOCALE_FR
   gt_LOCALE_FR_UTF8
   gt_LOCALE_JA
   gt_LOCALE_ZH_CN
   gt_LOCALE_FR_UTF8
+  gl_FUNC_MMAP_ANON
+  AC_CHECK_HEADERS_ONCE([sys/mman.h])
+  AC_CHECK_FUNCS_ONCE([mprotect])
   AC_CHECK_DECLS_ONCE([alarm])
   AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
   AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
@@ -518,6 +523,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/getaddrinfo.m4
   m4/getdelim.m4
   m4/getline.m4
+  m4/getpagesize.m4
   m4/getpass.m4
   m4/gettimeofday.m4
   m4/glibc21.m4
@@ -545,6 +551,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/memmem.m4
   m4/minmax.m4
   m4/mktime.m4
+  m4/mmap-anon.m4
   m4/multiarch.m4
   m4/netdb_h.m4
   m4/netinet_in_h.m4
@@ -608,6 +615,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/write.m4
   m4/xsize.m4
   m4/yield.m4
+  tests/test-alignof.c
   tests/test-alloca-opt.c
   tests/test-arpa_inet.c
   tests/test-btowc.c
@@ -670,6 +678,8 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-wcrtomb.c
   tests/test-wcrtomb.sh
   tests/test-wctype.c
+  tests/zerosize-ptr.h
+  tests=lib/getpagesize.c
   tests=lib/glthread/yield.h
   tests=lib/sockets.c
   tests=lib/sockets.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/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/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/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 4fbbb45..fd92f6b 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
@@ -143,6 +152,15 @@ 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-tests
 
 TESTS += test-gettimeofday
@@ -200,7 +218,7 @@ EXTRA_DIST += test-mbsinit.sh test-mbsinit.c
 TESTS += test-memmem
 check_PROGRAMS += test-memmem
 
-EXTRA_DIST += test-memmem.c
+EXTRA_DIST += test-memmem.c zerosize-ptr.h
 
 ## end   gnulib module memmem-tests
 
diff --git a/libmissing/tests/getpagesize.c b/libmissing/tests/getpagesize.c
new file mode 100644
index 0000000..5498aa9
--- /dev/null
+++ b/libmissing/tests/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 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 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/tests/test-alignof.c b/libmissing/tests/test-alignof.c
new file mode 100644
index 0000000..851cbf0
--- /dev/null
+++ b/libmissing/tests/test-alignof.c
@@ -0,0 +1,51 @@
+/* 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 "verify.h"
+
+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 (type) == offsetof (type##_helper, slot2));
+
+CHECK (char)
+CHECK (short)
+CHECK (int)
+CHECK (long)
+CHECK (float)
+CHECK (double)
+CHECK (struct1)
+CHECK (struct2)
+CHECK (struct3)
+CHECK (struct4)
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/libmissing/tests/test-memmem.c b/libmissing/tests/test-memmem.c
index e429ac0..7f0f925 100644
--- a/libmissing/tests/test-memmem.c
+++ b/libmissing/tests/test-memmem.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004, 2007, 2008 Free Software Foundation
+ * Copyright (C) 2004, 2007-2009 Free Software Foundation
  * Written by Bruno Haible and Eric Blake
  *
  * This program is free software: you can redistribute it and/or modify
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "zerosize-ptr.h"
+
 #define ASSERT(expr) \
   do									     \
     {									     \
@@ -78,9 +80,9 @@ main (int argc, char *argv[])
     ASSERT (result == input + 11);
   }
 
-  /* Check that length 0 does not dereference NULL.  */
+  /* Check that length 0 does not dereference the pointer.  */
   {
-    const char *result = memmem (NULL, 0, "foo", 3);
+    const char *result = memmem (zerosize_ptr (), 0, "foo", 3);
     ASSERT (result == NULL);
   }
 
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/zerosize-ptr.h b/libmissing/tests/zerosize-ptr.h
new file mode 100644
index 0000000..9918ac7
--- /dev/null
+++ b/libmissing/tests/zerosize-ptr.h
@@ -0,0 +1,66 @@
+/* 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, 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