From: Paolo Bonzini Date: Thu, 9 Oct 2008 22:23:06 +0000 (+0200) Subject: Combine the two replacements of 'close'. X-Git-Tag: v0.1~6872 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=59a539f3e601f4639e67d9a6d2a20c9450e642f4;p=gnulib.git Combine the two replacements of 'close'. --- diff --git a/ChangeLog b/ChangeLog index 38a308366..6a1ffa40b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,32 @@ 2008-10-09 Paolo Bonzini Bruno Haible + Combine the two replacements of 'close'. + * lib/sys_socket.in.h (close): Define to a reminder to include . + (_gl_close_fd_maybe_socket): New declaration. + (HAVE__GL_CLOSE_FD_MAYBE_SOCKET): New macro. + * lib/winsock.c (close): Remove undefinition. + (_gl_close_fd_maybe_socket): Renamed from rpl_close. Define only when + needed for the gnulib module 'close'. + * lib/unistd.in.h (close): If the gnulib module 'close' is not used, + define to an error symbol or to a warning, if suitable. + * lib/close.c: Include . + (rpl_close): Invoke _gl_close_fd_maybe_socket when gnulib defines it. + * m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_WINSOCK2): Set also + UNISTD_H_HAVE_WINSOCK2_H. + (gl_SYS_SOCKET_H_DEFAULTS): Require gl_UNISTD_H_DEFAULTS. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize + UNISTD_H_HAVE_WINSOCK2_H. + * modules/sys_socket (Files): Add m4/unistd_h.m4. + (configure.ac): Set a module indicator. + (Makefile.am): Substitute GNULIB_CLOSE. + * modules/unistd (Makefile.am): Substitute UNISTD_H_HAVE_WINSOCK2_H. + * modules/poll-tests (Depends-on): Add close. + * modules/select-tests (Depends-on): Likewise. + +2008-10-09 Paolo Bonzini + Bruno Haible + New module 'close'. * modules/close: New file. * lib/unistd.in.h (close): Move declaration out of the diff --git a/lib/close.c b/lib/close.c index b0464c96b..9b050668a 100644 --- a/lib/close.c +++ b/lib/close.c @@ -19,6 +19,10 @@ /* Specification. */ #include +#if GNULIB_SYS_SOCKET +# include +#endif + /* Override close() to call into other gnulib modules. */ @@ -26,7 +30,11 @@ 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) diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index 13729c646..74cb37a98 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -138,10 +138,9 @@ rpl_fd_isset (int fd, fd_set * set) /* 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@ @@ -376,6 +375,12 @@ extern int rpl_setsockopt (int, int, int, const void *, int); # 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 diff --git a/lib/unistd.in.h b/lib/unistd.in.h index c7233b125..8b4facbd4 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -82,6 +82,15 @@ extern int chown (const char *file, uid_t uid, gid_t gid); # 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 diff --git a/lib/winsock.c b/lib/winsock.c index 00609cf96..feee00d54 100644 --- a/lib/winsock.c +++ b/lib/winsock.c @@ -25,7 +25,6 @@ #include #include -#undef close #undef socket #undef connect #undef accept @@ -44,10 +43,11 @@ # define SOCKET_TO_FD(fh) (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY)) -/* Wrappers for libc functions. */ +/* Hook for gnulib module close. */ +#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET int -rpl_close (int fd) +_gl_close_fd_maybe_socket (int fd) { SOCKET sock = FD_TO_SOCKET (fd); WSANETWORKEVENTS ev; @@ -67,6 +67,7 @@ rpl_close (int fd) else return _close (fd); } +#endif /* Wrappers for WinSock functions. */ diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4 index 1e38ee3a9..e61de7bcb 100644 --- a/m4/sys_socket_h.m4 +++ b/m4/sys_socket_h.m4 @@ -1,4 +1,4 @@ -# sys_socket_h.m4 serial 8 +# sys_socket_h.m4 serial 9 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, @@ -71,6 +71,7 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET], # Sets and substitutes HAVE_WINSOCK2_H. AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2], [ + AC_REQUIRE([gl_UNISTD_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 @@ -81,6 +82,7 @@ AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2], fi if test "$ac_cv_header_winsock2_h" = yes; then HAVE_WINSOCK2_H=1 + UNISTD_H_HAVE_WINSOCK2_H=1 else HAVE_WINSOCK2_H=0 fi @@ -97,6 +99,7 @@ AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR], 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]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 21c400c4e..e9f7a7d58 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -69,4 +69,5 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], 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]) ]) diff --git a/modules/poll-tests b/modules/poll-tests index 72241ae73..403287cad 100644 --- a/modules/poll-tests +++ b/modules/poll-tests @@ -17,6 +17,7 @@ setsockopt listen connect accept +close configure.ac: AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h]) diff --git a/modules/select-tests b/modules/select-tests index 178834815..80ee60c0f 100644 --- a/modules/select-tests +++ b/modules/select-tests @@ -16,6 +16,7 @@ setsockopt listen connect accept +close configure.ac: diff --git a/modules/sys_socket b/modules/sys_socket index d2cf460ce..0d435707e 100644 --- a/modules/sys_socket +++ b/modules/sys_socket @@ -6,6 +6,7 @@ lib/sys_socket.in.h lib/winsock.c m4/sys_socket_h.m4 m4/sockpfaf.m4 +m4/unistd_h.m4 Depends-on: include_next @@ -14,6 +15,7 @@ errno configure.ac: gl_HEADER_SYS_SOCKET +gl_MODULE_INDICATOR([sys_socket]) AC_PROG_MKDIR_P Makefile.am: @@ -28,6 +30,7 @@ sys/socket.h: sys_socket.in.h -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' \ diff --git a/modules/unistd b/modules/unistd index 95e10d9bd..820f33e83 100644 --- a/modules/unistd +++ b/modules/unistd @@ -60,6 +60,7 @@ unistd.h: unistd.in.h -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