Override <sys/socket.h> when it exists but is incomplete.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2008 12:56:42 +0000 (14:56 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2008 12:56:42 +0000 (14:56 +0200)
ChangeLog
doc/posix-headers/sys_socket.texi
lib/sys_socket.in.h
m4/sys_socket_h.m4
modules/sys_socket

index 44deb66a8942f90960348c1eb5c86bd79dacc939..c2117a8df1160cebc1898a69669b20c212120f56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-04-13  Bruno Haible  <bruno@clisp.org>
+
+       * doc/posix-headers/sys_socket.texi: Document the problem on EMX.
+       * lib/sys_socket.in.h (SHUT_RD, SHUT_WR, SHUT_RDWR): Define if missing.
+       * m4/sys_socket_h.m4 (gl_HEADER_SYS_SOCKET): Replace <sys/socket.h>
+       also if it exists but lacks definitions of the SHUT_* macros.
+       * modules/sys_socket (Description): Update.
+       Reported by Elbert Pol <e.pol@chello.nl>.
+
 2008-04-13  Bruno Haible  <bruno@clisp.org>
 
        * lib/localcharset.c (OS2): Don't redefine if already defined.
index de71813f3145a6a141fa44a7b81face48a812df1..4680fa2f9a8b205eb11b0fe38a3d41ef4ba48145 100644 (file)
@@ -13,6 +13,11 @@ mingw.
 @item
 This header file is not self-contained on some platforms: it requires
 @code{<sys/types.h>} to be included first.
+@item
+This header file is lacking the @code{SHUT_RD}, @code{SHUT_WR},
+@code{SHUT_RDWR} macros on some platforms, despite having the @code{shutdown}
+functions:
+emx+gcc.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index c25b6ab842071e6008d01533f38902323432ceac..d94f425fcbdb295b0eb1b128810e5e4de8160241 100644 (file)
@@ -1,5 +1,6 @@
-/* Provide a sys/socket header file for systems lacking it (read: MinGW).
-   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+/* Provide a sys/socket header file for systems lacking it (read: MinGW)
+   and for systems where it is incomplete.
+   Copyright (C) 2005-2008 Free Software Foundation, Inc.
    Written by Simon Josefsson.
 
    This program is free software; you can redistribute it and/or modify
@@ -16,8 +17,9 @@
    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 <sys/socket.h>
-   and on platforms where <sys/socket.h> cannot be included standalone.
+/* This file is supposed to be used on platforms that lack <sys/socket.h>,
+   on platforms where <sys/socket.h> cannot be included standalone, and on
+   platforms where <sys/socket.h> does not provide all necessary definitions.
    It is intended to provide definitions and prototypes needed by an
    application.  */
 
 #ifndef _GL_SYS_SOCKET_H
 #define _GL_SYS_SOCKET_H
 
-#if !@HAVE_SYS_SOCKET_H@
+#if @HAVE_SYS_SOCKET_H@
+
+/* A platform that has <sys/socket.h>.  */
+
+/* For shutdown().  */
+# if !defined SHUT_RD
+#  define SHUT_RD 0
+# endif
+# if !defined SHUT_WR
+#  define SHUT_WR 1
+# endif
+# if !defined SHUT_RDWR
+#  define SHUT_RDWR 2
+# endif
+
+#else
 
 /* A platform that lacks <sys/socket.h>.
 
index d9659c2d75eee465474b20db7b34996fafed0389..887cff80ebb60f077326e80bf69e141c5fc36283 100644 (file)
@@ -1,5 +1,5 @@
-# sys_socket_h.m4 serial 4
-dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+# sys_socket_h.m4 serial 5
+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,
 dnl with or without modifications, as long as this notice is preserved.
@@ -17,9 +17,28 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
     ])
   if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
     SYS_SOCKET_H=''
+    dnl If the shutdown function exists, <sys/socket.h> should define
+    dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
+    AC_CHECK_FUNCS([shutdown])
+    if test $ac_cv_func_shutdown = yes; then
+      AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
+        [gl_cv_header_sys_socket_h_shut],
+        [
+          AC_COMPILE_IFELSE(
+            [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
+               [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
+            [gl_cv_header_sys_socket_h_shut=yes],
+            [gl_cv_header_sys_socket_h_shut=no])
+        ])
+      if test $gl_cv_header_sys_socket_h_shut = no; then
+        SYS_SOCKET_H='sys/socket.h'
+      fi
+    fi
   else
     SYS_SOCKET_H='sys/socket.h'
-
+  fi
+  if test -n "$SYS_SOCKET_H"; then
+    dnl Check prerequisites of the <sys/socket.h> replacement.
     gl_CHECK_NEXT_HEADERS([sys/socket.h])
     if test $ac_cv_header_sys_socket_h = yes; then
       HAVE_SYS_SOCKET_H=1
index 0c7b6dbb302a18d03c20f480baeb325f83f70d58..36af3cbca149457bdee0d8ec5ac32a2c26dc66ee 100644 (file)
@@ -1,5 +1,5 @@
 Description:
-A <sys/socket.h> for systems lacking it.
+A POSIX-like <sys/socket.h>.
 
 Files:
 lib/sys_socket.in.h