Mercurial > hg > octave-lyh > gnulib-hg
changeset 10610:9202c6340cce
Combine the two replacements of 'close'.
author | Paolo Bonzini <bonzini@gnu.org> |
---|---|
date | Fri, 10 Oct 2008 00:23:06 +0200 |
parents | 5acc60c1ec66 |
children | 02d4e9fb77b9 |
files | ChangeLog lib/close.c lib/sys_socket.in.h lib/unistd.in.h lib/winsock.c m4/sys_socket_h.m4 m4/unistd_h.m4 modules/poll-tests modules/select-tests modules/sys_socket modules/unistd |
diffstat | 11 files changed, 66 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2008-10-09 Paolo Bonzini <bonzini@gnu.org> + Bruno Haible <bruno@clisp.org> + + Combine the two replacements of 'close'. + * lib/sys_socket.in.h (close): Define to a reminder to include <unistd.h>. + (_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 <sys/socket.h>. + (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 <bonzini@gnu.org> Bruno Haible <bruno@clisp.org>
--- a/lib/close.c +++ b/lib/close.c @@ -19,6 +19,10 @@ /* Specification. */ #include <unistd.h> +#if GNULIB_SYS_SOCKET +# include <sys/socket.h> +#endif + /* Override close() to call into other gnulib modules. */ @@ -26,7 +30,11 @@ 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)
--- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -138,10 +138,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@ @@ -376,6 +375,12 @@ # 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
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -82,6 +82,15 @@ # 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
--- a/lib/winsock.c +++ b/lib/winsock.c @@ -25,7 +25,6 @@ #include <io.h> #include <sys/socket.h> -#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 @@ else return _close (fd); } +#endif /* Wrappers for WinSock functions. */
--- 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 @@ # 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 @@ 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_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])
--- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -69,4 +69,5 @@ 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]) ])
--- a/modules/poll-tests +++ b/modules/poll-tests @@ -17,6 +17,7 @@ listen connect accept +close configure.ac: AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
--- a/modules/select-tests +++ b/modules/select-tests @@ -16,6 +16,7 @@ listen connect accept +close configure.ac:
--- a/modules/sys_socket +++ b/modules/sys_socket @@ -6,6 +6,7 @@ lib/winsock.c m4/sys_socket_h.m4 m4/sockpfaf.m4 +m4/unistd_h.m4 Depends-on: include_next @@ -14,6 +15,7 @@ configure.ac: gl_HEADER_SYS_SOCKET +gl_MODULE_INDICATOR([sys_socket]) AC_PROG_MKDIR_P Makefile.am: @@ -28,6 +30,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' \
--- a/modules/unistd +++ b/modules/unistd @@ -60,6 +60,7 @@ -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