+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>
/* Specification. */
#include <unistd.h>
+#if GNULIB_SYS_SOCKET
+# include <sys/socket.h>
+#endif
+
/* Override close() to call into other gnulib modules. */
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)
/* 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@
# 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
# 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
#include <io.h>
#include <sys/socket.h>
-#undef close
#undef socket
#undef connect
#undef accept
# 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;
else
return _close (fd);
}
+#endif
/* Wrappers for WinSock functions. */
-# 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,
# 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
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
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])
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])
])
listen
connect
accept
+close
configure.ac:
AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
listen
connect
accept
+close
configure.ac:
lib/winsock.c
m4/sys_socket_h.m4
m4/sockpfaf.m4
+m4/unistd_h.m4
Depends-on:
include_next
configure.ac:
gl_HEADER_SYS_SOCKET
+gl_MODULE_INDICATOR([sys_socket])
AC_PROG_MKDIR_P
Makefile.am:
-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' \
-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