From 844191ea0f97be425fea2a18c55a5b139da5d7e7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 7 Jul 2011 03:34:18 +0200 Subject: [PATCH] sys_select: Fix compilation error on mingw, introduced on 2011-06-30. * lib/sys_select.in.h: Don't include . Instead, include . (rpl_fd_isset, FD_ISSET): New definitions, copied from lib/sys_socket.in.h. (close, gethostname): Hide declarations from . (socket, connect, accept, bind, getpeername, getsockname, getsockopt, listen, recv, send, recvfrom, sendto, setsockopt, shutdown): Likewise. * lib/sys_socket.in.h (close, gethostname): Tweak indentation. (select): Don't override if gnulib's was already included. * lib/unistd.in.h (socket, connect, accept, bind, getpeername, getsockname, getsockopt, listen, recv, send, recvfrom, sendto, setsockopt, shutdown, select): Tweak indentation. --- ChangeLog | 17 +++++++ lib/sys_select.in.h | 122 +++++++++++++++++++++++++++++++++++++++++++-- lib/sys_socket.in.h | 56 +++++++++++---------- lib/unistd.in.h | 141 ++++++++++++++++++++++++++-------------------------- 4 files changed, 234 insertions(+), 102 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe3d26a3a..8e8e34c5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2011-07-06 Bruno Haible + + sys_select: Fix compilation error on mingw, introduced on 2011-06-30. + * lib/sys_select.in.h: Don't include . Instead, include + . + (rpl_fd_isset, FD_ISSET): New definitions, copied from + lib/sys_socket.in.h. + (close, gethostname): Hide declarations from . + (socket, connect, accept, bind, getpeername, getsockname, getsockopt, + listen, recv, send, recvfrom, sendto, setsockopt, shutdown): Likewise. + * lib/sys_socket.in.h (close, gethostname): Tweak indentation. + (select): Don't override if gnulib's was already + included. + * lib/unistd.in.h (socket, connect, accept, bind, getpeername, + getsockname, getsockopt, listen, recv, send, recvfrom, sendto, + setsockopt, shutdown, select): Tweak indentation. + 2011-07-06 Paul Eggert * modules/pthread_sigmask (configure.ac): gl_SIGNAL_MODULE_INDICATOR diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index 8cbeb66a3..836a38734 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h @@ -85,10 +85,11 @@ # include # endif /* On native Windows platforms: - Get the 'fd_set' type. Also, gnulib's redefines select - so as to hide the declaration from . */ -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -# include + Get the 'fd_set' type. */ +# if @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H +# define _GL_INCLUDING_WINSOCK2_H +# include +# undef _GL_INCLUDING_WINSOCK2_H # endif #endif @@ -97,6 +98,119 @@ /* The definition of _GL_WARN_ON_USE is copied here. */ +/* Fix some definitions from . */ + +#if @HAVE_WINSOCK2_H@ + +# if !GNULIB_defined_rpl_fd_isset + +/* Re-define FD_ISSET to avoid a WSA call while we are not using + network sockets. */ +static inline int +rpl_fd_isset (SOCKET fd, fd_set * set) +{ + u_int i; + if (set == NULL) + return 0; + + for (i = 0; i < set->fd_count; i++) + if (set->fd_array[i] == fd) + return 1; + + return 0; +} + +# define GNULIB_defined_rpl_fd_isset 1 +# endif + +# undef FD_ISSET +# define FD_ISSET(fd, set) rpl_fd_isset(fd, set) + +#endif + +/* Hide some function declarations from . */ + +#if @HAVE_WINSOCK2_H@ +# if !defined _@GUARD_PREFIX@_UNISTD_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef close +# define close close_used_without_including_unistd_h +# else + _GL_WARN_ON_USE (close, + "close() used without including "); +# endif +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gethostname +# define gethostname gethostname_used_without_including_unistd_h +# else + _GL_WARN_ON_USE (gethostname, + "gethostname() used without including "); +# endif +# endif +# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef socket +# define socket socket_used_without_including_sys_socket_h +# undef connect +# define connect connect_used_without_including_sys_socket_h +# undef accept +# define accept accept_used_without_including_sys_socket_h +# undef bind +# define bind bind_used_without_including_sys_socket_h +# undef getpeername +# define getpeername getpeername_used_without_including_sys_socket_h +# undef getsockname +# define getsockname getsockname_used_without_including_sys_socket_h +# undef getsockopt +# define getsockopt getsockopt_used_without_including_sys_socket_h +# undef listen +# define listen listen_used_without_including_sys_socket_h +# undef recv +# define recv recv_used_without_including_sys_socket_h +# undef send +# define send send_used_without_including_sys_socket_h +# undef recvfrom +# define recvfrom recvfrom_used_without_including_sys_socket_h +# undef sendto +# define sendto sendto_used_without_including_sys_socket_h +# undef setsockopt +# define setsockopt setsockopt_used_without_including_sys_socket_h +# undef shutdown +# define shutdown shutdown_used_without_including_sys_socket_h +# else + _GL_WARN_ON_USE (socket, + "socket() used without including "); + _GL_WARN_ON_USE (connect, + "connect() used without including "); + _GL_WARN_ON_USE (accept, + "accept() used without including "); + _GL_WARN_ON_USE (bind, + "bind() used without including "); + _GL_WARN_ON_USE (getpeername, + "getpeername() used without including "); + _GL_WARN_ON_USE (getsockname, + "getsockname() used without including "); + _GL_WARN_ON_USE (getsockopt, + "getsockopt() used without including "); + _GL_WARN_ON_USE (listen, + "listen() used without including "); + _GL_WARN_ON_USE (recv, + "recv() used without including "); + _GL_WARN_ON_USE (send, + "send() used without including "); + _GL_WARN_ON_USE (recvfrom, + "recvfrom() used without including "); + _GL_WARN_ON_USE (sendto, + "sendto() used without including "); + _GL_WARN_ON_USE (setsockopt, + "setsockopt() used without including "); + _GL_WARN_ON_USE (shutdown, + "shutdown() used without including "); +# endif +# endif +#endif + + #if @GNULIB_PSELECT@ # if @REPLACE_PSELECT@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index 72d1150b7..c42497d04 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -194,6 +194,8 @@ struct msghdr { #endif +/* Fix some definitions from . */ + #if @HAVE_WINSOCK2_H@ # if !GNULIB_defined_rpl_fd_isset @@ -222,28 +224,38 @@ rpl_fd_isset (SOCKET fd, fd_set * set) #endif -/* Wrap everything else to use libc file descriptors for sockets. */ +/* Hide some function declarations from . */ -#if @HAVE_WINSOCK2_H@ && !defined _@GUARD_PREFIX@_UNISTD_H -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef close -# define close close_used_without_including_unistd_h -# else - _GL_WARN_ON_USE (close, - "close() used without including "); +#if @HAVE_WINSOCK2_H@ +# if !defined _@GUARD_PREFIX@_UNISTD_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef close +# define close close_used_without_including_unistd_h +# else + _GL_WARN_ON_USE (close, + "close() used without including "); +# endif +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gethostname +# define gethostname gethostname_used_without_including_unistd_h +# else + _GL_WARN_ON_USE (gethostname, + "gethostname() used without including "); +# endif # endif -#endif - -#if @HAVE_WINSOCK2_H@ && !defined _@GUARD_PREFIX@_UNISTD_H -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef gethostname -# define gethostname gethostname_used_without_including_unistd_h -# else - _GL_WARN_ON_USE (gethostname, - "gethostname() used without including "); +# if !defined _@GUARD_PREFIX@_SYS_SELECT_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef select +# define select select_used_without_including_sys_select_h +# else + _GL_WARN_ON_USE (select, + "select() used without including "); +# endif # endif #endif +/* Wrap everything else to use libc file descriptors for sockets. */ + #if @GNULIB_SOCKET@ # if @HAVE_WINSOCK2_H@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) @@ -633,16 +645,6 @@ _GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX compliant - " # endif #endif -#if @HAVE_WINSOCK2_H@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef select -# define select select_used_without_including_sys_select_h -# else - _GL_WARN_ON_USE (select, - "select() used without including "); -# endif -#endif - #if @GNULIB_ACCEPT4@ /* Accept a connection on a socket, with specific opening flags. The flags are a bitmask, possibly including O_CLOEXEC (defined in ) diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 1adbd1a6c..e612fb37d 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -117,78 +117,77 @@ /* The definition of _GL_WARN_ON_USE is copied here. */ -#if @GNULIB_GETHOSTNAME@ -/* Get all possible declarations of gethostname(). */ -# if @UNISTD_H_HAVE_WINSOCK2_H@ -# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef socket -# define socket socket_used_without_including_sys_socket_h -# undef connect -# define connect connect_used_without_including_sys_socket_h -# undef accept -# define accept accept_used_without_including_sys_socket_h -# undef bind -# define bind bind_used_without_including_sys_socket_h -# undef getpeername -# define getpeername getpeername_used_without_including_sys_socket_h -# undef getsockname -# define getsockname getsockname_used_without_including_sys_socket_h -# undef getsockopt -# define getsockopt getsockopt_used_without_including_sys_socket_h -# undef listen -# define listen listen_used_without_including_sys_socket_h -# undef recv -# define recv recv_used_without_including_sys_socket_h -# undef send -# define send send_used_without_including_sys_socket_h -# undef recvfrom -# define recvfrom recvfrom_used_without_including_sys_socket_h -# undef sendto -# define sendto sendto_used_without_including_sys_socket_h -# undef setsockopt -# define setsockopt setsockopt_used_without_including_sys_socket_h -# undef shutdown -# define shutdown shutdown_used_without_including_sys_socket_h -# else - _GL_WARN_ON_USE (socket, - "socket() used without including "); - _GL_WARN_ON_USE (connect, - "connect() used without including "); - _GL_WARN_ON_USE (accept, - "accept() used without including "); - _GL_WARN_ON_USE (bind, - "bind() used without including "); - _GL_WARN_ON_USE (getpeername, - "getpeername() used without including "); - _GL_WARN_ON_USE (getsockname, - "getsockname() used without including "); - _GL_WARN_ON_USE (getsockopt, - "getsockopt() used without including "); - _GL_WARN_ON_USE (listen, - "listen() used without including "); - _GL_WARN_ON_USE (recv, - "recv() used without including "); - _GL_WARN_ON_USE (send, - "send() used without including "); - _GL_WARN_ON_USE (recvfrom, - "recvfrom() used without including "); - _GL_WARN_ON_USE (sendto, - "sendto() used without including "); - _GL_WARN_ON_USE (setsockopt, - "setsockopt() used without including "); - _GL_WARN_ON_USE (shutdown, - "shutdown() used without including "); -# endif +/* Hide some function declarations from . */ + +#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ +# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef socket +# define socket socket_used_without_including_sys_socket_h +# undef connect +# define connect connect_used_without_including_sys_socket_h +# undef accept +# define accept accept_used_without_including_sys_socket_h +# undef bind +# define bind bind_used_without_including_sys_socket_h +# undef getpeername +# define getpeername getpeername_used_without_including_sys_socket_h +# undef getsockname +# define getsockname getsockname_used_without_including_sys_socket_h +# undef getsockopt +# define getsockopt getsockopt_used_without_including_sys_socket_h +# undef listen +# define listen listen_used_without_including_sys_socket_h +# undef recv +# define recv recv_used_without_including_sys_socket_h +# undef send +# define send send_used_without_including_sys_socket_h +# undef recvfrom +# define recvfrom recvfrom_used_without_including_sys_socket_h +# undef sendto +# define sendto sendto_used_without_including_sys_socket_h +# undef setsockopt +# define setsockopt setsockopt_used_without_including_sys_socket_h +# undef shutdown +# define shutdown shutdown_used_without_including_sys_socket_h +# else + _GL_WARN_ON_USE (socket, + "socket() used without including "); + _GL_WARN_ON_USE (connect, + "connect() used without including "); + _GL_WARN_ON_USE (accept, + "accept() used without including "); + _GL_WARN_ON_USE (bind, + "bind() used without including "); + _GL_WARN_ON_USE (getpeername, + "getpeername() used without including "); + _GL_WARN_ON_USE (getsockname, + "getsockname() used without including "); + _GL_WARN_ON_USE (getsockopt, + "getsockopt() used without including "); + _GL_WARN_ON_USE (listen, + "listen() used without including "); + _GL_WARN_ON_USE (recv, + "recv() used without including "); + _GL_WARN_ON_USE (send, + "send() used without including "); + _GL_WARN_ON_USE (recvfrom, + "recvfrom() used without including "); + _GL_WARN_ON_USE (sendto, + "sendto() used without including "); + _GL_WARN_ON_USE (setsockopt, + "setsockopt() used without including "); + _GL_WARN_ON_USE (shutdown, + "shutdown() used without including "); # endif -# if !defined _@GUARD_PREFIX@_SYS_SELECT_H -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef select -# define select select_used_without_including_sys_select_h -# else - _GL_WARN_ON_USE (select, - "select() used without including "); -# endif +# endif +# if !defined _@GUARD_PREFIX@_SYS_SELECT_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef select +# define select select_used_without_including_sys_select_h +# else + _GL_WARN_ON_USE (select, + "select() used without including "); # endif # endif #endif -- 2.11.0