r11074 - in libprelude/trunk/libmissing: . glthread m4 tests

[email protected]
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
Author: yoann
Date: 2008-10-21 10:58:44 +0200 (Tue, 21 Oct 2008)
New Revision: 11074

Added:
   libprelude/trunk/libmissing/m4/close.m4
   libprelude/trunk/libmissing/m4/fclose.m4
   libprelude/trunk/libmissing/m4/netdb_h.m4
   libprelude/trunk/libmissing/m4/sys_ioctl_h.m4
   libprelude/trunk/libmissing/netdb.in.h
   libprelude/trunk/libmissing/tests/close.c
   libprelude/trunk/libmissing/tests/fclose.c
   libprelude/trunk/libmissing/tests/test-netdb.c
Removed:
   libprelude/trunk/libmissing/getaddrinfo.h
Modified:
   libprelude/trunk/libmissing/Makefile.am
   libprelude/trunk/libmissing/arpa_inet.in.h
   libprelude/trunk/libmissing/errno.in.h
   libprelude/trunk/libmissing/float.in.h
   libprelude/trunk/libmissing/gai_strerror.c
   libprelude/trunk/libmissing/getaddrinfo.c
   libprelude/trunk/libmissing/glthread/cond.c
   libprelude/trunk/libmissing/glthread/cond.h
   libprelude/trunk/libmissing/glthread/lock.c
   libprelude/trunk/libmissing/glthread/lock.h
   libprelude/trunk/libmissing/glthread/thread.c
   libprelude/trunk/libmissing/glthread/thread.h
   libprelude/trunk/libmissing/m4/getaddrinfo.m4
   libprelude/trunk/libmissing/m4/gnulib-common.m4
   libprelude/trunk/libmissing/m4/gnulib-comp.m4
   libprelude/trunk/libmissing/m4/sleep.m4
   libprelude/trunk/libmissing/m4/stdio_h.m4
   libprelude/trunk/libmissing/m4/stdlib_h.m4
   libprelude/trunk/libmissing/m4/sys_socket_h.m4
   libprelude/trunk/libmissing/m4/sys_stat_h.m4
   libprelude/trunk/libmissing/m4/unistd_h.m4
   libprelude/trunk/libmissing/netinet_in.in.h
   libprelude/trunk/libmissing/signal.in.h
   libprelude/trunk/libmissing/sigprocmask.c
   libprelude/trunk/libmissing/stdint.in.h
   libprelude/trunk/libmissing/stdio.in.h
   libprelude/trunk/libmissing/stdlib.in.h
   libprelude/trunk/libmissing/string.in.h
   libprelude/trunk/libmissing/strings.in.h
   libprelude/trunk/libmissing/sys_select.in.h
   libprelude/trunk/libmissing/sys_socket.in.h
   libprelude/trunk/libmissing/sys_stat.in.h
   libprelude/trunk/libmissing/sys_time.in.h
   libprelude/trunk/libmissing/tests/Makefile.am
   libprelude/trunk/libmissing/tests/test-getaddrinfo.c
   libprelude/trunk/libmissing/tests/test-lock.c
   libprelude/trunk/libmissing/tests/test-poll.c
   libprelude/trunk/libmissing/tests/test-select.c
   libprelude/trunk/libmissing/tests/winsock.c
   libprelude/trunk/libmissing/time.in.h
   libprelude/trunk/libmissing/unistd.in.h
   libprelude/trunk/libmissing/wchar.in.h
   libprelude/trunk/libmissing/wctype.in.h
   libprelude/trunk/libmissing/winsock.c
Log:
Gnulib code update.


Modified: libprelude/trunk/libmissing/Makefile.am
===================================================================
--- libprelude/trunk/libmissing/Makefile.am	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/Makefile.am	2008-10-21 08:58:44 UTC (rev 11074)
@@ -260,7 +260,7 @@
 ## begin gnulib module getaddrinfo
 
 
-EXTRA_DIST += gai_strerror.c getaddrinfo.c getaddrinfo.h
+EXTRA_DIST += gai_strerror.c getaddrinfo.c
 
 EXTRA_libmissing_la_SOURCES += gai_strerror.c getaddrinfo.c
 
@@ -490,6 +490,29 @@
 
 ## end   gnulib module mktime
 
+## begin gnulib module netdb
+
+BUILT_SOURCES += $(NETDB_H)
+
+# We need the following in order to create <netdb.h> when the system
+# doesn't have one that works with the given compiler.
+netdb.h: netdb.in.h
+	rm -f $@-t $@
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
+	      -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
+	      -e 's|@''GNULIB_GETADDRINFO''@|$(GNULIB_GETADDRINFO)|g' \
+	      < $(srcdir)/netdb.in.h; \
+	} > $@-t
+	mv $@-t $@
+MOSTLYCLEANFILES += netdb.h netdb.h-t
+
+EXTRA_DIST += netdb.in.h
+
+## end   gnulib module netdb
+
 ## begin gnulib module netinet_in
 
 BUILT_SOURCES += $(NETINET_IN_H)
@@ -769,6 +792,7 @@
 	      -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
 	      -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
 	      -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
+	      -e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
 	      -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
 	      -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
 	      -e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
@@ -801,6 +825,7 @@
 	      -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
 	      -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
 	      -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|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' \
 	      -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \
@@ -832,6 +857,8 @@
 	      -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
 	      -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
 	      -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \
+	      -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \
+	      -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
 	      -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
 	      -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
 	      -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
@@ -839,7 +866,10 @@
 	      -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \
 	      -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
 	      -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \
+	      -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \
+	      -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \
 	      -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
+	      -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
 	      -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
 	      -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
 	      -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
@@ -848,7 +878,11 @@
 	      -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
 	      -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
 	      -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
+	      -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
+	      -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
+	      -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
 	      -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
+	      -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
 	      -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
 	      -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
 	      -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
@@ -1095,6 +1129,7 @@
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \
 	      -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
+	      -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
 	      -e 's|@''GNULIB_SOCKET''@|$(GNULIB_SOCKET)|g' \
 	      -e 's|@''GNULIB_CONNECT''@|$(GNULIB_CONNECT)|g' \
 	      -e 's|@''GNULIB_ACCEPT''@|$(GNULIB_ACCEPT)|g' \
@@ -1108,6 +1143,7 @@
 	      -e 's|@''GNULIB_RECVFROM''@|$(GNULIB_RECVFROM)|g' \
 	      -e 's|@''GNULIB_SENDTO''@|$(GNULIB_SENDTO)|g' \
 	      -e 's|@''GNULIB_SETSOCKOPT''@|$(GNULIB_SETSOCKOPT)|g' \
+	      -e 's|@''GNULIB_SHUTDOWN''@|$(GNULIB_SHUTDOWN)|g' \
 	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
 	      -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
@@ -1136,8 +1172,13 @@
 	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
+	      -e 's|@''GNULIB_LCHMOD''@|$(GNULIB_LCHMOD)|g' \
+	      -e 's|@''GNULIB_LSTAT''@|$(GNULIB_LSTAT)|g' \
+	      -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
 	      -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
+	      -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
 	      -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
+	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/sys_stat.in.h; \
 	} > $@-t
 	mv $@-t $@
@@ -1260,15 +1301,19 @@
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
 	      -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \
+	      -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
 	      -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
 	      -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
+	      -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
 	      -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
 	      -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \
 	      -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
 	      -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
+	      -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
 	      -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
 	      -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
 	      -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
+	      -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
 	      -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
 	      -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
 	      -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
@@ -1276,10 +1321,13 @@
 	      -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \
 	      -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \
 	      -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
+	      -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
 	      -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
 	      -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
+	      -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \
 	      -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
 	      -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
+	      -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \
 	      -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
 	      -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
 	      -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
@@ -1287,12 +1335,14 @@
 	      -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
 	      -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
 	      -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
+	      -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
 	      -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
 	      -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
 	      -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
 	      -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
 	      -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
 	      -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
+	      -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/unistd.in.h; \
 	} > $@-t

Modified: libprelude/trunk/libmissing/arpa_inet.in.h
===================================================================
--- libprelude/trunk/libmissing/arpa_inet.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/arpa_inet.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -24,7 +24,9 @@
 
 #if @HAVE_ARPA_INET_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@

Modified: libprelude/trunk/libmissing/errno.in.h
===================================================================
--- libprelude/trunk/libmissing/errno.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/errno.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,7 +18,9 @@
 
 #ifndef _GL_ERRNO_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_ERRNO_H@

Modified: libprelude/trunk/libmissing/float.in.h
===================================================================
--- libprelude/trunk/libmissing/float.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/float.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -17,7 +17,9 @@
 
 #ifndef _GL_FLOAT_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_FLOAT_H@

Modified: libprelude/trunk/libmissing/gai_strerror.c
===================================================================
--- libprelude/trunk/libmissing/gai_strerror.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/gai_strerror.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Philip Blundell <[email protected]>, 1997.
 
@@ -18,13 +18,10 @@
 
 #ifndef _LIBC
 # include <config.h>
-# include "getaddrinfo.h"
 #endif
 
 #include <stdio.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
+#include <netdb.h>
 
 #ifdef _LIBC
 # include <libintl.h>

Modified: libprelude/trunk/libmissing/getaddrinfo.c
===================================================================
--- libprelude/trunk/libmissing/getaddrinfo.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/getaddrinfo.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -19,7 +19,7 @@
 
 #include <config.h>
 
-#include "getaddrinfo.h"
+#include <netdb.h>
 
 #if HAVE_NETINET_IN_H
 # include <netinet/in.h>
@@ -301,6 +301,22 @@
   tmp->ai_addr->sa_family = he->h_addrtype;
   tmp->ai_family = he->h_addrtype;
 
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+  switch (he->h_addrtype)
+    {
+#if HAVE_IPV4
+    case AF_INET:
+      tmp->ai_addr->sa_len = sizeof (struct sockaddr_in);
+      break;
+#endif
+#if HAVE_IPV6
+    case AF_INET6:
+      tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6);
+      break;
+#endif
+    }
+#endif
+
   /* FIXME: If more than one address, create linked list of addrinfo's. */
 
   *res = tmp;

Deleted: libprelude/trunk/libmissing/getaddrinfo.h
===================================================================
--- libprelude/trunk/libmissing/getaddrinfo.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/getaddrinfo.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,163 +0,0 @@
-/* Get address information.
-   Copyright (C) 1996-2002, 2003, 2004, 2005, 2006, 2008
-                 Free Software Foundation, Inc.
-   Contributed by Simon Josefsson <[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 2, 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, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef GETADDRINFO_H
-#define GETADDRINFO_H
-
-/* sys/socket.h in i386-unknown-freebsd4.10 and
-   powerpc-apple-darwin5.5 require sys/types.h, so include it first.
-   Then we'll also get 'socklen_t' and 'struct sockaddr' which are
-   used below. */
-#include <sys/types.h>
-/* Get all getaddrinfo related declarations, if available.  */
-#include <sys/socket.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
-
-#ifndef HAVE_STRUCT_ADDRINFO
-
-/* Structure to contain information about address of a service provider.  */
-struct addrinfo
-{
-  int ai_flags;			/* Input flags.  */
-  int ai_family;		/* Protocol family for socket.  */
-  int ai_socktype;		/* Socket type.  */
-  int ai_protocol;		/* Protocol for socket.  */
-  socklen_t ai_addrlen;		/* Length of socket address.  */
-  struct sockaddr *ai_addr;	/* Socket address for socket.  */
-  char *ai_canonname;		/* Canonical name for service location.  */
-  struct addrinfo *ai_next;	/* Pointer to next in list.  */
-};
-#endif
-
-/* Possible values for `ai_flags' field in `addrinfo' structure.  */
-#ifndef AI_PASSIVE
-# define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
-#endif
-#ifndef AI_CANONNAME
-# define AI_CANONNAME	0x0002	/* Request for canonical name.  */
-#endif
-#ifndef AI_NUMERICSERV
-# define AI_NUMERICSERV	0x0400	/* Don't use name resolution.  */
-#endif
-
-#if 0
-/* The commented out definitions below are not yet implemented in the
-   GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
-   cause conflicts on systems with a getaddrinfo() function which does not
-   define them.
-
-   If they are restored, be sure to protect the definitions with #ifndef.  */
-#define AI_NUMERICHOST	0x0004	/* Don't use name resolution.  */
-#define AI_V4MAPPED	0x0008	/* IPv4 mapped addresses are acceptable.  */
-#define AI_ALL		0x0010	/* Return IPv4 mapped and IPv6 addresses.  */
-#define AI_ADDRCONFIG	0x0020	/* Use configuration of this host to choose
-				   returned address type..  */
-#endif /* 0 */
-
-/* Error values for `getaddrinfo' function.  */
-#ifndef EAI_BADFLAGS
-# define EAI_BADFLAGS	  -1	/* Invalid value for `ai_flags' field.  */
-# define EAI_NONAME	  -2	/* NAME or SERVICE is unknown.  */
-# define EAI_AGAIN	  -3	/* Temporary failure in name resolution.  */
-# define EAI_FAIL	  -4	/* Non-recoverable failure in name res.  */
-# define EAI_NODATA	  -5	/* No address associated with NAME.  */
-# define EAI_FAMILY	  -6	/* `ai_family' not supported.  */
-# define EAI_SOCKTYPE	  -7	/* `ai_socktype' not supported.  */
-# define EAI_SERVICE	  -8	/* SERVICE not supported for `ai_socktype'.  */
-# define EAI_MEMORY	  -10	/* Memory allocation failure.  */
-#endif
-
-/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
-   FreeBSD, which does define EAI_BADFLAGS) have removed the definition
-   in favor of EAI_NONAME.  */
-#if !defined EAI_NODATA && defined EAI_NONAME
-# define EAI_NODATA EAI_NONAME
-#endif
-
-#ifndef EAI_OVERFLOW
-/* Not defined on mingw32. */
-# define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
-#endif
-#ifndef EAI_ADDRFAMILY
-/* Not defined on mingw32. */
-# define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */
-#endif
-#ifndef EAI_SYSTEM
-/* Not defined on mingw32. */
-# define EAI_SYSTEM	  -11	/* System error returned in `errno'.  */
-#endif
-
-#ifdef __USE_GNU
-# ifndef EAI_INPROGRESS
-#  define EAI_INPROGRESS	-100	/* Processing request in progress.  */
-#  define EAI_CANCELED		-101	/* Request canceled.  */
-#  define EAI_NOTCANCELED	-102	/* Request not canceled.  */
-#  define EAI_ALLDONE		-103	/* All requests done.  */
-#  define EAI_INTR		-104	/* Interrupted by a signal.  */
-#  define EAI_IDN_ENCODE	-105	/* IDN encoding failed.  */
-# endif
-#endif
-
-#if !HAVE_DECL_GETADDRINFO
-/* Translate name of a service location and/or a service name to set of
-   socket addresses.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
-extern int getaddrinfo (const char *restrict nodename,
-			const char *restrict servname,
-			const struct addrinfo *restrict hints,
-			struct addrinfo **restrict res);
-#endif
-
-#if !HAVE_DECL_FREEADDRINFO
-/* Free `addrinfo' structure AI including associated storage.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
-extern void freeaddrinfo (struct addrinfo *ai);
-#endif
-
-#if !HAVE_DECL_GAI_STRERROR
-/* Convert error return from getaddrinfo() to a string.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
-extern const char *gai_strerror (int ecode);
-#endif
-
-#if !HAVE_DECL_GETNAMEINFO
-/* Convert socket address to printable node and service names.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */
-extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
-		       char *restrict node, socklen_t nodelen,
-		       char *restrict service, socklen_t servicelen,
-		       int flags);
-
-#endif
-
-/* Possible flags for getnameinfo.  */
-#ifndef NI_NUMERICHOST
-# define NI_NUMERICHOST 1
-#endif
-#ifndef NI_NUMERICSERV
-# define NI_NUMERICSERV 2
-#endif
-
-#endif /* GETADDRINFO_H */

Modified: libprelude/trunk/libmissing/glthread/cond.c
===================================================================
--- libprelude/trunk/libmissing/glthread/cond.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/glthread/cond.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -15,246 +15,448 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-/* Written by Yoann Vandoorselaere <[email protected]>, 2008.  */
+/* Written by Yoann Vandoorselaere <[email protected]>, 2008,
+   and Bruno Haible <[email protected]>, 2008.  */
 
 #include <config.h>
-#include <sys/time.h>
 
 #include "glthread/cond.h"
 
 /* ========================================================================= */
 
-#if USE_WIN32_THREADS
+#if USE_PTH_THREADS
 
-/*
- * WIN32 implementation based on http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
- */
+/* -------------------------- gl_cond_t datatype -------------------------- */
 
-int glthread_cond_init_func(gl_cond_t *cv)
+int
+glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
+				       gl_lock_t *lock,
+				       struct timespec *abstime)
 {
-  cv->waiters_count = 0;
-  cv->wait_generation_count = 0;
-  cv->release_count = 0;
-  
-  InitializeCriticalSection(&cv->lock);
+  int ret, status;
+  pth_event_t ev;
 
-  /* Create a manual-reset event. */
-  cv->event = CreateEvent (NULL, TRUE, FALSE, NULL);
-  cv->guard.done = 1;
+  ev = pth_event (PTH_EVENT_TIME, pth_time (abstime->tv_sec, abstime->tv_nsec / 1000));
+  ret = pth_cond_await (cond, lock, ev);
 
-  return 0;
-}
+  status = pth_event_status (ev);
+  pth_event_free (ev, PTH_FREE_THIS);
 
+  if (status == PTH_STATUS_OCCURRED)
+    return ETIMEDOUT;
 
-static void 
-init_once(gl_cond_t *cv)
-{
-  if (!cv->guard.done)
-    {
-      if (InterlockedIncrement (&cv->guard.started) == 0)
-        /* This thread is the first one to need this lock.  Initialize it.  */
-        glthread_cond_init (cv);
-      else
-        /* Yield the CPU while waiting for another thread to finish
-           initializing this lock.  */
-        while (!cv->guard.done)
-          Sleep (0);
-    }
+  return ret;
 }
 
+#endif
 
-int glthread_cond_destroy_func(gl_cond_t *cv)
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* -------------------------- gl_cond_t datatype -------------------------- */
+
+int
+glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
+				       gl_lock_t *lock,
+				       struct timespec *abstime)
 {
-  CloseHandle(cv->event);
-  return 0;
+  int ret;
+
+  ret = cond_timedwait (cond, lock, abstime);
+  if (ret == ETIME)
+    return ETIMEDOUT;
+  return ret;
 }
 
+#endif
 
-static int cond_wait(gl_cond_t *cv, gl_lock_t *external_mutex, DWORD msec)
-{
-  int ret, my_generation, wait_done; 
+/* ========================================================================= */
 
-  init_once(cv);
+#if USE_WIN32_THREADS
 
-  EnterCriticalSection(&cv->lock);
+#include <sys/time.h>
 
-  /* Increment count of waiters, 
-    and store current generation in our activation record. */
-  cv->waiters_count++;
-  my_generation = cv->wait_generation_count;
+/* -------------------------- gl_cond_t datatype -------------------------- */
 
-  LeaveCriticalSection(&cv->lock);
-  glthread_lock_unlock(external_mutex);
+/* In this file, the waitqueues are implemented as linked lists.  */
+#define gl_waitqueue_t gl_linked_waitqueue_t
 
-  do 
-   {
-    /* Wait until the event is signaled. */
-    ret = WaitForSingleObject (cv->event, msec);
-    if ( ret != WAIT_OBJECT_0 )
-      break;
+/* All links of a circular list, except the anchor, are of this type, carrying
+   a payload.  */
+struct gl_waitqueue_element
+{
+  struct gl_waitqueue_link link; /* must be the first field! */
+  HANDLE event; /* Waiting thread, represented by an event.
+                   This field is immutable once initialized. */
+};
 
-    EnterCriticalSection (&cv->lock);
-    /* Exit the loop when the event is signaled and there are still
-       waiting threads from this <wait_generation> that haven't been released from this wait yet.
-     */
-    wait_done = cv->release_count > 0 && cv->wait_generation_count != my_generation;
-    LeaveCriticalSection (&cv->lock);
-  } while (!wait_done);
+static inline void
+gl_waitqueue_init (gl_waitqueue_t *wq)
+{
+  wq->wq_list.wql_next = &wq->wq_list;
+  wq->wq_list.wql_prev = &wq->wq_list;
+}
 
-  glthread_lock_lock(external_mutex);
-  EnterCriticalSection(&cv->lock);
-  cv->waiters_count--;
+/* Enqueues the current thread, represented by an event, in a wait queue.
+   Returns NULL if an allocation failure occurs.  */
+static struct gl_waitqueue_element *
+gl_waitqueue_add (gl_waitqueue_t *wq)
+{
+  struct gl_waitqueue_element *elt;
+  HANDLE event;
 
-  if ( ret == WAIT_OBJECT_0 ) 
+  /* Allocate the memory for the waitqueue element on the heap, not on the
+     thread's stack.  If the thread exits unexpectedly, we prefer to leak
+     some memory rather than to access unavailable memory and crash.  */
+  elt =
+    (struct gl_waitqueue_element *)
+    malloc (sizeof (struct gl_waitqueue_element));
+  if (elt == NULL)
+    /* No more memory.  */
+    return NULL;
+
+  /* Whether the created event is a manual-reset one or an auto-reset one,
+     does not matter, since we will wait on it only once.  */
+  event = CreateEvent (NULL, TRUE, FALSE, NULL);
+  if (event == INVALID_HANDLE_VALUE)
     {
-      if ( --cv->release_count == 0 )
-        /* We're the last waiter to be notified, so reset the manual event. */
-        ResetEvent (cv->event);
+      /* No way to allocate an event.  */
+      free (elt);
+      return NULL;
     }
-
-  LeaveCriticalSection (&cv->lock);
-
-  return (ret == WAIT_TIMEOUT) ? ETIMEDOUT : (ret == WAIT_OBJECT_0) ? 0 : -1;
+  elt->event = event;
+  /* Insert elt at the end of the circular list.  */
+  (elt->link.wql_prev = wq->wq_list.wql_prev)->wql_next = &elt->link;
+  (elt->link.wql_next = &wq->wq_list)->wql_prev = &elt->link;
+  return elt;
 }
 
-
-int glthread_cond_wait_func(gl_cond_t *cv, gl_lock_t *external_mutex)
+/* Removes the current thread, represented by a 'struct gl_waitqueue_element *',
+   from a wait queue.
+   Returns true if is was found and removed, false if it was not present.  */
+static inline bool
+gl_waitqueue_remove (gl_waitqueue_t *wq, struct gl_waitqueue_element *elt)
 {
-  return cond_wait(cv, external_mutex, INFINITE);
+  if (elt->link.wql_next != NULL && elt->link.wql_prev != NULL)
+    {
+      /* Remove elt from the circular list.  */
+      struct gl_waitqueue_link *prev = elt->link.wql_prev;
+      struct gl_waitqueue_link *next = elt->link.wql_next;
+      prev->wql_next = next;
+      next->wql_prev = prev;
+      elt->link.wql_next = NULL;
+      elt->link.wql_prev = NULL;
+      return true;
+    }
+  else
+    return false;
 }
 
-
-/* Subtract the `struct timeval' values X and Y,
-        storing the result in RESULT.
-        Return 1 if the difference is negative, otherwise 0.  */
-     
-static int 
-timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y)
+/* Notifies the first thread from a wait queue and dequeues it.  */
+static inline void
+gl_waitqueue_notify_first (gl_waitqueue_t *wq)
 {
-  /* Perform the carry for the later subtraction by updating y. */
-  if (x->tv_usec < y->tv_usec) 
+  if (wq->wq_list.wql_next != &wq->wq_list)
     {
-      int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
-      y->tv_usec -= 1000000 * nsec;
-      y->tv_sec += nsec;
+      struct gl_waitqueue_element *elt =
+	(struct gl_waitqueue_element *) wq->wq_list.wql_next;
+      struct gl_waitqueue_link *prev;
+      struct gl_waitqueue_link *next;
+
+      /* Remove elt from the circular list.  */
+      prev = &wq->wq_list; /* = elt->link.wql_prev; */
+      next = elt->link.wql_next;
+      prev->wql_next = next;
+      next->wql_prev = prev;
+      elt->link.wql_next = NULL;
+      elt->link.wql_prev = NULL;
+
+      SetEvent (elt->event);
+      /* After the SetEvent, this thread cannot access *elt any more, because
+	 the woken-up thread will quickly call  free (elt).  */
     }
-  if (x->tv_usec - y->tv_usec > 1000000) 
-    {
-      int nsec = (x->tv_usec - y->tv_usec) / 1000000;
-      y->tv_usec += 1000000 * nsec;
-      y->tv_sec -= nsec;
-    }
-     
-  /* Compute the time remaining to wait.
-     tv_usec is certainly positive. */
-  result->tv_sec = x->tv_sec - y->tv_sec;
-  result->tv_usec = x->tv_usec - y->tv_usec;
-     
-  /* Return 1 if result is negative. */
-  return x->tv_sec < y->tv_sec;
 }
 
-
-int glthread_cond_timedwait_func(gl_cond_t *cv, gl_lock_t *external_mutex, struct timespec *ts)
+/* Notifies all threads from a wait queue and dequeues them all.  */
+static inline void
+gl_waitqueue_notify_all (gl_waitqueue_t *wq)
 {
-  struct timeval res, now, end;
+  struct gl_waitqueue_link *l;
 
-  end.tv_sec = ts->tv_sec;
-  end.tv_usec = ts->tv_nsec / 1000;
-  gettimeofday(&now, NULL);
+  for (l = wq->wq_list.wql_next; l != &wq->wq_list; )
+    {
+      struct gl_waitqueue_element *elt = (struct gl_waitqueue_element *) l;
+      struct gl_waitqueue_link *prev;
+      struct gl_waitqueue_link *next;
 
-  timeval_subtract(&res, &end, &now);
+      /* Remove elt from the circular list.  */
+      prev = &wq->wq_list; /* = elt->link.wql_prev; */
+      next = elt->link.wql_next;
+      prev->wql_next = next;
+      next->wql_prev = prev;
+      elt->link.wql_next = NULL;
+      elt->link.wql_prev = NULL;
 
-  return cond_wait(cv, external_mutex, (res.tv_sec * 1000) + (res.tv_usec / 1000));
+      SetEvent (elt->event);
+      /* After the SetEvent, this thread cannot access *elt any more, because
+	 the woken-up thread will quickly call  free (elt).  */
+
+      l = next;
+    }
+  if (!(wq->wq_list.wql_next == &wq->wq_list
+        && wq->wq_list.wql_prev == &wq->wq_list))
+    abort ();
 }
 
-
-int glthread_cond_broadcast_func(gl_cond_t *cv)
+int
+glthread_cond_init_func (gl_cond_t *cond)
 {
-  init_once(cv);
+  InitializeCriticalSection (&cond->lock);
+  gl_waitqueue_init (&cond->waiters);
 
-  EnterCriticalSection(&cv->lock);
-  /* The pthread_cond_broadcast() and pthread_cond_signal() functions  shall
-     have no effect if there are no threads currently blocked on cond.
-   */
-  if (cv->waiters_count > 0) 
-    {  
-      SetEvent(cv->event);
-      /* Release all the threads in this generation. */
-      cv->release_count = cv->waiters_count;
-      cv->wait_generation_count++;
-    }
-  LeaveCriticalSection(&cv->lock);
-
+  cond->guard.done = 1;
   return 0;
 }
 
-	
-int glthread_cond_signal_func(gl_cond_t *cv)
+int
+glthread_cond_wait_func (gl_cond_t *cond, gl_lock_t *lock)
 {
-  init_once(cv);
-
-  EnterCriticalSection(&cv->lock);
-  /* The pthread_cond_broadcast() and pthread_cond_signal() functions  shall
-     have no effect if there are no threads currently blocked on cond.
-   */
-  if (cv->waiters_count > cv->release_count)
+  if (!cond->guard.done)
     {
-      SetEvent(cv->event); /* Signal the manual-reset event.*/
-      cv->release_count++;
-      cv->wait_generation_count++;
+      if (InterlockedIncrement (&cond->guard.started) == 0)
+	/* This thread is the first one to need this condition variable.
+	   Initialize it.  */
+	glthread_cond_init (cond);
+      else
+	/* Yield the CPU while waiting for another thread to finish
+	   initializing this condition variable.  */
+	while (!cond->guard.done)
+	  Sleep (0);
     }
-  LeaveCriticalSection(&cv->lock);
 
-  return 0;
+  EnterCriticalSection (&cond->lock);
+  {
+    struct gl_waitqueue_element *elt = gl_waitqueue_add (&cond->waiters);
+    LeaveCriticalSection (&cond->lock);
+    if (elt == NULL)
+      {
+	/* Allocation failure.  Weird.  */
+	return EAGAIN;
+      }
+    else
+      {
+	HANDLE event = elt->event;
+	int err;
+	DWORD result;
+
+	/* Now release the lock and let any other thread take it.  */
+	err = glthread_lock_unlock (lock);
+	if (err != 0)
+	  {
+	    EnterCriticalSection (&cond->lock);
+	    gl_waitqueue_remove (&cond->waiters, elt);
+	    LeaveCriticalSection (&cond->lock);
+	    CloseHandle (event);
+	    free (elt);
+	    return err;
+	  }
+	/* POSIX says:
+	    "If another thread is able to acquire the mutex after the
+	     about-to-block thread has released it, then a subsequent call to
+	     pthread_cond_broadcast() or pthread_cond_signal() in that thread
+	     shall behave as if it were issued after the about-to-block thread
+	     has blocked."
+	   This is fulfilled here, because the thread signalling is done
+	   through SetEvent, not PulseEvent.  */
+	/* Wait until another thread signals this event.  */
+	result = WaitForSingleObject (event, INFINITE);
+	if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+	  abort ();
+	CloseHandle (event);
+	free (elt);
+	/* The thread which signalled the event already did the bookkeeping:
+	   removed us from the waiters.  */
+	return glthread_lock_lock (lock);
+      }
+  }
 }
 
+int
+glthread_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec *abstime)
+{
+  struct timeval currtime;
 
-#endif
+  gettimeofday (&currtime, NULL);
+  if (currtime.tv_sec > abstime->tv_sec
+      || (currtime.tv_sec == abstime->tv_sec
+	  && currtime.tv_usec * 1000 >= abstime->tv_nsec))
+    return ETIMEDOUT;
 
-#if USE_PTH_THREADS
+  if (!cond->guard.done)
+    {
+      if (InterlockedIncrement (&cond->guard.started) == 0)
+	/* This thread is the first one to need this condition variable.
+	   Initialize it.  */
+	glthread_cond_init (cond);
+      else
+	/* Yield the CPU while waiting for another thread to finish
+	   initializing this condition variable.  */
+	while (!cond->guard.done)
+	  Sleep (0);
+    }
 
-/* -------------------------- gl_cond_t datatype -------------------------- */
+  EnterCriticalSection (&cond->lock);
+  {
+    struct gl_waitqueue_element *elt = gl_waitqueue_add (&cond->waiters);
+    LeaveCriticalSection (&cond->lock);
+    if (elt == NULL)
+      {
+	/* Allocation failure.  Weird.  */
+	return EAGAIN;
+      }
+    else
+      {
+	HANDLE event = elt->event;
+	int err;
+	DWORD timeout;
+	DWORD result;
 
+	/* Now release the lock and let any other thread take it.  */
+	err = glthread_lock_unlock (lock);
+	if (err != 0)
+	  {
+	    EnterCriticalSection (&cond->lock);
+	    gl_waitqueue_remove (&cond->waiters, elt);
+	    LeaveCriticalSection (&cond->lock);
+	    CloseHandle (event);
+	    free (elt);
+	    return err;
+	  }
+	/* POSIX says:
+	    "If another thread is able to acquire the mutex after the
+	     about-to-block thread has released it, then a subsequent call to
+	     pthread_cond_broadcast() or pthread_cond_signal() in that thread
+	     shall behave as if it were issued after the about-to-block thread
+	     has blocked."
+	   This is fulfilled here, because the thread signalling is done
+	   through SetEvent, not PulseEvent.  */
+	/* Wait until another thread signals this event or until the abstime
+	   passes.  */
+	gettimeofday (&currtime, NULL);
+	if (currtime.tv_sec > abstime->tv_sec)
+	  timeout = 0;
+	else
+	  {
+	    unsigned long seconds = abstime->tv_sec - currtime.tv_sec;
+	    timeout = seconds * 1000;
+	    if (timeout / 1000 != seconds) /* overflow? */
+	      timeout = INFINITE;
+	    else
+	      {
+		long milliseconds =
+		  abstime->tv_nsec / 1000000 - currtime.tv_usec / 1000;
+		if (milliseconds >= 0)
+		  {
+		    timeout += milliseconds;
+		    if (timeout < milliseconds) /* overflow? */
+		      timeout = INFINITE;
+		  }
+		else
+		  {
+		    if (timeout >= - milliseconds)
+		      timeout -= (- milliseconds);
+		    else
+		      timeout = 0;
+		  }
+	      }
+	  }
+	result = WaitForSingleObject (event, timeout);
+	if (result == WAIT_FAILED)
+	  abort ();
+	if (result == WAIT_TIMEOUT)
+	  {
+	    EnterCriticalSection (&cond->lock);
+	    if (gl_waitqueue_remove (&cond->waiters, elt))
+	      {
+		/* The event was not signaled between the WaitForSingleObject
+		   call and the EnterCriticalSection call.  */
+		if (!(WaitForSingleObject (event, 0) == WAIT_TIMEOUT))
+		  abort ();
+	      }
+	    else
+	      {
+		/* The event was signaled between the WaitForSingleObject
+		   call and the EnterCriticalSection call.  */
+		if (!(WaitForSingleObject (event, 0) == WAIT_OBJECT_0))
+		  abort ();
+		/* Produce the right return value.  */
+		result = WAIT_OBJECT_0;
+	      }
+	    LeaveCriticalSection (&cond->lock);
+	  }
+	else
+	  {
+	    /* The thread which signalled the event already did the
+	       bookkeeping: removed us from the waiters.  */
+	  }
+	CloseHandle (event);
+	free (elt);
+	/* Take the lock again.  It does not matter whether this is done
+	   before or after the bookkeeping for WAIT_TIMEOUT.  */
+	err = glthread_lock_lock (lock);
+	return (err ? err :
+		result == WAIT_OBJECT_0 ? 0 :
+		result == WAIT_TIMEOUT ? ETIMEDOUT :
+		/* WAIT_FAILED shouldn't happen */ EAGAIN);
+      }
+  }
+}
+
 int
-glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
-				       gl_lock_t *lock,
-				       struct timespec *abstime)
+glthread_cond_signal_func (gl_cond_t *cond)
 {
-  int ret, status;
-  pth_event_t ev;
+  if (!cond->guard.done)
+    return EINVAL;
 
-  ev = pth_event (PTH_EVENT_TIME, pth_time (abstime->tv_sec, abstime->tv_nsec / 1000));
-  ret = pth_cond_await (cond, lock, ev);
+  EnterCriticalSection (&cond->lock);
+  /* POSIX says:
+      "The pthread_cond_broadcast() and pthread_cond_signal() functions shall
+       have no effect if there are no threads currently blocked on cond."  */
+  if (cond->waiters.wq_list.wql_next != &cond->waiters.wq_list)
+    gl_waitqueue_notify_first (&cond->waiters);
+  LeaveCriticalSection (&cond->lock);
 
-  status = pth_event_status (ev);
-  pth_event_free (ev, PTH_FREE_THIS);
-
-  if (status == PTH_STATUS_OCCURRED)
-    return ETIMEDOUT;
-
-  return ret;
+  return 0;
 }
 
-#endif
+int
+glthread_cond_broadcast_func (gl_cond_t *cond)
+{
+  if (!cond->guard.done)
+    return EINVAL;
 
-/* ========================================================================= */
+  EnterCriticalSection (&cond->lock);
+  /* POSIX says:
+      "The pthread_cond_broadcast() and pthread_cond_signal() functions shall
+       have no effect if there are no threads currently blocked on cond."
+     gl_waitqueue_notify_all is a nop in this case.  */
+  gl_waitqueue_notify_all (&cond->waiters);
+  LeaveCriticalSection (&cond->lock);
 
-#if USE_SOLARIS_THREADS
+  return 0;
+}
 
-/* -------------------------- gl_cond_t datatype -------------------------- */
-
 int
-glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
-				       gl_lock_t *lock,
-				       struct timespec *abstime)
+glthread_cond_destroy_func (gl_cond_t *cond)
 {
-  int ret;
-
-  ret = cond_timedwait (cond, lock, abstime);
-  if (ret == ETIME)
-    return ETIMEDOUT;
-  return ret;
+  if (!cond->guard.done)
+    return EINVAL;
+  if (cond->waiters.wq_list.wql_next != &cond->waiters.wq_list)
+    return EBUSY;
+  DeleteCriticalSection (&cond->lock);
+  cond->guard.done = 0;
+  return 0;
 }
 
 #endif

Modified: libprelude/trunk/libmissing/glthread/cond.h
===================================================================
--- libprelude/trunk/libmissing/glthread/cond.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/glthread/cond.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -267,27 +267,35 @@
 
 #endif
 
-
 /* ========================================================================= */
 
 #if USE_WIN32_THREADS
 
+# include <windows.h>
+
 # ifdef __cplusplus
 extern "C" {
 # endif
 
 /* -------------------------- gl_cond_t datatype -------------------------- */
 
-typedef struct {
-  gl_spinlock_t guard;
-  CRITICAL_SECTION lock;
-
-  int waiters_count;
-  int release_count;
-  int wait_generation_count;
-  HANDLE event;
-} gl_cond_t;
-
+struct gl_waitqueue_link
+{
+  struct gl_waitqueue_link *wql_next;
+  struct gl_waitqueue_link *wql_prev;
+};
+typedef struct
+        {
+          struct gl_waitqueue_link wq_list; /* circular list of waiting threads */
+        }
+        gl_linked_waitqueue_t;
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          CRITICAL_SECTION lock; /* protects the remaining fields */
+          gl_linked_waitqueue_t waiters; /* waiting threads */
+        }
+        gl_cond_t;
 # define gl_cond_define(STORAGECLASS, NAME) \
     STORAGECLASS gl_cond_t NAME;
 # define gl_cond_define_initialized(STORAGECLASS, NAME) \
@@ -306,14 +314,13 @@
     glthread_cond_broadcast_func (COND)
 # define glthread_cond_destroy(COND) \
     glthread_cond_destroy_func (COND)
+extern int glthread_cond_init_func (gl_cond_t *cond);
+extern int glthread_cond_wait_func (gl_cond_t *cond, gl_lock_t *lock);
+extern int glthread_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec *abstime);
+extern int glthread_cond_signal_func (gl_cond_t *cond);
+extern int glthread_cond_broadcast_func (gl_cond_t *cond);
+extern int glthread_cond_destroy_func (gl_cond_t *cond);
 
-int glthread_cond_init_func(gl_cond_t *cv);
-int glthread_cond_signal_func(gl_cond_t *cv);
-int glthread_cond_broadcast_func(gl_cond_t *cv);
-int glthread_cond_wait_func(gl_cond_t *cv, gl_lock_t *external_mutex);
-int glthread_cond_timedwait_func(gl_cond_t *cv, gl_lock_t *external_mutex, struct timespec *ts);
-int glthread_cond_destroy_func(gl_cond_t *cv);
-
 # ifdef __cplusplus
 }
 # endif
@@ -327,7 +334,6 @@
 /* Provide dummy implementation if threads are not supported.  */
 
 typedef int gl_cond_t;
-# define gl_cond_initializer 0
 # define gl_cond_define(STORAGECLASS, NAME)
 # define gl_cond_define_initialized(STORAGECLASS, NAME)
 # define glthread_cond_init(COND) 0

Modified: libprelude/trunk/libmissing/glthread/lock.c
===================================================================
--- libprelude/trunk/libmissing/glthread/lock.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/glthread/lock.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -680,6 +680,9 @@
 
 /* ------------------------- gl_rwlock_t datatype ------------------------- */
 
+/* In this file, the waitqueues are implemented as circular arrays.  */
+#define gl_waitqueue_t gl_carray_waitqueue_t
+
 static inline void
 gl_waitqueue_init (gl_waitqueue_t *wq)
 {
@@ -726,6 +729,8 @@
       wq->array = new_array;
       wq->alloc = new_alloc;
     }
+  /* Whether the created event is a manual-reset one or an auto-reset one,
+     does not matter, since we will wait on it only once.  */
   event = CreateEvent (NULL, TRUE, FALSE, NULL);
   if (event == INVALID_HANDLE_VALUE)
     /* No way to allocate an event.  */

Modified: libprelude/trunk/libmissing/glthread/lock.h
===================================================================
--- libprelude/trunk/libmissing/glthread/lock.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/glthread/lock.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -675,13 +675,13 @@
           unsigned int alloc; /* length of allocated array */
           unsigned int offset; /* index of first waiting thread in array */
         }
-        gl_waitqueue_t;
+        gl_carray_waitqueue_t;
 typedef struct
         {
           gl_spinlock_t guard; /* protects the initialization */
           CRITICAL_SECTION lock; /* protects the remaining fields */
-          gl_waitqueue_t waiting_readers; /* waiting readers */
-          gl_waitqueue_t waiting_writers; /* waiting writers */
+          gl_carray_waitqueue_t waiting_readers; /* waiting readers */
+          gl_carray_waitqueue_t waiting_writers; /* waiting writers */
           int runcount; /* number of readers running, or -1 when a writer runs */
         }
         gl_rwlock_t;

Modified: libprelude/trunk/libmissing/glthread/thread.c
===================================================================
--- libprelude/trunk/libmissing/glthread/thread.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/glthread/thread.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -31,6 +31,8 @@
 
 #if USE_WIN32_THREADS
 
+#include <process.h>
+
 /* -------------------------- gl_thread_t datatype -------------------------- */
 
 /* The Thread-Local Storage (TLS) key that allows to access each thread's
@@ -118,7 +120,7 @@
 
 /* The main function of a freshly creating thread.  It's a wrapper around
    the FUNC and ARG arguments passed to glthread_create_func.  */
-static DWORD WINAPI
+static unsigned int WINAPI
 wrapper_func (void *varg)
 {
   struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
@@ -154,11 +156,12 @@
   thread->arg = arg;
 
   {
-    DWORD thread_id;
+    unsigned int thread_id;
     HANDLE thread_handle;
 
-    thread_handle =
-      CreateThread (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+    thread_handle = (HANDLE)
+      _beginthreadex (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+      /* calls CreateThread with the same arguments */
     if (thread_handle == NULL)
       {
 	DeleteCriticalSection (&thread->handle_lock);
@@ -206,7 +209,7 @@
 {
   gl_thread_t thread = gl_thread_self ();
   thread->result = retval;
-  ExitThread (0);
+  _endthreadex (0); /* calls ExitThread (0) */
 }
 
 #endif

Modified: libprelude/trunk/libmissing/glthread/thread.h
===================================================================
--- libprelude/trunk/libmissing/glthread/thread.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/glthread/thread.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -137,6 +137,9 @@
 
 /* -------------------------- gl_thread_t datatype -------------------------- */
 
+/* This choice of gl_thread_t assumes that
+     pthread_equal (a, b)  is equivalent to  ((a) == (b)).
+   This is the case on all platforms in use in 2008.  */
 typedef pthread_t gl_thread_t;
 # define glthread_create(THREADP, FUNC, ARG) \
     (pthread_in_use () ? pthread_create (THREADP, NULL, FUNC, ARG) : ENOSYS)

Added: libprelude/trunk/libmissing/m4/close.m4
===================================================================
--- libprelude/trunk/libmissing/m4/close.m4	                        (rev 0)
+++ libprelude/trunk/libmissing/m4/close.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,25 @@
+# close.m4 serial 2
+dnl Copyright (C) 2008 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_CLOSE],
+[
+  m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
+    gl_PREREQ_SYS_H_WINSOCK2
+    if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
+      gl_REPLACE_CLOSE
+    fi
+  ])
+])
+
+AC_DEFUN([gl_REPLACE_CLOSE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  if test $REPLACE_CLOSE != 1; then
+    AC_LIBOBJ([close])
+  fi
+  REPLACE_CLOSE=1
+  gl_REPLACE_FCLOSE
+])

Added: libprelude/trunk/libmissing/m4/fclose.m4
===================================================================
--- libprelude/trunk/libmissing/m4/fclose.m4	                        (rev 0)
+++ libprelude/trunk/libmissing/m4/fclose.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,18 @@
+# fclose.m4 serial 1
+dnl Copyright (C) 2008 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_FCLOSE],
+[
+])
+
+AC_DEFUN([gl_REPLACE_FCLOSE],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  if test $REPLACE_FCLOSE != 1; then
+    AC_LIBOBJ([fclose])
+  fi
+  REPLACE_FCLOSE=1
+])

Modified: libprelude/trunk/libmissing/m4/getaddrinfo.m4
===================================================================
--- libprelude/trunk/libmissing/m4/getaddrinfo.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/getaddrinfo.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,5 +1,5 @@
-# getaddrinfo.m4 serial 15
-dnl Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+# getaddrinfo.m4 serial 16
+dnl Copyright (C) 2004, 2005, 2006, 2007, 2008 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.
@@ -7,10 +7,9 @@
 AC_DEFUN([gl_GETADDRINFO],
 [
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
+  AC_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
   AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
 
-  AC_CHECK_HEADERS_ONCE(netdb.h)
-
   AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
   AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
     AC_TRY_LINK([
@@ -72,7 +71,7 @@
   gl_PREREQ_GETADDRINFO
 ])
 
-# Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
+# Prerequisites of lib/getaddrinfo.c.
 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
   AC_SEARCH_LIBS(gethostbyname, [inet nsl])
@@ -99,7 +98,12 @@
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   AC_REQUIRE([AC_C_INLINE])
   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
-  AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
+
+  dnl Including sys/socket.h is wrong for Windows, but Windows does not
+  dnl have sa_len so the result is correct anyway.
+  AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
+
+  AC_CHECK_HEADERS_ONCE(netinet/in.h)
   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and

Modified: libprelude/trunk/libmissing/m4/gnulib-common.m4
===================================================================
--- libprelude/trunk/libmissing/m4/gnulib-common.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/gnulib-common.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 5
+# gnulib-common.m4 serial 6
 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -21,7 +21,17 @@
 #if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
 # define __GNUC_STDC_INLINE__ 1
 #endif])
+  AH_VERBATIM([unused_parameter],
+[/* Define as a marker that can be attached to function parameter declarations
+   for parameters that are not used.  This helps to reduce warnings, such as
+   from GCC -Wunused-parameter.  */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _UNUSED_PARAMETER_ __attribute__ ((__unused__))
+#else
+# define _UNUSED_PARAMETER_
+#endif
 ])
+])
 
 # gl_MODULE_INDICATOR([modulename])
 # defines a C macro indicating the presence of the given module.

Modified: libprelude/trunk/libmissing/m4/gnulib-comp.m4
===================================================================
--- libprelude/trunk/libmissing/m4/gnulib-comp.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/gnulib-comp.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -68,6 +68,7 @@
   gl_STDIO_MODULE_INDICATOR([fseeko])
   gl_FUNC_FTW
   gl_GETADDRINFO
+  gl_NETDB_MODULE_INDICATOR([getaddrinfo])
   gl_FUNC_GETDELIM
   gl_STDIO_MODULE_INDICATOR([getdelim])
   gl_FUNC_GETLINE
@@ -102,6 +103,7 @@
   gl_STRING_MODULE_INDICATOR([memmem])
   gl_MINMAX
   gl_FUNC_MKTIME
+  gl_HEADER_NETDB
   gl_HEADER_NETINET_IN
   AC_PROG_MKDIR_P
   gl_PATHMAX
@@ -166,6 +168,7 @@
   gl_HEADER_SYS_SELECT
   AC_PROG_MKDIR_P
   gl_HEADER_SYS_SOCKET
+  gl_MODULE_INDICATOR([sys_socket])
   AC_PROG_MKDIR_P
   gl_HEADER_SYS_STAT_H
   AC_PROG_MKDIR_P
@@ -236,6 +239,10 @@
     AC_LIBOBJ([winsock])
   fi
   gl_SYS_SOCKET_MODULE_INDICATOR([bind])
+  gl_FUNC_CLOSE
+  gl_UNISTD_MODULE_INDICATOR([close])
+  gl_FUNC_FCLOSE
+  gl_STDIO_MODULE_INDICATOR([fclose])
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   if test "$ac_cv_header_winsock2_h" = yes; then
     AC_LIBOBJ([winsock])
@@ -360,7 +367,6 @@
   lib/ftw_.h
   lib/gai_strerror.c
   lib/getaddrinfo.c
-  lib/getaddrinfo.h
   lib/getdelim.c
   lib/getline.c
   lib/getpass.c
@@ -388,6 +394,7 @@
   lib/memmem.c
   lib/minmax.h
   lib/mktime.c
+  lib/netdb.in.h
   lib/netinet_in.in.h
   lib/pathmax.h
   lib/perror.c
@@ -454,11 +461,13 @@
   lib/xsize.h
   m4/alloca.m4
   m4/arpa_inet_h.m4
+  m4/close.m4
   m4/codeset.m4
   m4/cond.m4
   m4/dup2.m4
   m4/errno_h.m4
   m4/extensions.m4
+  m4/fclose.m4
   m4/float_h.m4
   m4/fopen.m4
   m4/fseeko.m4
@@ -489,6 +498,7 @@
   m4/memmem.m4
   m4/minmax.m4
   m4/mktime.m4
+  m4/netdb_h.m4
   m4/netinet_in_h.m4
   m4/onceonly.m4
   m4/pathmax.m4
@@ -523,6 +533,7 @@
   m4/strpbrk.m4
   m4/strptime.m4
   m4/strsep.m4
+  m4/sys_ioctl_h.m4
   m4/sys_select_h.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
@@ -563,6 +574,7 @@
   tests/test-memchr.c
   tests/test-memcmp.c
   tests/test-memmem.c
+  tests/test-netdb.c
   tests/test-netinet_in.c
   tests/test-perror.c
   tests/test-perror.sh
@@ -590,6 +602,8 @@
   tests/test-vsnprintf.c
   tests/test-wchar.c
   tests/test-wctype.c
+  tests=lib/close.c
+  tests=lib/fclose.c
   tests=lib/glthread/yield.h
   tests=lib/sockets.c
   tests=lib/sockets.h

Added: libprelude/trunk/libmissing/m4/netdb_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/netdb_h.m4	                        (rev 0)
+++ libprelude/trunk/libmissing/m4/netdb_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,32 @@
+# netdb_h.m4 serial 2
+dnl Copyright (C) 2008 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_HEADER_NETDB],
+[
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  gl_CHECK_NEXT_HEADERS([netdb.h])
+  if test $ac_cv_header_netdb_h = yes; then
+    NETDB_H=''
+    HAVE_NETDB_H=1
+  else
+    NETDB_H='netdb.h'
+    HAVE_NETDB_H=0
+  fi
+  AC_SUBST([HAVE_NETDB_H])
+  AC_SUBST([NETDB_H])
+])
+
+AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_NETDB_H_DEFAULTS],
+[
+  GNULIB_GETADDRINFO=0; AC_SUBST([GNULIB_GETADDRINFO])
+])

Modified: libprelude/trunk/libmissing/m4/sleep.m4
===================================================================
--- libprelude/trunk/libmissing/m4/sleep.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/sleep.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,5 +1,5 @@
-# sleep.m4 serial 1
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
+# sleep.m4 serial 2
+dnl Copyright (C) 2007-2008 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.
@@ -7,8 +7,13 @@
 AC_DEFUN([gl_FUNC_SLEEP],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
-  AC_CHECK_FUNCS_ONCE([sleep])
-  if test $ac_cv_func_sleep = no; then
+  dnl We expect to see the declaration of sleep() in a header file.
+  dnl Older versions of mingw have a sleep() function that is an alias to
+  dnl _sleep() in MSVCRT. It has a different signature than POSIX sleep():
+  dnl it takes the number of milliseconds as argument and returns void.
+  dnl mingw does not declare this function.
+  AC_CHECK_DECLS([sleep], , , [#include <unistd.h>])
+  if test $ac_cv_have_decl_sleep != yes; then
     HAVE_SLEEP=0
     AC_LIBOBJ([sleep])
     gl_PREREQ_SLEEP

Modified: libprelude/trunk/libmissing/m4/stdio_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/stdio_h.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/stdio_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 13
+# stdio_h.m4 serial 14
 dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -63,6 +63,7 @@
   GNULIB_FTELL=0;                AC_SUBST([GNULIB_FTELL])
   GNULIB_FTELLO=0;               AC_SUBST([GNULIB_FTELLO])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
+  GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
   GNULIB_FPUTC=0;                AC_SUBST([GNULIB_FPUTC])
   GNULIB_PUTC=0;                 AC_SUBST([GNULIB_PUTC])
   GNULIB_PUTCHAR=0;              AC_SUBST([GNULIB_PUTCHAR])
@@ -98,6 +99,7 @@
   REPLACE_FTELLO=0;              AC_SUBST([REPLACE_FTELLO])
   REPLACE_FTELL=0;               AC_SUBST([REPLACE_FTELL])
   REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
+  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])
   REPLACE_GETLINE=0;             AC_SUBST([REPLACE_GETLINE])

Modified: libprelude/trunk/libmissing/m4/stdlib_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/stdlib_h.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/stdlib_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 7
+# stdlib_h.m4 serial 10
 dnl Copyright (C) 2007, 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -22,6 +22,8 @@
   GNULIB_MALLOC_POSIX=0;  AC_SUBST([GNULIB_MALLOC_POSIX])
   GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
   GNULIB_CALLOC_POSIX=0;  AC_SUBST([GNULIB_CALLOC_POSIX])
+  GNULIB_ATOLL=0;         AC_SUBST([GNULIB_ATOLL])
+  GNULIB_GETLOADAVG=0;    AC_SUBST([GNULIB_GETLOADAVG])
   GNULIB_GETSUBOPT=0;     AC_SUBST([GNULIB_GETSUBOPT])
   GNULIB_MKDTEMP=0;       AC_SUBST([GNULIB_MKDTEMP])
   GNULIB_MKSTEMP=0;       AC_SUBST([GNULIB_MKSTEMP])
@@ -29,8 +31,11 @@
   GNULIB_RPMATCH=0;       AC_SUBST([GNULIB_RPMATCH])
   GNULIB_SETENV=0;        AC_SUBST([GNULIB_SETENV])
   GNULIB_STRTOD=0;        AC_SUBST([GNULIB_STRTOD])
+  GNULIB_STRTOLL=0;       AC_SUBST([GNULIB_STRTOLL])
+  GNULIB_STRTOULL=0;      AC_SUBST([GNULIB_STRTOULL])
   GNULIB_UNSETENV=0;      AC_SUBST([GNULIB_UNSETENV])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_ATOLL=1;           AC_SUBST([HAVE_ATOLL])
   HAVE_CALLOC_POSIX=1;    AC_SUBST([HAVE_CALLOC_POSIX])
   HAVE_GETSUBOPT=1;       AC_SUBST([HAVE_GETSUBOPT])
   HAVE_MALLOC_POSIX=1;    AC_SUBST([HAVE_MALLOC_POSIX])
@@ -39,7 +44,11 @@
   HAVE_RPMATCH=1;         AC_SUBST([HAVE_RPMATCH])
   HAVE_SETENV=1;          AC_SUBST([HAVE_SETENV])
   HAVE_STRTOD=1;          AC_SUBST([HAVE_STRTOD])
+  HAVE_STRTOLL=1;         AC_SUBST([HAVE_STRTOLL])
+  HAVE_STRTOULL=1;        AC_SUBST([HAVE_STRTOULL])
+  HAVE_SYS_LOADAVG_H=0;   AC_SUBST([HAVE_SYS_LOADAVG_H])
   HAVE_UNSETENV=1;        AC_SUBST([HAVE_UNSETENV])
+  HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
   REPLACE_MKSTEMP=0;      AC_SUBST([REPLACE_MKSTEMP])
   REPLACE_PUTENV=0;       AC_SUBST([REPLACE_PUTENV])
   REPLACE_STRTOD=0;       AC_SUBST([REPLACE_STRTOD])

Added: libprelude/trunk/libmissing/m4/sys_ioctl_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/sys_ioctl_h.m4	                        (rev 0)
+++ libprelude/trunk/libmissing/m4/sys_ioctl_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,60 @@
+# sys_ioctl_h.m4 serial 1
+dnl Copyright (C) 2008 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.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_SYS_IOCTL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
+    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
+    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
+      [gl_cv_decl_ioctl_in_sys_ioctl_h],
+      [AC_CHECK_DECL([ioctl],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no],
+         [#include <sys/ioctl.h>])
+      ])
+    if test $gl_cv_decl_ioctl_in_sys_ioctl_h != yes; then
+      SYS_IOCTL_H='sys/ioctl.h'
+    fi
+  else
+    HAVE_SYS_IOCTL_H=0
+    SYS_IOCTL_H='sys/ioctl.h'
+  fi
+  AC_SUBST([HAVE_SYS_IOCTL_H])
+  dnl Execute this unconditionally, because SYS_IOCTL_H may be set by other
+  dnl modules, after this code is executed.
+  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
+])
+
+dnl Unconditionally enables the replacement of <sys/ioctl.h>.
+AC_DEFUN([gl_REPLACE_SYS_IOCTL_H],
+[
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  SYS_IOCTL_H='sys/ioctl.h'
+])
+
+AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
+[
+  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
+  SYS_IOCTL_H='';                AC_SUBST([SYS_IOCTL_H])
+])

Modified: libprelude/trunk/libmissing/m4/sys_socket_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/sys_socket_h.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/sys_socket_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-# sys_socket_h.m4 serial 8
+# sys_socket_h.m4 serial 11
 dnl Copyright (C) 2005-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -60,9 +60,6 @@
       fi
     fi
     gl_PREREQ_SYS_H_WINSOCK2
-    if test x$ac_cv_header_winsock2_h = xyes; then
-      AC_LIBOBJ(winsock)
-    fi
     AC_SUBST([HAVE_SYS_SOCKET_H])
     AC_SUBST([HAVE_WS2TCPIP_H])
   fi
@@ -74,6 +71,8 @@
 # Sets and substitutes HAVE_WINSOCK2_H.
 AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
 [
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
   AC_CHECK_HEADERS_ONCE([sys/socket.h])
   if test $ac_cv_header_sys_socket_h != yes; then
     dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
@@ -84,6 +83,8 @@
   fi
   if test "$ac_cv_header_winsock2_h" = yes; then
     HAVE_WINSOCK2_H=1
+    UNISTD_H_HAVE_WINSOCK2_H=1
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=1
   else
     HAVE_WINSOCK2_H=0
   fi
@@ -100,6 +101,7 @@
 
 AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
 [
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for GNULIB_CLOSE
   GNULIB_SOCKET=0;      AC_SUBST([GNULIB_SOCKET])
   GNULIB_CONNECT=0;     AC_SUBST([GNULIB_CONNECT])
   GNULIB_ACCEPT=0;      AC_SUBST([GNULIB_ACCEPT])
@@ -113,4 +115,5 @@
   GNULIB_RECVFROM=0;    AC_SUBST([GNULIB_RECVFROM])
   GNULIB_SENDTO=0;      AC_SUBST([GNULIB_SENDTO])
   GNULIB_SETSOCKOPT=0;  AC_SUBST([GNULIB_SETSOCKOPT])
+  GNULIB_SHUTDOWN=0;    AC_SUBST([GNULIB_SHUTDOWN])
 ])

Modified: libprelude/trunk/libmissing/m4/sys_stat_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/sys_stat_h.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/sys_stat_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 8   -*- Autoconf -*-
+# sys_stat_h.m4 serial 10   -*- Autoconf -*-
 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -50,6 +50,10 @@
 
 AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
+  GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD])
+  GNULIB_LSTAT=0;  AC_SUBST([GNULIB_LSTAT])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_LCHMOD=1;   AC_SUBST([HAVE_LCHMOD])
+  REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
   REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
 ])

Modified: libprelude/trunk/libmissing/m4/unistd_h.m4
===================================================================
--- libprelude/trunk/libmissing/m4/unistd_h.m4	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/m4/unistd_h.m4	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 13
+# unistd_h.m4 serial 15
 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -33,15 +33,19 @@
 AC_DEFUN([gl_UNISTD_H_DEFAULTS],
 [
   GNULIB_CHOWN=0;            AC_SUBST([GNULIB_CHOWN])
+  GNULIB_CLOSE=0;            AC_SUBST([GNULIB_CLOSE])
   GNULIB_DUP2=0;             AC_SUBST([GNULIB_DUP2])
   GNULIB_ENVIRON=0;          AC_SUBST([GNULIB_ENVIRON])
+  GNULIB_EUIDACCESS=0;       AC_SUBST([GNULIB_EUIDACCESS])
   GNULIB_FCHDIR=0;           AC_SUBST([GNULIB_FCHDIR])
   GNULIB_FSYNC=0;            AC_SUBST([GNULIB_FSYNC])
   GNULIB_FTRUNCATE=0;        AC_SUBST([GNULIB_FTRUNCATE])
   GNULIB_GETCWD=0;           AC_SUBST([GNULIB_GETCWD])
+  GNULIB_GETDOMAINNAME=0;    AC_SUBST([GNULIB_GETDOMAINNAME])
   GNULIB_GETDTABLESIZE=0;    AC_SUBST([GNULIB_GETDTABLESIZE])
   GNULIB_GETLOGIN_R=0;       AC_SUBST([GNULIB_GETLOGIN_R])
   GNULIB_GETPAGESIZE=0;      AC_SUBST([GNULIB_GETPAGESIZE])
+  GNULIB_GETUSERSHELL=0;     AC_SUBST([GNULIB_GETUSERSHELL])
   GNULIB_LCHOWN=0;           AC_SUBST([GNULIB_LCHOWN])
   GNULIB_LSEEK=0;            AC_SUBST([GNULIB_LSEEK])
   GNULIB_READLINK=0;         AC_SUBST([GNULIB_READLINK])
@@ -50,10 +54,13 @@
   GNULIB_WRITE=0;            AC_SUBST([GNULIB_WRITE])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DUP2=1;            AC_SUBST([HAVE_DUP2])
+  HAVE_EUIDACCESS=1;      AC_SUBST([HAVE_EUIDACCESS])
   HAVE_FSYNC=1;           AC_SUBST([HAVE_FSYNC])
   HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
+  HAVE_GETDOMAINNAME=1;   AC_SUBST([HAVE_GETDOMAINNAME])
   HAVE_GETDTABLESIZE=1;   AC_SUBST([HAVE_GETDTABLESIZE])
   HAVE_GETPAGESIZE=1;     AC_SUBST([HAVE_GETPAGESIZE])
+  HAVE_GETUSERSHELL=1;    AC_SUBST([HAVE_GETUSERSHELL])
   HAVE_READLINK=1;        AC_SUBST([HAVE_READLINK])
   HAVE_SLEEP=1;           AC_SUBST([HAVE_SLEEP])
   HAVE_DECL_ENVIRON=1;    AC_SUBST([HAVE_DECL_ENVIRON])
@@ -61,10 +68,12 @@
   HAVE_OS_H=0;            AC_SUBST([HAVE_OS_H])
   HAVE_SYS_PARAM_H=0;     AC_SUBST([HAVE_SYS_PARAM_H])
   REPLACE_CHOWN=0;        AC_SUBST([REPLACE_CHOWN])
+  REPLACE_CLOSE=0;        AC_SUBST([REPLACE_CLOSE])
   REPLACE_FCHDIR=0;       AC_SUBST([REPLACE_FCHDIR])
   REPLACE_GETCWD=0;       AC_SUBST([REPLACE_GETCWD])
   REPLACE_GETPAGESIZE=0;  AC_SUBST([REPLACE_GETPAGESIZE])
   REPLACE_LCHOWN=0;       AC_SUBST([REPLACE_LCHOWN])
   REPLACE_LSEEK=0;        AC_SUBST([REPLACE_LSEEK])
   REPLACE_WRITE=0;        AC_SUBST([REPLACE_WRITE])
+  UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
 ])

Added: libprelude/trunk/libmissing/netdb.in.h
===================================================================
--- libprelude/trunk/libmissing/netdb.in.h	                        (rev 0)
+++ libprelude/trunk/libmissing/netdb.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,189 @@
+/* Provide a netdb.h header file for systems lacking it (read: MinGW).
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   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 2, 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, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* This file is supposed to be used on platforms that lack <netdb.h>.
+   It is intended to provide definitions and prototypes needed by an
+   application.  */
+
+#ifndef _GL_NETDB_H
+
+#if @HAVE_NETDB_H@
+
+# if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+# endif
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_NETDB_H@
+
+#endif
+
+#ifndef _GL_NETDB_H
+#define _GL_NETDB_H
+
+#if @HAVE_NETDB_H@
+
+/* Declarations for a platform that has <netdb.h>.  */
+
+#else
+
+/* Get netdb.h definitions such as struct hostent for MinGW.  */
+#include <sys/socket.h>
+
+/* Declarations for a platform that lacks <netdb.h>.  */
+
+#if @GNULIB_GETADDRINFO@
+
+# ifndef HAVE_STRUCT_ADDRINFO
+
+/* Structure to contain information about address of a service provider.  */
+struct addrinfo
+{
+  int ai_flags;			/* Input flags.  */
+  int ai_family;		/* Protocol family for socket.  */
+  int ai_socktype;		/* Socket type.  */
+  int ai_protocol;		/* Protocol for socket.  */
+  socklen_t ai_addrlen;		/* Length of socket address.  */
+  struct sockaddr *ai_addr;	/* Socket address for socket.  */
+  char *ai_canonname;		/* Canonical name for service location.  */
+  struct addrinfo *ai_next;	/* Pointer to next in list.  */
+};
+# endif
+
+/* Possible values for `ai_flags' field in `addrinfo' structure.  */
+# ifndef AI_PASSIVE
+#  define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
+# endif
+# ifndef AI_CANONNAME
+#  define AI_CANONNAME	0x0002	/* Request for canonical name.  */
+# endif
+# ifndef AI_NUMERICSERV
+#  define AI_NUMERICSERV	0x0400	/* Don't use name resolution.  */
+# endif
+
+# if 0
+/* The commented out definitions below are not yet implemented in the
+   GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
+   cause conflicts on systems with a getaddrinfo() function which does not
+   define them.
+
+   If they are restored, be sure to protect the definitions with #ifndef.  */
+#  define AI_NUMERICHOST	0x0004	/* Don't use name resolution.  */
+#  define AI_V4MAPPED	0x0008	/* IPv4 mapped addresses are acceptable.  */
+#  define AI_ALL		0x0010	/* Return IPv4 mapped and IPv6 addresses.  */
+#  define AI_ADDRCONFIG	0x0020	/* Use configuration of this host to choose
+				   returned address type..  */
+# endif /* 0 */
+
+/* Error values for `getaddrinfo' function.  */
+# ifndef EAI_BADFLAGS
+#  define EAI_BADFLAGS	  -1	/* Invalid value for `ai_flags' field.  */
+#  define EAI_NONAME	  -2	/* NAME or SERVICE is unknown.  */
+#  define EAI_AGAIN	  -3	/* Temporary failure in name resolution.  */
+#  define EAI_FAIL	  -4	/* Non-recoverable failure in name res.  */
+#  define EAI_NODATA	  -5	/* No address associated with NAME.  */
+#  define EAI_FAMILY	  -6	/* `ai_family' not supported.  */
+#  define EAI_SOCKTYPE	  -7	/* `ai_socktype' not supported.  */
+#  define EAI_SERVICE	  -8	/* SERVICE not supported for `ai_socktype'.  */
+#  define EAI_MEMORY	  -10	/* Memory allocation failure.  */
+# endif
+
+/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
+   FreeBSD, which does define EAI_BADFLAGS) have removed the definition
+   in favor of EAI_NONAME.  */
+# if !defined EAI_NODATA && defined EAI_NONAME
+#  define EAI_NODATA EAI_NONAME
+# endif
+
+# ifndef EAI_OVERFLOW
+/* Not defined on mingw32. */
+#  define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
+# endif
+# ifndef EAI_ADDRFAMILY
+/* Not defined on mingw32. */
+#  define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */
+# endif
+# ifndef EAI_SYSTEM
+/* Not defined on mingw32. */
+#  define EAI_SYSTEM	  -11	/* System error returned in `errno'.  */
+# endif
+
+# if 0
+/* The commented out definitions below are not yet implemented in the
+   GNULIB getaddrinfo() replacement, so are not yet needed.
+
+   If they are restored, be sure to protect the definitions with #ifndef.  */
+#  ifndef EAI_INPROGRESS
+#   define EAI_INPROGRESS	-100	/* Processing request in progress.  */
+#   define EAI_CANCELED		-101	/* Request canceled.  */
+#   define EAI_NOTCANCELED	-102	/* Request not canceled.  */
+#   define EAI_ALLDONE		-103	/* All requests done.  */
+#   define EAI_INTR		-104	/* Interrupted by a signal.  */
+#   define EAI_IDN_ENCODE	-105	/* IDN encoding failed.  */
+#  endif
+# endif
+
+# if !HAVE_DECL_GETADDRINFO
+/* Translate name of a service location and/or a service name to set of
+   socket addresses.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
+extern int getaddrinfo (const char *restrict nodename,
+			const char *restrict servname,
+			const struct addrinfo *restrict hints,
+			struct addrinfo **restrict res);
+# endif
+
+# if !HAVE_DECL_FREEADDRINFO
+/* Free `addrinfo' structure AI including associated storage.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
+extern void freeaddrinfo (struct addrinfo *ai);
+# endif
+
+# if !HAVE_DECL_GAI_STRERROR
+/* Convert error return from getaddrinfo() to a string.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
+extern const char *gai_strerror (int ecode);
+# endif
+
+# if !HAVE_DECL_GETNAMEINFO
+/* Convert socket address to printable node and service names.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */
+extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
+		       char *restrict node, socklen_t nodelen,
+		       char *restrict service, socklen_t servicelen,
+		       int flags);
+# endif
+
+/* Possible flags for getnameinfo.  */
+# ifndef NI_NUMERICHOST
+#  define NI_NUMERICHOST 1
+# endif
+# ifndef NI_NUMERICSERV
+#  define NI_NUMERICSERV 2
+# endif
+
+#endif /* @GNULIB_GETADDRINFO@ */
+
+#endif /* HAVE_NETDB_H */
+
+#endif /* _GL_NETDB_H */
+#endif /* _GL_NETDB_H */

Modified: libprelude/trunk/libmissing/netinet_in.in.h
===================================================================
--- libprelude/trunk/libmissing/netinet_in.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/netinet_in.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -19,7 +19,9 @@
 
 #if @HAVE_NETINET_IN_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* On many platforms, <netinet/in.h> assumes prior inclusion of
    <sys/types.h>.  */

Modified: libprelude/trunk/libmissing/signal.in.h
===================================================================
--- libprelude/trunk/libmissing/signal.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/signal.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -15,7 +15,9 @@
    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/>.  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined __need_sig_atomic_t || defined __need_sigset_t
 /* Special invocation convention inside glibc header files.  */

Modified: libprelude/trunk/libmissing/sigprocmask.c
===================================================================
--- libprelude/trunk/libmissing/sigprocmask.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/sigprocmask.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -43,6 +43,19 @@
 # define SIGSTOP (-1)
 #endif
 
+/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
+   for the signal SIGABRT.  Only one signal handler is stored for both
+   SIGABRT and SIGABRT_COMPAT.  SIGABRT_COMPAT is not a signal of its own.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef SIGABRT_COMPAT
+# define SIGABRT_COMPAT 6
+#endif
+#ifdef SIGABRT_COMPAT
+# define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT)
+#else
+# define SIGABRT_COMPAT_MASK 0
+#endif
+
 typedef void (*handler_t) (int);
 
 /* Handling of gnulib defined signals.  */
@@ -74,7 +87,14 @@
 sigismember (const sigset_t *set, int sig)
 {
   if (sig >= 0 && sig < NSIG)
-    return (*set >> sig) & 1;
+    {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
+      return (*set >> sig) & 1;
+    }
   else
     return 0;
 }
@@ -91,6 +111,11 @@
 {
   if (sig >= 0 && sig < NSIG)
     {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
       *set |= 1U << sig;
       return 0;
     }
@@ -106,6 +131,11 @@
 {
   if (sig >= 0 && sig < NSIG)
     {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
       *set &= ~(1U << sig);
       return 0;
     }
@@ -116,10 +146,11 @@
     }
 }
 
+
 int
 sigfillset (sigset_t *set)
 {
-  *set = (2U << (NSIG - 1)) - 1;
+  *set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK;
   return 0;
 }
 
@@ -241,6 +272,11 @@
   if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP
       && handler != SIG_ERR)
     {
+      #ifdef SIGABRT_COMPAT
+      if (sig == SIGABRT_COMPAT)
+	sig = SIGABRT;
+      #endif
+
       if (blocked_set & (1U << sig))
 	{
 	  /* POSIX states that sigprocmask and signal are both

Modified: libprelude/trunk/libmissing/stdint.in.h
===================================================================
--- libprelude/trunk/libmissing/stdint.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/stdint.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -49,7 +49,9 @@
      in <inttypes.h> would reinclude us, skipping our contents because
      _GL_STDINT_H is defined.
      The include_next requires a split double-inclusion guard.  */
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 # @INCLUDE_NEXT@ @NEXT_STDINT_H@
 #endif
 

Modified: libprelude/trunk/libmissing/stdio.in.h
===================================================================
--- libprelude/trunk/libmissing/stdio.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/stdio.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -16,7 +16,9 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined __need_FILE || defined __need___FILE
 /* Special invocation convention inside glibc header files.  */
@@ -373,6 +375,21 @@
     fflush (f))
 #endif
 
+#if @GNULIB_FCLOSE@
+# if @REPLACE_FCLOSE@
+#  define fclose rpl_fclose
+  /* Close STREAM and its underlying file descriptor.  */
+extern int fclose (FILE *stream);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef fclose
+# define fclose(f) \
+   (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
+                     "use gnulib module fclose for portable " \
+                     "POSIX compliance"), \
+    fclose (f))
+#endif
+
 #if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
 # undef fputc
 # define fputc rpl_fputc

Modified: libprelude/trunk/libmissing/stdlib.in.h
===================================================================
--- libprelude/trunk/libmissing/stdlib.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/stdlib.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -15,7 +15,9 @@
    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/>.  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined __need_malloc_and_calloc
 /* Special invocation convention inside glibc header files.  */
@@ -34,6 +36,11 @@
 #define _GL_STDLIB_H
 
 
+/* Solaris declares getloadavg() in <sys/loadavg.h>.  */
+#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
+# include <sys/loadavg.h>
+#endif
+
 /* The definition of GL_LINK_WARNING is copied here.  */
 
 
@@ -101,6 +108,38 @@
 #endif
 
 
+#if @GNULIB_ATOLL@
+# if !@HAVE_ATOLL@
+/* Parse a signed decimal integer.
+   Returns the value of the integer.  Errors are not detected.  */
+extern long long atoll (const char *string);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef atoll
+# define atoll(s) \
+    (GL_LINK_WARNING ("atoll is unportable - " \
+                      "use gnulib module atoll for portability"), \
+     atoll (s))
+#endif
+
+
+#if @GNULIB_GETLOADAVG@
+# if !@HAVE_DECL_GETLOADAVG@
+/* Store max(NELEM,3) load average numbers in LOADAVG[].
+   The three numbers are the load average of the last 1 minute, the last 5
+   minutes, and the last 15 minutes, respectively.
+   LOADAVG is an array of NELEM numbers.  */
+extern int getloadavg (double loadavg[], int nelem);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getloadavg
+# define getloadavg(l,n) \
+    (GL_LINK_WARNING ("getloadavg is not portable - " \
+                      "use gnulib module getloadavg for portability"), \
+     getloadavg (l, n))
+#endif
+
+
 #if @GNULIB_GETSUBOPT@
 /* Assuming *OPTIONP is a comma separated list of elements of the form
    "token" or "token=value", getsubopt parses the first of these elements.
@@ -233,6 +272,48 @@
 #endif
 
 
+#if @GNULIB_STRTOLL@
+# if !@HAVE_STRTOLL@
+/* Parse a signed integer whose textual representation starts at STRING.
+   The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
+   it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
+   "0x").
+   If ENDPTR is not NULL, the address of the first byte after the integer is
+   stored in *ENDPTR.
+   Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
+   to ERANGE.  */
+extern long long strtoll (const char *string, char **endptr, int base);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef strtoll
+# define strtoll(s,e,b) \
+    (GL_LINK_WARNING ("strtoll is unportable - " \
+                      "use gnulib module strtoll for portability"), \
+     strtoll (s, e, b))
+#endif
+
+
+#if @GNULIB_STRTOULL@
+# if !@HAVE_STRTOULL@
+/* Parse an unsigned integer whose textual representation starts at STRING.
+   The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
+   it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
+   "0x").
+   If ENDPTR is not NULL, the address of the first byte after the integer is
+   stored in *ENDPTR.
+   Upon overflow, the return value is ULLONG_MAX, and errno is set to
+   ERANGE.  */
+extern unsigned long long strtoull (const char *string, char **endptr, int base);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef strtoull
+# define strtoull(s,e,b) \
+    (GL_LINK_WARNING ("strtoull is unportable - " \
+                      "use gnulib module strtoull for portability"), \
+     strtoull (s, e, b))
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: libprelude/trunk/libmissing/string.in.h
===================================================================
--- libprelude/trunk/libmissing/string.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/string.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,7 +18,9 @@
 
 #ifndef _GL_STRING_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_STRING_H@

Modified: libprelude/trunk/libmissing/strings.in.h
===================================================================
--- libprelude/trunk/libmissing/strings.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/strings.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,7 +18,9 @@
 
 #ifndef _GL_STRINGS_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_STRINGS_H@

Modified: libprelude/trunk/libmissing/sys_select.in.h
===================================================================
--- libprelude/trunk/libmissing/sys_select.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/sys_select.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -19,7 +19,9 @@
 
 #if @HAVE_SYS_SELECT_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* On many platforms, <sys/select.h> assumes prior inclusion of
    <sys/types.h>.  */

Modified: libprelude/trunk/libmissing/sys_socket.in.h
===================================================================
--- libprelude/trunk/libmissing/sys_socket.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/sys_socket.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -27,7 +27,9 @@
 
 #if @HAVE_SYS_SOCKET_H@
 
+# if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+# endif
 
 /* On many platforms, <sys/socket.h> assumes prior inclusion of
    <sys/types.h>.  */
@@ -138,10 +140,9 @@
 
 /* Wrap everything else to use libc file descriptors for sockets.  */
 
-# if @HAVE_WINSOCK2_H@
+# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
 #  undef close
-#  define close			rpl_close
-extern int rpl_close(int);
+#  define close close_used_without_including_unistd_h
 # endif
 
 # if @GNULIB_SOCKET@
@@ -280,12 +281,6 @@
       listen (s, b))
 # endif
 
-# if @HAVE_WINSOCK2_H@
-#  undef ioctl
-#  define ioctl			rpl_ioctl
-extern int rpl_ioctl (int, unsigned long, char *);
-# endif
-
 # if @GNULIB_RECV@
 #  if @HAVE_WINSOCK2_H@
 #   undef recv
@@ -371,11 +366,34 @@
       setsockopt (s, lvl, o, v, l))
 # endif
 
+# if @GNULIB_SHUTDOWN@
+#  if @HAVE_WINSOCK2_H@
+#   undef shutdown
+#   define shutdown		rpl_shutdown
+extern int rpl_shutdown (int, int);
+#  endif
+# elif @HAVE_WINSOCK2_H@
+#  undef shutdown
+#  define shutdown shutdown_used_without_requesting_gnulib_module_shutdown
+# elif defined GNULIB_POSIXCHECK
+#  undef shutdown
+#  define shutdown(s,h) \
+     (GL_LINK_WARNING ("shutdown is not always POSIX compliant - " \
+                       "use gnulib module shutdown for portability"), \
+      shutdown (s, h))
+# endif
+
 # if @HAVE_WINSOCK2_H@
 #  undef select
 #  define select		select_used_without_including_sys_select_h
 # endif
 
+# if @GNULIB_CLOSE@ && @HAVE_WINSOCK2_H@
+/* gnulib internal function.  */
+#  define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
+extern int _gl_close_fd_maybe_socket (int fd);
+# endif
+
 # ifdef __cplusplus
 }
 # endif

Modified: libprelude/trunk/libmissing/sys_stat.in.h
===================================================================
--- libprelude/trunk/libmissing/sys_stat.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/sys_stat.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,5 +1,5 @@
 /* Provide a more complete sys/stat header file.
-   Copyright (C) 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 2005-2008 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
@@ -21,16 +21,28 @@
    incomplete.  It is intended to provide definitions and prototypes
    needed by an application.  Start with what the system provides.  */
 
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+#if defined __need_system_sys_stat_h
+/* Special invocation convention.  */
+
+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
+
+#else
+/* Normal invocation convention.  */
+
 #ifndef _GL_SYS_STAT_H
 
-@PRAGMA_SYSTEM_HEADER@
-
 /* The include_next requires a split double-inclusion guard.  */
 #@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
 
 #ifndef _GL_SYS_STAT_H
 #define _GL_SYS_STAT_H
 
+/* The definition of GL_LINK_WARNING is copied here.  */
+
 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
    headers that may declare mkdir().  */
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
@@ -268,7 +280,13 @@
 #if ! @HAVE_LSTAT@
 # define lstat stat
 #endif
+#if @GNULIB_LSTAT@ && @REPLACE_LSTAT@
+# undef lstat
+# define lstat rpl_lstat
+extern int rpl_lstat (const char *name, struct stat *buf);
+#endif
 
+
 #if @REPLACE_MKDIR@
 # undef mkdir
 # define mkdir rpl_mkdir
@@ -289,5 +307,33 @@
 # endif
 #endif
 
+
+/* Declare BSD extensions.  */
+
+#if @GNULIB_LCHMOD@
+/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
+   denotes a symbolic link.  */
+# if !@HAVE_LCHMOD@
+/* The lchmod replacement follows symbolic links.  Callers should take
+   this into account; lchmod should be applied only to arguments that
+   are known to not be symbolic links.  On hosts that lack lchmod,
+   this can lead to race conditions between the check and the
+   invocation of lchmod, but we know of no workarounds that are
+   reliable in general.  You might try requesting support for lchmod
+   from your operating system supplier.  */
+#  define lchmod chmod
+# endif
+# if 0 /* assume already declared */
+extern int lchmod (const char *filename, mode_t mode);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lchmod
+# define lchmod(f,m) \
+    (GL_LINK_WARNING ("lchmod is unportable - " \
+                      "use gnulib module lchmod for portability"), \
+     lchmod (f, m))
+#endif
+
 #endif /* _GL_SYS_STAT_H */
 #endif /* _GL_SYS_STAT_H */
+#endif

Modified: libprelude/trunk/libmissing/sys_time.in.h
===================================================================
--- libprelude/trunk/libmissing/sys_time.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/sys_time.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,7 +18,9 @@
 
 /* Written by Paul Eggert.  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if defined _GL_SYS_TIME_H
 

Modified: libprelude/trunk/libmissing/tests/Makefile.am
===================================================================
--- libprelude/trunk/libmissing/tests/Makefile.am	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/tests/Makefile.am	2008-10-21 08:58:44 UTC (rev 11074)
@@ -87,6 +87,15 @@
 
 ## end   gnulib module c-ctype-tests
 
+## begin gnulib module close
+
+
+EXTRA_DIST += close.c
+
+EXTRA_libtests_a_SOURCES += close.c
+
+## end   gnulib module close
+
 ## begin gnulib module cond-tests
 
 TESTS += test-cond
@@ -105,6 +114,15 @@
 
 ## end   gnulib module errno-tests
 
+## begin gnulib module fclose
+
+
+EXTRA_DIST += fclose.c
+
+EXTRA_libtests_a_SOURCES += fclose.c
+
+## end   gnulib module fclose
+
 ## begin gnulib module fopen-tests
 
 TESTS += test-fopen
@@ -212,6 +230,15 @@
 
 ## end   gnulib module memmem-tests
 
+## begin gnulib module netdb-tests
+
+TESTS += test-netdb
+check_PROGRAMS += test-netdb
+
+EXTRA_DIST += test-netdb.c
+
+## end   gnulib module netdb-tests
+
 ## begin gnulib module netinet_in-tests
 
 TESTS += test-netinet_in

Added: libprelude/trunk/libmissing/tests/close.c
===================================================================
--- libprelude/trunk/libmissing/tests/close.c	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/close.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,45 @@
+/* close replacement.
+   Copyright (C) 2008 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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#if GNULIB_SYS_SOCKET
+# include <sys/socket.h>
+#endif
+
+
+/* Override close() to call into other gnulib modules.  */
+
+int
+rpl_close (int fd)
+#undef close
+{
+#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
+  int retval = _gl_close_fd_maybe_socket (fd);
+#else
+  int retval = close (fd);
+#endif
+
+#ifdef FCHDIR_REPLACEMENT
+  if (retval >= 0)
+    _gl_unregister_fd (fd);
+#endif
+
+  return retval;
+}

Added: libprelude/trunk/libmissing/tests/fclose.c
===================================================================
--- libprelude/trunk/libmissing/tests/fclose.c	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/fclose.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,47 @@
+/* fclose replacement.
+   Copyright (C) 2008 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/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+/* Override fclose() to call the overridden close().  */
+
+int
+rpl_fclose (FILE *fp)
+#undef fclose
+{
+  int saved_errno = 0;
+
+  if (fflush (fp))
+    saved_errno = errno;
+
+  if (close (fileno (fp)) < 0 && saved_errno == 0)
+    saved_errno = errno;
+
+  fclose (fp); /* will fail with errno = EBADF */
+
+  if (saved_errno != 0)
+    {
+      errno = saved_errno;
+      return EOF;
+    }
+  return 0;
+}

Modified: libprelude/trunk/libmissing/tests/test-getaddrinfo.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-getaddrinfo.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/tests/test-getaddrinfo.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,7 +18,7 @@
 /* Written by Simon Josefsson.  */
 
 #include <config.h>
-#include "getaddrinfo.h"
+#include <netdb.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <stdio.h>

Modified: libprelude/trunk/libmissing/tests/test-lock.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-lock.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/tests/test-lock.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -20,6 +20,19 @@
 
 #if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || USE_WIN32_THREADS
 
+#if USE_POSIX_THREADS
+# define TEST_POSIX_THREADS 1
+#endif
+#if USE_SOLARIS_THREADS
+# define TEST_SOLARIS_THREADS 1
+#endif
+#if USE_PTH_THREADS
+# define TEST_PTH_THREADS 1
+#endif
+#if USE_WIN32_THREADS
+# define TEST_WIN32_THREADS 1
+#endif
+
 /* Whether to enable locking.
    Uncomment this to get a test program without locking, to verify that
    it crashes.  */

Added: libprelude/trunk/libmissing/tests/test-netdb.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-netdb.c	                        (rev 0)
+++ libprelude/trunk/libmissing/tests/test-netdb.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -0,0 +1,29 @@
+/* Test of <netdb.h> substitute.
+   Copyright (C) 2007-2008 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 Simon Josefsson <[email protected]>, 2008.  */
+
+#include <config.h>
+#include <netdb.h>
+
+/* Check that the 'struct hostent' type is defined.  */
+struct hostent t1;
+
+int
+main (void)
+{
+  return 0;
+}

Modified: libprelude/trunk/libmissing/tests/test-poll.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-poll.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/tests/test-poll.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdbool.h>
+#include <sys/ioctl.h>
 #include <errno.h>
 #include "sockets.h"
 
@@ -367,10 +368,8 @@
 #endif
 
   result = test (test_connect_first, "Unconnected socket test");
-#if ! defined(__OpenBSD__)
   result += test (test_socket_pair, "Connected sockets test");
   result += test (test_accept_first, "General socket test with fork");
-#endif
   result += test (test_pipe, "Pipe test");
 
   exit (result);

Modified: libprelude/trunk/libmissing/tests/test-select.c
===================================================================
--- libprelude/trunk/libmissing/tests/test-select.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/tests/test-select.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdbool.h>
+#include <sys/ioctl.h>
 #include <errno.h>
 #include "sockets.h"
 

Modified: libprelude/trunk/libmissing/tests/winsock.c
===================================================================
--- libprelude/trunk/libmissing/tests/winsock.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/tests/winsock.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,14 +18,17 @@
 /* Written by Paolo Bonzini */
 
 #include <config.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <io.h>
 #include <sys/socket.h>
+#if GNULIB_IOCTL
+#include <sys/ioctl.h>
+#endif
 
-#undef close
 #undef socket
 #undef connect
 #undef accept
@@ -39,38 +42,12 @@
 #undef recvfrom
 #undef sendto
 #undef setsockopt
+#undef shutdown
 
-# define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
-# define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
 
 
-/* Wrappers for libc functions.  */
-
-int
-rpl_close (int fd)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  WSANETWORKEVENTS ev;
-
-  ev.lNetworkEvents = 0xDEADBEEF;
-  WSAEnumNetworkEvents (sock, NULL, &ev);
-  if (ev.lNetworkEvents != 0xDEADBEEF)
-    {
-      /* FIXME: other applications, like squid, use an undocumented
-	 _free_osfhnd free function.  Instead, here we just close twice
-	 the file descriptor.  I could not get the former to work
-	 (pb, Sep 22 2008).  */
-      int r = closesocket (sock);
-      _close (fd);
-      return r;
-    }
-  else
-    return _close (fd);
-}
-
-
-/* Wrappers for WinSock functions.  */
-
 static inline void
 set_winsock_errno (void)
 {
@@ -104,6 +81,45 @@
     }
 }
 
+
+/* Hook for gnulib module close.  */
+
+#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
+int
+_gl_close_fd_maybe_socket (int fd)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  WSANETWORKEVENTS ev;
+
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents (sock, NULL, &ev);
+  if (ev.lNetworkEvents != 0xDEADBEEF)
+    {
+      /* FIXME: other applications, like squid, use an undocumented
+	 _free_osfhnd free function.  But this is not enough: The 'osfile'
+	 flags for fd also needs to be cleared, but it is hard to access it.
+	 Instead, here we just close twice the file descriptor.  */
+      if (closesocket (sock))
+	{
+	  set_winsock_errno ();
+	  return -1;
+	}
+      else
+	{
+	  /* This call frees the file descriptor and does a
+	     CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
+	  _close (fd);
+	  return 0;
+	}
+    }
+  else
+    return _close (fd);
+}
+#endif
+
+
+/* Wrappers for WinSock functions.  */
+
 #if GNULIB_SOCKET
 int
 rpl_socket (int domain, int type, int protocol)
@@ -222,16 +238,27 @@
 }
 #endif
 
+#if GNULIB_IOCTL
 int
-rpl_ioctl (int fd, unsigned long req, char *buf)
+rpl_ioctl (int fd, int req, ...)
 {
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = ioctlsocket (sock, req, (void *) buf);
+  void *buf;
+  va_list args;
+  SOCKET sock;
+  int r;
+
+  va_start (args, req);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  sock = FD_TO_SOCKET (fd);
+  r = ioctlsocket (sock, req, buf);
   if (r < 0)
     set_winsock_errno ();
 
   return r;
 }
+#endif
 
 #if GNULIB_RECV
 int
@@ -306,3 +333,16 @@
   return r;
 }
 #endif
+
+#if GNULIB_SHUTDOWN
+int
+rpl_shutdown (int fd, int how)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = shutdown (sock, how);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
+#endif

Modified: libprelude/trunk/libmissing/time.in.h
===================================================================
--- libprelude/trunk/libmissing/time.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/time.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -16,7 +16,9 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* Don't get in the way of glibc when it includes time.h merely to
    declare a few standard symbols, rather than to declare all the

Modified: libprelude/trunk/libmissing/unistd.in.h
===================================================================
--- libprelude/trunk/libmissing/unistd.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/unistd.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -1,5 +1,5 @@
 /* Substitute for and wrapper around <unistd.h>.
-   Copyright (C) 2004-2008 Free Software Foundation, Inc.
+   Copyright (C) 2003-2008 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
@@ -17,7 +17,9 @@
 
 #ifndef _GL_UNISTD_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_UNISTD_H@
@@ -75,6 +77,25 @@
 #endif
 
 
+#if @GNULIB_CLOSE@
+# if @REPLACE_CLOSE@
+/* Automatically included by modules that need a replacement for close.  */
+#  undef close
+#  define close rpl_close
+extern int close (int);
+# endif
+#elif @UNISTD_H_HAVE_WINSOCK2_H@
+# undef close
+# define close close_used_without_requesting_gnulib_module_close
+#elif defined GNULIB_POSIXCHECK
+# undef close
+# define close(f) \
+    (GL_LINK_WARNING ("close does not portably work on sockets - " \
+                      "use gnulib module close for portability"), \
+     close (f))
+#endif
+
+
 #if @GNULIB_DUP2@
 # if !@HAVE_DUP2@
 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
@@ -113,6 +134,21 @@
 #endif
 
 
+#if @GNULIB_EUIDACCESS@
+# if !@HAVE_EUIDACCESS@
+/* Like access(), except that is uses the effective user id and group id of
+   the current process.  */
+extern int euidaccess (const char *filename, int mode);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef euidaccess
+# define euidaccess(f,m) \
+    (GL_LINK_WARNING ("euidaccess is unportable - " \
+                      "use gnulib module euidaccess for portability"), \
+     euidaccess (f, m))
+#endif
+
+
 #if @GNULIB_FCHDIR@
 # if @REPLACE_FCHDIR@
 
@@ -123,8 +159,6 @@
    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
 extern int fchdir (int /*fd*/);
 
-#  define close rpl_close
-extern int close (int);
 #  define dup rpl_dup
 extern int dup (int);
 #  define dup2 rpl_dup2
@@ -201,6 +235,29 @@
 #endif
 
 
+#if @GNULIB_GETDOMAINNAME@
+/* Return the NIS domain name of the machine.
+   WARNING! The NIS domain name is unrelated to the fully qualified host name
+            of the machine.  It is also unrelated to email addresses.
+   WARNING! The NIS domain name is usually the empty string or "(none)" when
+            not using NIS.
+
+   Put up to LEN bytes of the NIS domain name into NAME.
+   Null terminate it if the name is shorter than LEN.
+   If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
+   Return 0 if successful, otherwise set errno and return -1.  */
+# if !@HAVE_GETDOMAINNAME@
+extern int getdomainname(char *name, size_t len);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getdomainname
+# define getdomainname(n,l) \
+    (GL_LINK_WARNING ("getdomainname is unportable - " \
+                      "use gnulib module getdomainname for portability"), \
+     getdomainname (n, l))
+#endif
+
+
 #if @GNULIB_GETDTABLESIZE@
 # if !@HAVE_GETDTABLESIZE@
 /* Return the maximum number of file descriptors in the current process.  */
@@ -296,6 +353,36 @@
 #endif
 
 
+#if @GNULIB_GETUSERSHELL@
+# if !@HAVE_GETUSERSHELL@
+/* Return the next valid login shell on the system, or NULL when the end of
+   the list has been reached.  */
+extern char *getusershell (void);
+/* Rewind to pointer that is advanced at each getusershell() call.  */
+extern void setusershell (void);
+/* Free the pointer that is advanced at each getusershell() call and
+   associated resources.  */
+extern void endusershell (void);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getusershell
+# define getusershell() \
+    (GL_LINK_WARNING ("getusershell is unportable - " \
+                      "use gnulib module getusershell for portability"), \
+     getusershell ())
+# undef setusershell
+# define setusershell() \
+    (GL_LINK_WARNING ("setusershell is unportable - " \
+                      "use gnulib module getusershell for portability"), \
+     setusershell ())
+# undef endusershell
+# define endusershell() \
+    (GL_LINK_WARNING ("endusershell is unportable - " \
+                      "use gnulib module getusershell for portability"), \
+     endusershell ())
+#endif
+
+
 #if @GNULIB_LCHOWN@
 # if @REPLACE_LCHOWN@
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
@@ -379,6 +466,12 @@
 #endif
 
 
+#ifdef FCHDIR_REPLACEMENT
+/* gnulib internal function.  */
+extern void _gl_unregister_fd (int fd);
+#endif
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: libprelude/trunk/libmissing/wchar.in.h
===================================================================
--- libprelude/trunk/libmissing/wchar.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/wchar.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -26,7 +26,9 @@
  * the declaration of wcwidth().
  */
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #ifdef __need_mbstate_t
 /* Special invocation convention inside uClibc header files.  */

Modified: libprelude/trunk/libmissing/wctype.in.h
===================================================================
--- libprelude/trunk/libmissing/wctype.in.h	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/wctype.in.h	2008-10-21 08:58:44 UTC (rev 11074)
@@ -28,7 +28,9 @@
 
 #ifndef _GL_WCTYPE_H
 
+#if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
+#endif
 
 #if @HAVE_WINT_T@
 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.

Modified: libprelude/trunk/libmissing/winsock.c
===================================================================
--- libprelude/trunk/libmissing/winsock.c	2008-10-17 13:10:13 UTC (rev 11073)
+++ libprelude/trunk/libmissing/winsock.c	2008-10-21 08:58:44 UTC (rev 11074)
@@ -18,14 +18,17 @@
 /* Written by Paolo Bonzini */
 
 #include <config.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <io.h>
 #include <sys/socket.h>
+#if GNULIB_IOCTL
+#include <sys/ioctl.h>
+#endif
 
-#undef close
 #undef socket
 #undef connect
 #undef accept
@@ -39,38 +42,12 @@
 #undef recvfrom
 #undef sendto
 #undef setsockopt
+#undef shutdown
 
-# define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
-# define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
 
 
-/* Wrappers for libc functions.  */
-
-int
-rpl_close (int fd)
-{
-  SOCKET sock = FD_TO_SOCKET (fd);
-  WSANETWORKEVENTS ev;
-
-  ev.lNetworkEvents = 0xDEADBEEF;
-  WSAEnumNetworkEvents (sock, NULL, &ev);
-  if (ev.lNetworkEvents != 0xDEADBEEF)
-    {
-      /* FIXME: other applications, like squid, use an undocumented
-	 _free_osfhnd free function.  Instead, here we just close twice
-	 the file descriptor.  I could not get the former to work
-	 (pb, Sep 22 2008).  */
-      int r = closesocket (sock);
-      _close (fd);
-      return r;
-    }
-  else
-    return _close (fd);
-}
-
-
-/* Wrappers for WinSock functions.  */
-
 static inline void
 set_winsock_errno (void)
 {
@@ -104,6 +81,45 @@
     }
 }
 
+
+/* Hook for gnulib module close.  */
+
+#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
+int
+_gl_close_fd_maybe_socket (int fd)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  WSANETWORKEVENTS ev;
+
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents (sock, NULL, &ev);
+  if (ev.lNetworkEvents != 0xDEADBEEF)
+    {
+      /* FIXME: other applications, like squid, use an undocumented
+	 _free_osfhnd free function.  But this is not enough: The 'osfile'
+	 flags for fd also needs to be cleared, but it is hard to access it.
+	 Instead, here we just close twice the file descriptor.  */
+      if (closesocket (sock))
+	{
+	  set_winsock_errno ();
+	  return -1;
+	}
+      else
+	{
+	  /* This call frees the file descriptor and does a
+	     CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
+	  _close (fd);
+	  return 0;
+	}
+    }
+  else
+    return _close (fd);
+}
+#endif
+
+
+/* Wrappers for WinSock functions.  */
+
 #if GNULIB_SOCKET
 int
 rpl_socket (int domain, int type, int protocol)
@@ -222,16 +238,27 @@
 }
 #endif
 
+#if GNULIB_IOCTL
 int
-rpl_ioctl (int fd, unsigned long req, char *buf)
+rpl_ioctl (int fd, int req, ...)
 {
-  SOCKET sock = FD_TO_SOCKET (fd);
-  int r = ioctlsocket (sock, req, (void *) buf);
+  void *buf;
+  va_list args;
+  SOCKET sock;
+  int r;
+
+  va_start (args, req);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  sock = FD_TO_SOCKET (fd);
+  r = ioctlsocket (sock, req, buf);
   if (r < 0)
     set_winsock_errno ();
 
   return r;
 }
+#endif
 
 #if GNULIB_RECV
 int
@@ -306,3 +333,16 @@
   return r;
 }
 #endif
+
+#if GNULIB_SHUTDOWN
+int
+rpl_shutdown (int fd, int how)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r = shutdown (sock, how);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
+#endif

_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.