bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sys_socket module: make <sys/socket.h> self-contained


From: Bruno Haible
Subject: sys_socket module: make <sys/socket.h> self-contained
Date: Sat, 3 Mar 2007 02:33:31 +0100
User-agent: KMail/1.5.4

Hi Simon,

In the <sys/socket.h> test that I added a few weeks ago, I assumed - like
specified in POSIX:2001 - a self-contained <sys/socket.h>. However, the
current sys_socket module says that I should include <sys/types.h> before
it. And indeed, without <sys/types.h> before <sys/socket.h>, the test
fails on MacOS X:

gcc -DHAVE_CONFIG_H -I.  -I. -I. -I.. -I./.. -I../gllib -I./../gllib   -g -O2 
-MT test-sys_socket.o -MD -MP -MF .deps/test-sys_socket.Tpo -c -o 
test-sys_socket.o test-sys_socket.c
In file included from test-sys_socket.c:22:
/usr/include/sys/socket.h:77: error: parse error before "sa_family_t"
/usr/include/sys/socket.h:213: error: parse error before "u_char"
/usr/include/sys/socket.h:216: error: parse error before '}' token
/usr/include/sys/socket.h:224: error: parse error before "u_short"
/usr/include/sys/socket.h:238: error: parse error before "u_char"
/usr/include/sys/socket.h:240: error: `int64_t' undeclared here (not in a 
function)
/usr/include/sys/socket.h:240: error: `u_char' undeclared here (not in a 
function)
...

Since our goal is to allow people to program against the POSIX specifications,
here is a proposed patch. It causes lib/sys/socket.h to be created on
systems like MacOS X. Tested on Linux, MacOS X, mingw.


2007-03-02  Bruno Haible  <address@hidden>

        * lib/socket_.h: If sys/socket.h exists, include that and <sys/types.h>
        before it. Turn HAVE_WINSOCK2_H and HAVE_WS2TCPIP_H into configute-time
        values.
        * m4/sys_socket_h.m4 (gl_HEADER_SYS_SOCKET): Test also whether
        <sys/socket.h> is self-contained. Set ABSOLUTE_SYS_SOCKET_H,
        HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H, HAVE_WS2TCPIP_H.
        * modules/sys_socket (Depends-on): Add absolute-header.
        (Makefile.am): Substitute ABSOLUTE_SYS_SOCKET_H, HAVE_SYS_SOCKET_H,
        HAVE_WINSOCK2_H, HAVE_WS2TCPIP_H into sys/socket.h.
        (Include): Remove requirement of inclusion of <sys/types.h>.

*** lib/socket_.h       16 Jan 2007 12:43:13 -0000      1.8
--- lib/socket_.h       3 Mar 2007 01:21:26 -0000
***************
*** 1,5 ****
  /* Provide a sys/socket header file for systems lacking it (read: MinGW).
!    Copyright (C) 2005, 2006 Free Software Foundation, Inc.
     Written by Simon Josefsson.
  
     This program is free software; you can redistribute it and/or modify
--- 1,5 ----
  /* Provide a sys/socket header file for systems lacking it (read: MinGW).
!    Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
     Written by Simon Josefsson.
  
     This program is free software; you can redistribute it and/or modify
***************
*** 16,27 ****
     along with this program; if not, write to the Free Software Foundation,
     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
  
! #ifndef _SYS_SOCKET_H
! #define _SYS_SOCKET_H
  
! /* This file is supposed to be used on platforms that lack
!    sys/socket.h.  It is intended to provide definitions and prototypes
!    needed by an application.
  
     Currently only MinGW is supported.  See the gnulib manual regarding
     Windows sockets.  MinGW has the header files winsock2.h and
--- 16,40 ----
     along with this program; if not, write to the Free Software Foundation,
     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
  
! #ifndef GL_SYS_SOCKET_H
! #define GL_SYS_SOCKET_H
  
! /* 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.
!    It is intended to provide definitions and prototypes needed by an
!    application.  */
! 
! #if @HAVE_SYS_SOCKET_H@
! 
! /* On many platforms, <sys/socket.h> assumes prior inclusion of
!    <sys/types.h>.  */
! 
! # include <sys/types.h>
! # include @ABSOLUTE_SYS_SOCKET_H@
! 
! #else
! 
! /* A platform that lacks <sys/socket.h>.
  
     Currently only MinGW is supported.  See the gnulib manual regarding
     Windows sockets.  MinGW has the header files winsock2.h and
***************
*** 39,70 ****
     releases. */
  
  
! #if HAVE_WINSOCK2_H
! # include <winsock2.h>
! #endif
! #if HAVE_WS2TCPIP_H
! # include <ws2tcpip.h>
! #endif
  
  /* For shutdown(). */
! #if !defined SHUT_RD && defined SD_RECEIVE
! # define SHUT_RD SD_RECEIVE
! #endif
! #if !defined SHUT_WR && defined SD_SEND
! # define SHUT_WR SD_SEND
! #endif
! #if !defined SHUT_RDWR && defined SD_BOTH
! # define SHUT_RDWR SD_BOTH
! #endif
! 
! #if defined _WIN32 || defined __WIN32__
! # define ENOTSOCK                WSAENOTSOCK
! # define EADDRINUSE              WSAEADDRINUSE
! # define ENETRESET               WSAENETRESET
! # define ECONNABORTED            WSAECONNABORTED
! # define ECONNRESET              WSAECONNRESET
! # define ENOTCONN                WSAENOTCONN
! # define ESHUTDOWN               WSAESHUTDOWN
! #endif
  
! #endif /* _SYS_SOCKET_H */
--- 52,85 ----
     releases. */
  
  
! # if @HAVE_WINSOCK2_H@
! #  include <winsock2.h>
! # endif
! # if @HAVE_WS2TCPIP_H@
! #  include <ws2tcpip.h>
! # endif
  
  /* For shutdown(). */
! # if !defined SHUT_RD && defined SD_RECEIVE
! #  define SHUT_RD SD_RECEIVE
! # endif
! # if !defined SHUT_WR && defined SD_SEND
! #  define SHUT_WR SD_SEND
! # endif
! # if !defined SHUT_RDWR && defined SD_BOTH
! #  define SHUT_RDWR SD_BOTH
! # endif
! 
! # if defined _WIN32 || defined __WIN32__
! #  define ENOTSOCK                WSAENOTSOCK
! #  define EADDRINUSE              WSAEADDRINUSE
! #  define ENETRESET               WSAENETRESET
! #  define ECONNABORTED            WSAECONNABORTED
! #  define ECONNRESET              WSAECONNRESET
! #  define ENOTCONN                WSAENOTCONN
! #  define ESHUTDOWN               WSAESHUTDOWN
! # endif
! 
! #endif /* HAVE_SYS_SOCKET_H */
  
! #endif /* GL_SYS_SOCKET_H */
*** m4/sys_socket_h.m4  16 Feb 2006 09:48:07 -0000      1.2
--- m4/sys_socket_h.m4  3 Mar 2007 01:21:26 -0000
***************
*** 1,5 ****
! # sys_socket_h.m4 serial 2
! dnl Copyright (C) 2005, 2006 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.
--- 1,5 ----
! # sys_socket_h.m4 serial 3
! dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
***************
*** 8,23 ****
  
  AC_DEFUN([gl_HEADER_SYS_SOCKET],
  [
!   AC_CHECK_HEADERS_ONCE([sys/socket.h])
!   if test $ac_cv_header_sys_socket_h = yes; then
      SYS_SOCKET_H=''
    else
      dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
      dnl the check for those headers unconditional; yet cygwin reports
      dnl that the headers are present but cannot be compiled (since on
      dnl cygwin, all socket information should come from sys/socket.h).
!     AC_CHECK_HEADERS([winsock2.h ws2tcpip.h])
!     SYS_SOCKET_H='sys/socket.h'
    fi
!   AC_SUBST(SYS_SOCKET_H)
  ])
--- 8,55 ----
  
  AC_DEFUN([gl_HEADER_SYS_SOCKET],
  [
!   AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
!     [gl_cv_header_sys_socket_h_selfcontained],
!     [
!       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/socket.h>], [])],
!         [gl_cv_header_sys_socket_h_selfcontained=yes],
!         [gl_cv_header_sys_socket_h_selfcontained=no])
!     ])
!   if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
      SYS_SOCKET_H=''
    else
+     SYS_SOCKET_H='sys/socket.h'
+ 
      dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
      dnl the check for those headers unconditional; yet cygwin reports
      dnl that the headers are present but cannot be compiled (since on
      dnl cygwin, all socket information should come from sys/socket.h).
! 
!     AC_CHECK_HEADERS([sys/socket.h])
!     gl_ABSOLUTE_HEADER([sys/socket.h])
!     ABSOLUTE_SYS_SOCKET_H=\"$gl_cv_absolute_sys_socket_h\"
!     AC_SUBST([ABSOLUTE_SYS_SOCKET_H])
!     if test $ac_cv_header_sys_socket_h = yes; then
!       HAVE_SYS_SOCKET_H=1
!       HAVE_WINSOCK2_H=0
!       HAVE_WS2TCPIP_H=0
!     else
!       HAVE_SYS_SOCKET_H=0
!       AC_CHECK_HEADERS([winsock2.h ws2tcpip.h])
!       if test $ac_cv_header_winsock2_h = yes; then
!         HAVE_WINSOCK2_H=1
!       else
!         HAVE_WINSOCK2_H=0
!       fi
!       if test $ac_cv_header_ws2tcpip_h = yes; then
!         HAVE_WS2TCPIP_H=1
!       else
!         HAVE_WS2TCPIP_H=0
!       fi
!     fi
!     AC_SUBST([HAVE_SYS_SOCKET_H])
!     AC_SUBST([HAVE_WINSOCK2_H])
!     AC_SUBST([HAVE_WS2TCPIP_H])
    fi
!   AC_SUBST([SYS_SOCKET_H])
  ])
*** modules/sys_socket  22 Jan 2007 23:07:42 -0000      1.11
--- modules/sys_socket  3 Mar 2007 01:21:26 -0000
***************
*** 7,12 ****
--- 7,13 ----
  m4/sockpfaf.m4
  
  Depends-on:
+ absolute-header
  
  configure.ac:
  gl_HEADER_SYS_SOCKET
***************
*** 20,33 ****
  sys/socket.h: socket_.h
        @MKDIR_P@ sys
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
!         cat $(srcdir)/socket_.h; \
        } > address@hidden
        mv -f address@hidden $@
  MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
  MOSTLYCLEANDIRS += sys
  
  Include:
- #include <sys/types.h>
  #include <sys/socket.h>
  
  License:
--- 21,37 ----
  sys/socket.h: socket_.h
        @MKDIR_P@ sys
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
!         sed -e 's|@''ABSOLUTE_SYS_SOCKET_H''@|$(ABSOLUTE_SYS_SOCKET_H)|g' \
!             -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
!             -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
!             -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
!             < $(srcdir)/socket_.h; \
        } > address@hidden
        mv -f address@hidden $@
  MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t
  MOSTLYCLEANDIRS += sys
  
  Include:
  #include <sys/socket.h>
  
  License:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]